1 | <?php |
||
13 | final class Container |
||
14 | { |
||
15 | /** |
||
16 | * @var Dependency[] |
||
17 | */ |
||
18 | private $container = []; |
||
19 | |||
20 | /** |
||
21 | * @var Pointcut[] |
||
22 | */ |
||
23 | private $pointcuts = []; |
||
24 | |||
25 | public function __sleep() |
||
29 | |||
30 | /** |
||
31 | * Add binding to container |
||
32 | */ |
||
33 | public function add(Bind $bind) |
||
38 | |||
39 | /** |
||
40 | * Add Pointcut to container |
||
41 | */ |
||
42 | public function addPointcut(Pointcut $pointcut) |
||
46 | |||
47 | /** |
||
48 | * Return instance by interface + name(interface namespace) |
||
49 | */ |
||
50 | public function getInstance(string $interface, string $name) |
||
54 | |||
55 | /** |
||
56 | * Return dependency injected instance |
||
57 | * |
||
58 | * @throws Unbound |
||
59 | */ |
||
60 | public function getInstanceWithArgs(string $interface, string $name, array $params) |
||
70 | |||
71 | /** |
||
72 | * Return dependency injected instance |
||
73 | * |
||
74 | * @throws Unbound |
||
75 | */ |
||
76 | public function getDependency(string $index) |
||
85 | |||
86 | /** |
||
87 | * Rename existing dependency interface + name |
||
88 | */ |
||
89 | public function move(string $sourceInterface, string $sourceName, string $targetInterface, string $targetName) |
||
99 | |||
100 | /** |
||
101 | * Return Unbound exception |
||
102 | * |
||
103 | * @param string $index {interface}-{bind name} |
||
104 | * |
||
105 | * @return Unbound|Untargeted |
||
106 | */ |
||
107 | public function unbound(string $index) |
||
116 | |||
117 | /** |
||
118 | * Return container |
||
119 | * |
||
120 | * @return Dependency[] |
||
121 | */ |
||
122 | public function getContainer() : array |
||
126 | |||
127 | /** |
||
128 | * Return pointcuts |
||
129 | * |
||
130 | * @return Pointcut[] |
||
131 | */ |
||
132 | public function getPointcuts() : array |
||
136 | |||
137 | /** |
||
138 | * Merge container |
||
139 | */ |
||
140 | public function merge(self $container) |
||
145 | |||
146 | /** |
||
147 | * Weave aspects to all dependency in container |
||
148 | */ |
||
149 | public function weaveAspects(CompilerInterface $compiler) |
||
158 | |||
159 | /** |
||
160 | * Weave aspect to single dependency |
||
161 | */ |
||
162 | public function weaveAspect(Compiler $compiler, Dependency $dependency) : self |
||
168 | } |
||
169 |
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: