1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Auth\Authorization\PolicyInformation; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2015-2019 [email protected] |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Limoncello\Auth\Contracts\Authorization\PolicyInformation\ContextInterface; |
22
|
|
|
use Limoncello\Auth\Contracts\Authorization\PolicyEnforcement\RequestInterface; |
23
|
|
|
use Limoncello\Container\Container; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @package Limoncello\Auth |
27
|
|
|
*/ |
28
|
|
|
class Context extends Container implements ContextInterface |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var RequestInterface |
32
|
|
|
*/ |
33
|
|
|
private $request; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param RequestInterface $request |
37
|
33 |
|
* @param array $contextDefinitions |
38
|
|
|
*/ |
39
|
33 |
|
public function __construct(RequestInterface $request, array $contextDefinitions = []) |
40
|
|
|
{ |
41
|
33 |
|
parent::__construct([RequestInterface::class => $request] + $contextDefinitions); |
42
|
|
|
|
43
|
|
|
$this->request = $request; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
26 |
|
* @inheritdoc |
48
|
|
|
*/ |
49
|
26 |
|
public function has($key): bool |
50
|
|
|
{ |
51
|
|
|
return parent::has($key) === true || $this->getRequest()->has($key) === true; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
24 |
|
* @inheritdoc |
56
|
|
|
*/ |
57
|
24 |
|
public function get($key) |
58
|
11 |
|
{ |
59
|
|
|
if (parent::has($key) === true) { |
|
|
|
|
60
|
|
|
return parent::get($key); |
61
|
21 |
|
} |
62
|
|
|
|
63
|
|
|
return $this->getRequest()->get($key); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
24 |
|
* @return RequestInterface |
68
|
|
|
*/ |
69
|
24 |
|
public function getRequest(): RequestInterface |
70
|
|
|
{ |
71
|
|
|
return $this->request; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.