1 | <?php |
||
13 | final class Container |
||
14 | { |
||
15 | /** |
||
16 | * @var DependencyInterface[] |
||
17 | */ |
||
18 | private $container = []; |
||
19 | |||
20 | /** |
||
21 | * @var Pointcut[] |
||
22 | */ |
||
23 | private $pointcuts = []; |
||
24 | |||
25 | public function __sleep() |
||
29 | 4 | ||
30 | /** |
||
31 | 4 | * Add binding to container |
|
32 | */ |
||
33 | public function add(Bind $bind) |
||
34 | { |
||
35 | $dependency = $bind->getBound(); |
||
36 | $dependency->register($this->container, $bind); |
||
37 | } |
||
38 | |||
39 | 86 | /** |
|
40 | * Add Pointcut to container |
||
41 | 86 | */ |
|
42 | 86 | public function addPointcut(Pointcut $pointcut) |
|
46 | |||
47 | /** |
||
48 | * Return instance by interface + name(interface namespace) |
||
49 | */ |
||
50 | 42 | public function getInstance(string $interface, string $name) |
|
54 | |||
55 | /** |
||
56 | * Return dependency injected instance |
||
57 | * |
||
58 | * @throws Unbound |
||
59 | */ |
||
60 | 53 | public function getInstanceWithArgs(string $interface, array $params) |
|
73 | |||
74 | 73 | /** |
|
75 | 28 | * Return dependency injected instance |
|
76 | * |
||
77 | 69 | * @throws Unbound |
|
78 | */ |
||
79 | 69 | public function getDependency(string $index) |
|
88 | 3 | ||
89 | 1 | /** |
|
90 | * Rename existing dependency interface + name |
||
91 | 2 | */ |
|
92 | 2 | public function move(string $sourceInterface, string $sourceName, string $targetInterface, string $targetName) |
|
102 | |||
103 | 29 | /** |
|
104 | * Return Unbound exception |
||
105 | 29 | * |
|
106 | 29 | * @param string $index {interface}-{bind name} |
|
107 | 16 | * |
|
108 | * @return Unbound|Untargeted |
||
109 | */ |
||
110 | 16 | public function unbound(string $index) |
|
119 | |||
120 | 56 | /** |
|
121 | * Return container |
||
122 | * |
||
123 | * @return DependencyInterface[] |
||
124 | */ |
||
125 | public function getContainer() : array |
||
129 | |||
130 | 45 | /** |
|
131 | * Return pointcuts |
||
132 | * |
||
133 | * @return Pointcut[] |
||
134 | */ |
||
135 | public function getPointcuts() : array |
||
139 | 44 | ||
140 | 44 | /** |
|
141 | * Merge container |
||
142 | */ |
||
143 | public function merge(self $container) |
||
148 | 40 | ||
149 | 40 | /** |
|
150 | * Weave aspects to all dependency in container |
||
151 | 40 | */ |
|
152 | public function weaveAspects(CompilerInterface $compiler) |
||
161 | |||
162 | 16 | /** |
|
163 | * Weave aspect to single dependency |
||
164 | */ |
||
165 | public function weaveAspect(Compiler $compiler, Dependency $dependency) : self |
||
171 | } |
||
172 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: