1 | <?php |
||
29 | abstract class AbstractContainer implements Container |
||
30 | { |
||
31 | /** |
||
32 | * @var Container The parent container |
||
33 | */ |
||
34 | protected $parent; |
||
35 | /** |
||
36 | * @var string[] with string keys |
||
37 | */ |
||
38 | protected $types = []; |
||
39 | /** |
||
40 | * @var string[] the list of PHP native types |
||
41 | */ |
||
42 | protected static $primitives = ['array', 'bool', 'float', 'int', 'resource', 'string']; |
||
43 | |||
44 | /** |
||
45 | * Creates a new AbstractContainer. |
||
46 | * |
||
47 | * @param string[] $types with string keys |
||
48 | * @param \Caridea\Container\Container $parent The parent container |
||
49 | */ |
||
50 | 5 | protected function __construct(array $types, Container $parent = null) |
|
55 | |||
56 | /** |
||
57 | * {@inheritDoc} |
||
58 | */ |
||
59 | 1 | public function contains(string $name): bool |
|
63 | |||
64 | /** |
||
65 | * {@inheritDoc} |
||
66 | */ |
||
67 | 1 | public function containsType(string $type): bool |
|
77 | |||
78 | /** |
||
79 | * {@inheritDoc} |
||
80 | */ |
||
81 | 5 | public function get($id) |
|
90 | |||
91 | /** |
||
92 | * {@inheritDoc} |
||
93 | */ |
||
94 | 1 | public function getByType(string $type): array |
|
105 | |||
106 | /** |
||
107 | * {@inheritDoc} |
||
108 | */ |
||
109 | 1 | public function getFirst(string $type) |
|
119 | |||
120 | /** |
||
121 | * {@inheritDoc} |
||
122 | */ |
||
123 | 1 | public function has($name): bool |
|
124 | { |
||
125 | 1 | return isset($this->types[$name]) || |
|
126 | 1 | ($this->parent ? $this->parent->has($name) : false); |
|
127 | } |
||
128 | |||
129 | /** |
||
130 | * Retrieves the value |
||
131 | * |
||
132 | * @param string $name The value name |
||
133 | */ |
||
134 | abstract protected function doGet(string $name); |
||
135 | |||
136 | /** |
||
137 | * {@inheritDoc} |
||
138 | */ |
||
139 | 1 | public function getNames(): array |
|
143 | |||
144 | /** |
||
145 | * {@inheritDoc} |
||
146 | */ |
||
147 | 1 | public function getParent(): ?Container |
|
151 | |||
152 | /** |
||
153 | * {@inheritDoc} |
||
154 | */ |
||
155 | 1 | public function getType(string $name): ?string |
|
160 | |||
161 | /** |
||
162 | * {@inheritDoc} |
||
163 | */ |
||
164 | 4 | public function named(string $name, string $type) |
|
178 | } |
||
179 |