MediaWiki master
ButtonAuthenticationRequest.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Auth;
8
11
26#[\AllowDynamicProperties]
29 protected $name;
30
31 protected Message $label;
32 protected Message $help;
33
41 public function __construct( $name, Message $label, Message $help, $required = false ) {
42 $this->name = $name;
43 $this->label = $label;
44 $this->help = $help;
45 $this->required = $required ? self::REQUIRED : self::OPTIONAL;
46 }
47
52 public function getUniqueId() {
53 return parent::getUniqueId() . ':' . $this->name;
54 }
55
60 public function getFieldInfo() {
61 return [
62 $this->name => [
63 'type' => 'button',
64 'label' => $this->label,
65 'help' => $this->help,
66 ]
67 ];
68 }
69
77 public static function getRequestByName( array $reqs, $name ) {
78 $requests = array_filter( $reqs, static function ( $req ) use ( $name ) {
79 return $req instanceof ButtonAuthenticationRequest && $req->name === $name;
80 } );
81 // @phan-suppress-next-line PhanTypeMismatchReturnSuperType False positive
82 return count( $requests ) === 1 ? reset( $requests ) : null;
83 }
84
91 public static function __set_state( $data ) {
92 if ( !isset( $data['label'] ) ) {
93 $data['label'] = new RawMessage( '$1', $data['name'] );
94 } elseif ( is_string( $data['label'] ) ) {
95 $data['label'] = new Message( $data['label'] );
96 } elseif ( is_array( $data['label'] ) && $data['label'] ) {
97 // @phan-suppress-next-line PhanParamTooFewUnpack Should infer non-emptiness from above
98 $data['label'] = Message::newFromKey( ...$data['label'] );
99 }
100 if ( !isset( $data['help'] ) ) {
101 $data['help'] = new RawMessage( '$1', $data['name'] );
102 } elseif ( is_string( $data['help'] ) ) {
103 $data['help'] = new Message( $data['help'] );
104 } elseif ( is_array( $data['help'] ) && $data['help'] ) {
105 // @phan-suppress-next-line PhanParamTooFewUnpack Should infer non-emptiness from above
106 $data['help'] = Message::newFromKey( ...$data['help'] );
107 }
108 $ret = new static( $data['name'], $data['label'], $data['help'] );
109 foreach ( $data as $k => $v ) {
110 $ret->$k = $v;
111 }
112 return $ret;
113 }
114}
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.
An authentication request that implements a single 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:144
static newFromKey( $key,... $params)
Factory function that is just wrapper for the real constructor.
Definition Message.php:470