@@ -40,14 +40,18 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function bind(string $alias, mixed $resolver): void |
42 | 42 | { |
43 | - if ($resolver instanceof Inflector && (\interface_exists($alias) || \class_exists($alias))) { |
|
43 | + if ($resolver instanceof Inflector && (\interface_exists($alias) || \class_exists($alias))) |
|
44 | + { |
|
44 | 45 | $this->state->inflectors[$alias][] = $resolver; |
45 | 46 | return; |
46 | 47 | } |
47 | 48 | |
48 | - try { |
|
49 | + try |
|
50 | + { |
|
49 | 51 | $config = $this->makeConfig($resolver, false); |
50 | - } catch (\Throwable $e) { |
|
52 | + } |
|
53 | + catch (\Throwable $e) |
|
54 | + { |
|
51 | 55 | throw $this->invalidBindingException($alias, $e); |
52 | 56 | } |
53 | 57 | |
@@ -59,9 +63,12 @@ discard block |
||
59 | 63 | */ |
60 | 64 | public function bindSingleton(string $alias, mixed $resolver): void |
61 | 65 | { |
62 | - try { |
|
66 | + try |
|
67 | + { |
|
63 | 68 | $config = $this->makeConfig($resolver, true); |
64 | - } catch (\Throwable $e) { |
|
69 | + } |
|
70 | + catch (\Throwable $e) |
|
71 | + { |
|
65 | 72 | throw $this->invalidBindingException($alias, $e); |
66 | 73 | } |
67 | 74 | |
@@ -73,9 +80,11 @@ discard block |
||
73 | 80 | $bindings = &$this->state->bindings; |
74 | 81 | |
75 | 82 | $flags = []; |
76 | - while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class) { |
|
83 | + while ($binding = $bindings[$alias] ?? null and $binding::class === Alias::class) |
|
84 | + { |
|
77 | 85 | //Checking alias tree |
78 | - if ($flags[$binding->alias] ?? false) { |
|
86 | + if ($flags[$binding->alias] ?? false) |
|
87 | + { |
|
79 | 88 | return $binding->alias === $alias ?: throw new Exception('Circular alias detected'); |
80 | 89 | } |
81 | 90 | |
@@ -100,7 +109,8 @@ discard block |
||
100 | 109 | public function removeInjector(string $class): void |
101 | 110 | { |
102 | 111 | unset($this->state->injectors[$class]); |
103 | - if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) { |
|
112 | + if (!isset($this->state->bindings[$class]) || $this->state->bindings[$class]::class !== Injectable::class) |
|
113 | + { |
|
104 | 114 | return; |
105 | 115 | } |
106 | 116 | unset($this->state->bindings[$class]); |
@@ -108,13 +118,17 @@ discard block |
||
108 | 118 | |
109 | 119 | public function hasInjector(string $class): bool |
110 | 120 | { |
111 | - try { |
|
121 | + try |
|
122 | + { |
|
112 | 123 | $reflection = new \ReflectionClass($class); |
113 | - } catch (\ReflectionException $e) { |
|
124 | + } |
|
125 | + catch (\ReflectionException $e) |
|
126 | + { |
|
114 | 127 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
115 | 128 | } |
116 | 129 | |
117 | - if (\array_key_exists($class, $this->state->injectors)) { |
|
130 | + if (\array_key_exists($class, $this->state->injectors)) |
|
131 | + { |
|
118 | 132 | return true; |
119 | 133 | } |
120 | 134 | |
@@ -129,7 +143,8 @@ discard block |
||
129 | 143 | } |
130 | 144 | |
131 | 145 | // check interfaces |
132 | - foreach ($this->state->injectors as $target => $injector) { |
|
146 | + foreach ($this->state->injectors as $target => $injector) |
|
147 | + { |
|
133 | 148 | if ( |
134 | 149 | (\class_exists($target, true) && $reflection->isSubclassOf($target)) |
135 | 150 | || |
@@ -161,15 +176,18 @@ discard block |
||
161 | 176 | |
162 | 177 | private function makeConfigFromArray(array $resolver, bool $singleton): Binding |
163 | 178 | { |
164 | - if (\is_callable($resolver)) { |
|
179 | + if (\is_callable($resolver)) |
|
180 | + { |
|
165 | 181 | return new Factory($resolver, $singleton); |
166 | 182 | } |
167 | 183 | |
168 | 184 | // Validate lazy invokable array |
169 | - if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') { |
|
185 | + if (!isset($resolver[0]) || !isset($resolver[1]) || !\is_string($resolver[1]) || $resolver[1] === '') |
|
186 | + { |
|
170 | 187 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
171 | 188 | } |
172 | - if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') { |
|
189 | + if ((!\is_string($resolver[0]) && !\is_object($resolver[0])) || $resolver[0] === '') |
|
190 | + { |
|
173 | 191 | throw new InvalidArgumentException('Incompatible array declaration for resolver.'); |
174 | 192 | } |
175 | 193 | |
@@ -187,7 +205,8 @@ discard block |
||
187 | 205 | |
188 | 206 | private function setBinding(string $alias, Binding $config): void |
189 | 207 | { |
190 | - if (isset($this->state->singletons[$alias])) { |
|
208 | + if (isset($this->state->singletons[$alias])) |
|
209 | + { |
|
191 | 210 | throw new SingletonOverloadException($alias); |
192 | 211 | } |
193 | 212 |