1 | <?php |
||
17 | final class Container |
||
18 | { |
||
19 | /** |
||
20 | * @var DependencyInterface[] |
||
21 | */ |
||
22 | private $container = []; |
||
23 | |||
24 | /** |
||
25 | * @var Pointcut[] |
||
26 | */ |
||
27 | private $pointcuts = []; |
||
28 | |||
29 | 1 | public function __sleep() |
|
33 | |||
34 | /** |
||
35 | * Add binding to container |
||
36 | * |
||
37 | * @param Bind $bind |
||
38 | */ |
||
39 | 46 | public function add(Bind $bind) |
|
44 | |||
45 | /** |
||
46 | * Add Pointcut to container |
||
47 | * |
||
48 | * @param Pointcut $pointcut |
||
49 | */ |
||
50 | 4 | public function addPointcut(Pointcut $pointcut) |
|
54 | |||
55 | /** |
||
56 | * Return instance by interface + name(interface namespace) |
||
57 | * |
||
58 | * @return mixed |
||
59 | */ |
||
60 | 13 | public function getInstance(string $interface, string $name) |
|
64 | |||
65 | /** |
||
66 | * Return dependency injected instance |
||
67 | * |
||
68 | * @throws Unbound |
||
69 | * |
||
70 | * @return mixed |
||
71 | */ |
||
72 | 33 | public function getDependency(string $index) |
|
81 | |||
82 | /** |
||
83 | * Rename existing dependency interface + name |
||
84 | */ |
||
85 | 3 | public function move(string $sourceInterface, string $sourceName, string $targetInterface, string $targetName) |
|
95 | |||
96 | /** |
||
97 | * Return Unbound exception |
||
98 | * |
||
99 | * @param string $index {interface}-{bind name} |
||
100 | * |
||
101 | * @return Untargeted|Unbound |
||
102 | */ |
||
103 | 9 | public function unbound(string $index) |
|
112 | |||
113 | /** |
||
114 | * Return container |
||
115 | * |
||
116 | * @return DependencyInterface[] |
||
117 | */ |
||
118 | 17 | public function getContainer() : array |
|
122 | |||
123 | /** |
||
124 | * Return pointcuts |
||
125 | * |
||
126 | * @return Pointcut[] |
||
127 | */ |
||
128 | 7 | public function getPointcuts() : array |
|
132 | |||
133 | /** |
||
134 | * Merge container |
||
135 | */ |
||
136 | 6 | public function merge(self $container) |
|
141 | |||
142 | /** |
||
143 | * Weave aspects to all dependency in container |
||
144 | */ |
||
145 | public function weaveAspects(CompilerInterface $compiler) |
||
154 | |||
155 | /** |
||
156 | * Weave aspect to single dependency |
||
157 | */ |
||
158 | public function weaveAspect(Compiler $compiler, Dependency $dependency) : self |
||
164 | } |
||
165 |
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: