1 | <?php |
||
2 | /** |
||
3 | * |
||
4 | */ |
||
5 | |||
6 | namespace Mvc5\Config; |
||
7 | |||
8 | use function is_object; |
||
9 | |||
10 | trait Scope |
||
11 | { |
||
12 | /** |
||
13 | * @var bool|object|null |
||
14 | */ |
||
15 | protected $scope; |
||
16 | |||
17 | /** |
||
18 | * @param mixed|object $context |
||
19 | * @return Scopable|self |
||
20 | */ |
||
21 | 4 | function withScope($context) : Scopable |
|
22 | { |
||
23 | 4 | $scope = $this->scope; |
|
24 | |||
25 | 4 | if (! is_object($scope) || ($scope !== $this && ! $scope instanceof $context)) { |
|
26 | 1 | return clone $this; |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
27 | } |
||
28 | |||
29 | 3 | $this->scope = null; |
|
30 | |||
31 | 3 | $new = clone $this; |
|
32 | 3 | $new->scope = $scope === $this ? $new : $context; |
|
33 | |||
34 | 3 | $this->scope = $scope; |
|
35 | |||
36 | 3 | return $new; |
|
0 ignored issues
–
show
|
|||
37 | } |
||
38 | } |
||
39 |