MediaWiki master
ButtonAuthenticationRequest.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Auth;
23
26
38#[\AllowDynamicProperties]
41 protected $name;
42
43 protected Message $label;
44 protected Message $help;
45
53 public function __construct( $name, Message $label, Message $help, $required = false ) {
54 $this->name = $name;
55 $this->label = $label;
56 $this->help = $help;
57 $this->required = $required ? self::REQUIRED : self::OPTIONAL;
58 }
59
64 public function getUniqueId() {
65 return parent::getUniqueId() . ':' . $this->name;
66 }
67
72 public function getFieldInfo() {
73 return [
74 $this->name => [
75 'type' => 'button',
76 'label' => $this->label,
77 'help' => $this->help,
78 ]
79 ];
80 }
81
89 public static function getRequestByName( array $reqs, $name ) {
90 $requests = array_filter( $reqs, static function ( $req ) use ( $name ) {
91 return $req instanceof ButtonAuthenticationRequest && $req->name === $name;
92 } );
93 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType False positive
94 return count( $requests ) === 1 ? reset( $requests ) : null;
95 }
96
103 public static function __set_state( $data ) {
104 if ( !isset( $data['label'] ) ) {
105 $data['label'] = new RawMessage( '$1', $data['name'] );
106 } elseif ( is_string( $data['label'] ) ) {
107 $data['label'] = new Message( $data['label'] );
108 } elseif ( is_array( $data['label'] ) && $data['label'] ) {
109 // @phan-suppress-next-line PhanParamTooFewUnpack Should infer non-emptiness from above
110 $data['label'] = Message::newFromKey( ...$data['label'] );
111 }
112 if ( !isset( $data['help'] ) ) {
113 $data['help'] = new RawMessage( '$1', $data['name'] );
114 } elseif ( is_string( $data['help'] ) ) {
115 $data['help'] = new Message( $data['help'] );
116 } elseif ( is_array( $data['help'] ) && $data['help'] ) {
117 // @phan-suppress-next-line PhanParamTooFewUnpack Should infer non-emptiness from above
118 $data['help'] = Message::newFromKey( ...$data['help'] );
119 }
120 $ret = new static( $data['name'], $data['label'], $data['help'] );
121 foreach ( $data as $k => $v ) {
122 $ret->$k = $v;
123 }
124 return $ret;
125 }
126}
This is a value object for authentication requests.
const OPTIONAL
Indicates that the request is not required for authentication to proceed.
int $required
Whether the authentication request is required (for login, continue, and link actions).
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)
Variant of the Message class.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:157
static newFromKey( $key,... $params)
Factory function that is just wrapper for the real constructor.
Definition Message.php:494