1 | <?php declare(strict_types=1); |
||
11 | class Container implements ContainerInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var boolean |
||
15 | */ |
||
16 | protected $defaultToShared = false; |
||
17 | |||
18 | /** |
||
19 | * @var \League\Container\Definition\DefinitionAggregateInterface |
||
20 | */ |
||
21 | protected $definitions; |
||
22 | |||
23 | /** |
||
24 | * @var \League\Container\ServiceProvider\ServiceProviderAggregateInterface |
||
25 | */ |
||
26 | protected $providers; |
||
27 | |||
28 | /** |
||
29 | * @var \League\Container\Inflector\InflectorAggregateInterface |
||
30 | */ |
||
31 | protected $inflectors; |
||
32 | |||
33 | /** |
||
34 | * @var \Psr\Container\ContainerInterface[] |
||
35 | */ |
||
36 | protected $delegates = []; |
||
37 | |||
38 | /** |
||
39 | * Construct. |
||
40 | * |
||
41 | * @param \League\Container\Definition\DefinitionAggregateInterface|null $definitions |
||
42 | * @param \League\Container\ServiceProvider\ServiceProviderAggregateInterface|null $providers |
||
43 | * @param \League\Container\Inflector\InflectorAggregateInterface|null $inflectors |
||
44 | */ |
||
45 | 48 | public function __construct( |
|
66 | |||
67 | /** |
||
68 | * Add an item to the container. |
||
69 | * |
||
70 | * @param string $id |
||
71 | * @param mixed $concrete |
||
72 | * @param boolean $shared |
||
73 | * |
||
74 | * @return \League\Container\Definition\DefinitionInterface |
||
75 | */ |
||
76 | 27 | public function add(string $id, $concrete = null, bool $shared = null) : DefinitionInterface |
|
77 | { |
||
78 | 27 | $concrete = $concrete ?? $id; |
|
79 | 27 | $shared = $shared ?? $this->defaultToShared; |
|
80 | |||
81 | 27 | return $this->definitions->add($id, $concrete, $shared); |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * Proxy to add with shared as true. |
||
86 | * |
||
87 | * @param string $id |
||
88 | * @param mixed $concrete |
||
89 | * |
||
90 | * @return \League\Container\Definition\DefinitionInterface |
||
91 | */ |
||
92 | 3 | public function share(string $id, $concrete = null) : DefinitionInterface |
|
96 | |||
97 | /** |
||
98 | * Whether the container should default to defining shared definitions. |
||
99 | * |
||
100 | * @param boolean $shared |
||
101 | * |
||
102 | * @return self |
||
103 | */ |
||
104 | 6 | public function defaultToShared(bool $shared = true) : ContainerInterface |
|
110 | |||
111 | /** |
||
112 | * Get a definition to extend. |
||
113 | * |
||
114 | * @param string $id [description] |
||
115 | * |
||
116 | * @return \League\Container\Definition\DefinitionInterface |
||
117 | */ |
||
118 | 9 | public function extend(string $id) : DefinitionInterface |
|
132 | |||
133 | /** |
||
134 | * Add a service provider. |
||
135 | * |
||
136 | * @param \League\Container\ServiceProvider\ServiceProviderInterface|string $provider |
||
137 | * |
||
138 | * @return self |
||
139 | */ |
||
140 | 6 | public function addServiceProvider($provider) : self |
|
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | 27 | public function get($id, bool $new = false) |
|
186 | |||
187 | /** |
||
188 | * {@inheritdoc} |
||
189 | */ |
||
190 | 30 | public function has($id) : bool |
|
212 | |||
213 | /** |
||
214 | * Allows for manipulation of specific types on resolution. |
||
215 | * |
||
216 | * @param string $type |
||
217 | * @param callable|null $callback |
||
218 | * |
||
219 | * @return \League\Container\Inflector\InflectorInterface |
||
220 | */ |
||
221 | 3 | public function inflector(string $type, callable $callback = null) : InflectorInterface |
|
225 | |||
226 | /** |
||
227 | * Delegate a backup container to be checked for services if it |
||
228 | * cannot be resolved via this container. |
||
229 | * |
||
230 | * @param \Psr\Container\ContainerInterface $container |
||
231 | * |
||
232 | * @return self |
||
233 | */ |
||
234 | 3 | public function delegate(ContainerInterface $container) : self |
|
244 | } |
||
245 |