MediaWiki REL1_39
ButtonAuthenticationRequest.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
24use Message;
25use RawMessage;
26
33#[\AllowDynamicProperties]
36 protected $name;
37
39 protected $label;
40
42 protected $help;
43
51 public function __construct( $name, Message $label, Message $help, $required = false ) {
52 $this->name = $name;
53 $this->label = $label;
54 $this->help = $help;
55 $this->required = $required ? self::REQUIRED : self::OPTIONAL;
56 }
57
62 public function getUniqueId() {
63 return parent::getUniqueId() . ':' . $this->name;
64 }
65
70 public function getFieldInfo() {
71 return [
72 $this->name => [
73 'type' => 'button',
74 'label' => $this->label,
75 'help' => $this->help,
76 ]
77 ];
78 }
79
87 public static function getRequestByName( array $reqs, $name ) {
88 $requests = array_filter( $reqs, static function ( $req ) use ( $name ) {
89 return $req instanceof ButtonAuthenticationRequest && $req->name === $name;
90 } );
91 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType False positive
92 return count( $requests ) === 1 ? reset( $requests ) : null;
93 }
94
101 public static function __set_state( $data ) {
102 if ( !isset( $data['label'] ) ) {
103 $data['label'] = new RawMessage( '$1', $data['name'] );
104 } elseif ( is_string( $data['label'] ) ) {
105 $data['label'] = new Message( $data['label'] );
106 } elseif ( is_array( $data['label'] ) && $data['label'] ) {
107 // @phan-suppress-next-line PhanParamTooFewUnpack Should infer non-emptiness from above
108 $data['label'] = Message::newFromKey( ...$data['label'] );
109 }
110 if ( !isset( $data['help'] ) ) {
111 $data['help'] = new RawMessage( '$1', $data['name'] );
112 } elseif ( is_string( $data['help'] ) ) {
113 $data['help'] = new Message( $data['help'] );
114 } elseif ( is_array( $data['help'] ) && $data['help'] ) {
115 // @phan-suppress-next-line PhanParamTooFewUnpack Should infer non-emptiness from above
116 $data['help'] = Message::newFromKey( ...$data['help'] );
117 }
118 $ret = new static( $data['name'], $data['label'], $data['help'] );
119 foreach ( $data as $k => $v ) {
120 $ret->$k = $v;
121 }
122 return $ret;
123 }
124}
This is a value object for authentication requests.
const OPTIONAL
Indicates that the request is not required for authentication to proceed.
int $required
For login, continue, and link actions, one of self::OPTIONAL, self::REQUIRED, or self::PRIMARY_REQUIR...
const REQUIRED
Indicates that the request is required for authentication to proceed.
This is an authentication request that just implements a simple button.
getFieldInfo()
Fetch input field info.This will be used in the AuthManager APIs and web UIs to define API input para...
static getRequestByName(array $reqs, $name)
Fetch a ButtonAuthenticationRequest or subclass by name.
getUniqueId()
Supply a unique key for deduplication.When the AuthenticationRequests instances returned by the provi...
__construct( $name, Message $label, Message $help, $required=false)
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:140
static newFromKey( $key,... $params)
Factory function that is just wrapper for the real constructor.
Definition Message.php:399
Variant of the Message class.