1 | <?php |
||
38 | trait AuthenticateTrait |
||
39 | { |
||
40 | |||
41 | /** |
||
42 | * Objects that will be used for authentication checks. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $_authenticateObjects = []; |
||
47 | |||
48 | /** |
||
49 | * The instance of the Authenticate provider that was used for |
||
50 | * successfully logging in the current user after calling `login()` |
||
51 | * in the same request |
||
52 | * |
||
53 | * @var \Cake\Auth\BaseAuthenticate |
||
54 | */ |
||
55 | protected $_authenticationProvider; |
||
56 | |||
57 | /** |
||
58 | * Get the current user from storage. |
||
59 | * |
||
60 | * @param string|null $key Field to retrieve. Leave null to get entire User record. |
||
61 | * @return mixed|null Either User record or null if no user is logged in, or retrieved field if key is specified. |
||
62 | */ |
||
63 | 48 | public function user($key = null) |
|
76 | |||
77 | /** |
||
78 | * Set provided user info to storage as logged in user. |
||
79 | * |
||
80 | * The storage class is configured using `storage` config key or passing |
||
81 | * instance to AuthComponent::storage(). |
||
82 | * |
||
83 | * @param array $user Array of user data. |
||
84 | * @return void |
||
85 | */ |
||
86 | 3 | public function setUser(array $user) |
|
90 | |||
91 | /** |
||
92 | * connected authentication objects will have their |
||
93 | * getUser() methods called. |
||
94 | * |
||
95 | * This lets stateless authentication methods function correctly. |
||
96 | * |
||
97 | * @return bool true If a user can be found, false if one cannot. |
||
98 | */ |
||
99 | 48 | protected function _getUser() |
|
127 | |||
128 | /** |
||
129 | * Use the configured authentication adapters, and attempt to identify the user |
||
130 | * by credentials contained in $request. |
||
131 | * |
||
132 | * Triggers `Auth.afterIdentify` event which the authenticate classes can listen |
||
133 | * to. |
||
134 | * |
||
135 | * @return array|bool User record data, or false, if the user could not be identified. |
||
136 | */ |
||
137 | 4 | public function identify() |
|
159 | |||
160 | /** |
||
161 | * Loads the configured authentication objects. |
||
162 | * |
||
163 | * @return array|null The loaded authorization objects, or null on empty authenticate value. |
||
164 | * @throws \Cake\Core\Exception\Exception |
||
165 | */ |
||
166 | 52 | public function constructAuthenticate() |
|
199 | |||
200 | /** |
||
201 | * Getter for authenticate objects. Will return a particular authenticate object. |
||
202 | * |
||
203 | * @param string $alias Alias for the authenticate object |
||
204 | * |
||
205 | * @return \Cake\Auth\BaseAuthenticate|null |
||
206 | */ |
||
207 | public function getAuthenticate($alias) |
||
215 | |||
216 | /** |
||
217 | * If login was called during this request and the user was successfully |
||
218 | * authenticated, this function will return the instance of the authentication |
||
219 | * object that was used for logging the user in. |
||
220 | * |
||
221 | * @return \Cake\Auth\BaseAuthenticate|null |
||
222 | */ |
||
223 | public function authenticationProvider() |
||
227 | } |
||
228 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.