1 | <?php |
||
35 | class Psr7Authenticate extends BaseAuthenticate |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * Authenticates the identity contained in a request. Will use the `config.userModel`, and `config.fields` |
||
40 | * to find POST data that is used to find a matching record in the `config.userModel`. Will return false if |
||
41 | * there is no post data, either username or password is missing, or if the scope conditions have not been met. |
||
42 | * |
||
43 | * @param \Cake\Http\ServerRequest $request The request that contains login information. |
||
44 | * @param \Cake\Http\Response $response Unused response object. |
||
45 | * @return mixed False on login failure. An array of User data on success. |
||
46 | */ |
||
47 | public function authenticate(ServerRequest $request, Response $response) |
||
51 | |||
52 | /** |
||
53 | * Get a user based on information in the request. Primarily used by stateless authentication |
||
54 | * systems like basic and digest auth. |
||
55 | * |
||
56 | * @param \Cake\Http\ServerRequest $request Request object. |
||
57 | * @return mixed Either false or an array of user information |
||
58 | */ |
||
59 | public function getUser(ServerRequest $request) |
||
74 | } |
||
75 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.