Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
CreateFromLoginAuthenticationRequest
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
5 / 5
12
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getFieldInfo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 loadFromSubmission
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasStateForAction
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
5
 hasPrimaryStateForAction
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Auth
20 */
21
22namespace MediaWiki\Auth;
23
24/**
25 * This transfers state between the login and account creation flows.
26 *
27 * AuthManager::getAuthenticationRequests() won't return this type, but it
28 * may be passed to AuthManager::beginAuthentication() or
29 * AuthManager::beginAccountCreation() anyway.
30 *
31 * @stable to extend
32 * @ingroup Auth
33 * @since 1.27
34 */
35class CreateFromLoginAuthenticationRequest extends AuthenticationRequest {
36    public $required = self::OPTIONAL;
37
38    /** @var AuthenticationRequest|null */
39    public $createRequest;
40
41    /** @var AuthenticationRequest[] */
42    public $maybeLink = [];
43
44    /**
45     * @stable to call
46     * @param AuthenticationRequest|null $createRequest A request to use to
47     *  begin creating the account
48     * @param AuthenticationRequest[] $maybeLink Additional accounts to link
49     *  after creation.
50     */
51    public function __construct(
52        AuthenticationRequest $createRequest = null, array $maybeLink = []
53    ) {
54        $this->createRequest = $createRequest;
55        $this->maybeLink = $maybeLink;
56        $this->username = $createRequest ? $createRequest->username : null;
57    }
58
59    /**
60     * @inheritDoc
61     * @stable to override
62     */
63    public function getFieldInfo() {
64        return [];
65    }
66
67    /**
68     * @inheritDoc
69     * @stable to override
70     */
71    public function loadFromSubmission( array $data ) {
72        return true;
73    }
74
75    /**
76     * Indicate whether this request contains any state for the specified
77     * action.
78     * @stable to override
79     * @param string $action One of the AuthManager::ACTION_* constants
80     * @return bool
81     */
82    public function hasStateForAction( $action ) {
83        switch ( $action ) {
84            case AuthManager::ACTION_LOGIN:
85                return (bool)$this->maybeLink;
86            case AuthManager::ACTION_CREATE:
87                return $this->maybeLink || $this->createRequest;
88            default:
89                return false;
90        }
91    }
92
93    /**
94     * Indicate whether this request contains state for the specified
95     * action sufficient to replace other primary-required requests.
96     * @stable to override
97     * @param string $action One of the AuthManager::ACTION_* constants
98     * @return bool
99     */
100    public function hasPrimaryStateForAction( $action ) {
101        switch ( $action ) {
102            case AuthManager::ACTION_CREATE:
103                return (bool)$this->createRequest;
104            default:
105                return false;
106        }
107    }
108}