Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| CreateFromLoginAuthenticationRequest | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
12 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| getFieldInfo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| loadFromSubmission | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasStateForAction | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
5 | |||
| hasPrimaryStateForAction | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Auth; |
| 8 | |
| 9 | /** |
| 10 | * This transfers state between the login and account creation flows. |
| 11 | * |
| 12 | * AuthManager::getAuthenticationRequests() won't return this type, but it |
| 13 | * may be passed to AuthManager::beginAuthentication() or |
| 14 | * AuthManager::beginAccountCreation() anyway. |
| 15 | * |
| 16 | * @stable to extend |
| 17 | * @ingroup Auth |
| 18 | * @since 1.27 |
| 19 | */ |
| 20 | class CreateFromLoginAuthenticationRequest extends AuthenticationRequest { |
| 21 | /** @inheritDoc */ |
| 22 | public $required = self::OPTIONAL; |
| 23 | |
| 24 | /** @var AuthenticationRequest|null */ |
| 25 | public $createRequest; |
| 26 | |
| 27 | /** @var AuthenticationRequest[] */ |
| 28 | public $maybeLink = []; |
| 29 | |
| 30 | /** |
| 31 | * @stable to call |
| 32 | * @param AuthenticationRequest|null $createRequest A request to use to |
| 33 | * begin creating the account |
| 34 | * @param AuthenticationRequest[] $maybeLink Additional accounts to link |
| 35 | * after creation. |
| 36 | */ |
| 37 | public function __construct( |
| 38 | ?AuthenticationRequest $createRequest = null, array $maybeLink = [] |
| 39 | ) { |
| 40 | $this->createRequest = $createRequest; |
| 41 | $this->maybeLink = $maybeLink; |
| 42 | $this->username = $createRequest ? $createRequest->username : null; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @inheritDoc |
| 47 | * @stable to override |
| 48 | */ |
| 49 | public function getFieldInfo() { |
| 50 | return []; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @inheritDoc |
| 55 | * @stable to override |
| 56 | */ |
| 57 | public function loadFromSubmission( array $data ) { |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Indicate whether this request contains any state for the specified |
| 63 | * action. |
| 64 | * @stable to override |
| 65 | * @param string $action One of the AuthManager::ACTION_* constants |
| 66 | * @return bool |
| 67 | */ |
| 68 | public function hasStateForAction( $action ) { |
| 69 | switch ( $action ) { |
| 70 | case AuthManager::ACTION_LOGIN: |
| 71 | return (bool)$this->maybeLink; |
| 72 | case AuthManager::ACTION_CREATE: |
| 73 | return $this->maybeLink || $this->createRequest; |
| 74 | default: |
| 75 | return false; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Indicate whether this request contains state for the specified |
| 81 | * action sufficient to replace other primary-required requests. |
| 82 | * @stable to override |
| 83 | * @param string $action One of the AuthManager::ACTION_* constants |
| 84 | * @return bool |
| 85 | */ |
| 86 | public function hasPrimaryStateForAction( $action ) { |
| 87 | switch ( $action ) { |
| 88 | case AuthManager::ACTION_CREATE: |
| 89 | return (bool)$this->createRequest; |
| 90 | default: |
| 91 | return false; |
| 92 | } |
| 93 | } |
| 94 | } |