1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Railt package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace Railt\Reflection\Dictionary; |
11
|
|
|
|
12
|
|
|
use Railt\Reflection\Contracts\Definition; |
13
|
|
|
use Railt\Reflection\Contracts\Definition\TypeDefinition; |
14
|
|
|
use Railt\Reflection\Contracts\Dictionary; |
15
|
|
|
use Railt\Reflection\Contracts\Type; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class ProxyDictionary |
19
|
|
|
*/ |
20
|
|
|
class ProxyDictionary implements Dictionary |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Dictionary |
24
|
|
|
*/ |
25
|
|
|
private $parent; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* ProxyDictionary constructor. |
29
|
|
|
* @param Dictionary $parent |
30
|
|
|
*/ |
31
|
9 |
|
public function __construct(Dictionary $parent) |
32
|
|
|
{ |
33
|
9 |
|
$this->parent = $parent; |
34
|
9 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return Dictionary |
38
|
|
|
*/ |
39
|
|
|
public function getParentDictionary(): Dictionary |
40
|
|
|
{ |
41
|
|
|
return $this->parent; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param Type|null $of |
46
|
|
|
* @return iterable|TypeDefinition[] |
47
|
|
|
*/ |
48
|
3 |
|
public function all(Type $of = null): iterable |
49
|
|
|
{ |
50
|
3 |
|
foreach ($this->parent->all($of) as $definition) { |
51
|
3 |
|
yield $definition; |
52
|
|
|
} |
53
|
3 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $name |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
3 |
|
public function has(string $name): bool |
60
|
|
|
{ |
61
|
3 |
|
return $this->parent->has($name); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $name |
66
|
|
|
* @return null|TypeDefinition |
67
|
|
|
*/ |
68
|
11 |
|
public function find(string $name): ?TypeDefinition |
69
|
|
|
{ |
70
|
11 |
|
return $this->parent->find($name); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $name |
75
|
|
|
* @param Definition|null $from |
76
|
|
|
* @return TypeDefinition |
77
|
|
|
* @throws \Railt\Reflection\Exception\TypeNotFoundException |
78
|
|
|
*/ |
79
|
17 |
|
public function get(string $name, Definition $from = null): TypeDefinition |
80
|
|
|
{ |
81
|
17 |
|
return $this->parent->get($name, $from); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param TypeDefinition $type |
86
|
|
|
* @return Dictionary |
87
|
|
|
*/ |
88
|
17 |
|
public function add(TypeDefinition $type): Dictionary |
89
|
|
|
{ |
90
|
17 |
|
return $this->parent->add($type); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|