@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $this->expectExceptionMessage('Enum `Spiral\Tests\Core\Stub\EnumObject` can not be constructed.'); |
| 64 | 64 | |
| 65 | 65 | $this->resolveClosure( |
| 66 | - static function (EnumObject $enum) {}, |
|
| 66 | + static function (EnumObject $enum){}, |
|
| 67 | 67 | ); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | 77 | $this->resolveClosure( |
| 78 | - static function (TestTrait $enum) {}, |
|
| 78 | + static function (TestTrait $enum){}, |
|
| 79 | 79 | ); |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -63,7 +63,9 @@ discard block |
||
| 63 | 63 | $this->expectExceptionMessage('Enum `Spiral\Tests\Core\Stub\EnumObject` can not be constructed.'); |
| 64 | 64 | |
| 65 | 65 | $this->resolveClosure( |
| 66 | - static function (EnumObject $enum) {}, |
|
| 66 | + static function (EnumObject $enum) |
|
| 67 | + { |
|
| 68 | +}, |
|
| 67 | 69 | ); |
| 68 | 70 | } |
| 69 | 71 | |
@@ -75,7 +77,9 @@ discard block |
||
| 75 | 77 | ); |
| 76 | 78 | |
| 77 | 79 | $this->resolveClosure( |
| 78 | - static function (TestTrait $enum) {}, |
|
| 80 | + static function (TestTrait $enum) |
|
| 81 | + { |
|
| 82 | +}, |
|
| 79 | 83 | ); |
| 80 | 84 | } |
| 81 | 85 | } |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | $this->expectException(ContainerException::class); |
| 81 | 81 | |
| 82 | - try { |
|
| 82 | + try{ |
|
| 83 | 83 | $container->get(WithContainerInside::class); |
| 84 | - } catch (ContainerException $e) { |
|
| 84 | + }catch (ContainerException $e){ |
|
| 85 | 85 | $this->assertSame( |
| 86 | 86 | \preg_replace('/\s+/', '', 'Can\'tresolve`Spiral\Tests\Core\Fixtures\ |
| 87 | 87 | WithContainerInside`:undefinedclassorbinding`Spiral\Tests\Core\Fixtures\InvalidClass`. |
@@ -101,9 +101,9 @@ discard block |
||
| 101 | 101 | { |
| 102 | 102 | $this->expectException(ContainerException::class); |
| 103 | 103 | |
| 104 | - try { |
|
| 104 | + try{ |
|
| 105 | 105 | $container->get(ClassWithUndefinedDependency::class); |
| 106 | - } catch (ContainerException $e) { |
|
| 106 | + }catch (ContainerException $e){ |
|
| 107 | 107 | $this->assertSame( |
| 108 | 108 | \preg_replace('/\s+/', '', $message), |
| 109 | 109 | \preg_replace('/\s+/', '', $e->getMessage()) |
@@ -79,9 +79,12 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | $this->expectException(ContainerException::class); |
| 81 | 81 | |
| 82 | - try { |
|
| 82 | + try |
|
| 83 | + { |
|
| 83 | 84 | $container->get(WithContainerInside::class); |
| 84 | - } catch (ContainerException $e) { |
|
| 85 | + } |
|
| 86 | + catch (ContainerException $e) |
|
| 87 | + { |
|
| 85 | 88 | $this->assertSame( |
| 86 | 89 | \preg_replace('/\s+/', '', 'Can\'tresolve`Spiral\Tests\Core\Fixtures\ |
| 87 | 90 | WithContainerInside`:undefinedclassorbinding`Spiral\Tests\Core\Fixtures\InvalidClass`. |
@@ -101,9 +104,12 @@ discard block |
||
| 101 | 104 | { |
| 102 | 105 | $this->expectException(ContainerException::class); |
| 103 | 106 | |
| 104 | - try { |
|
| 107 | + try |
|
| 108 | + { |
|
| 105 | 109 | $container->get(ClassWithUndefinedDependency::class); |
| 106 | - } catch (ContainerException $e) { |
|
| 110 | + } |
|
| 111 | + catch (ContainerException $e) |
|
| 112 | + { |
|
| 107 | 113 | $this->assertSame( |
| 108 | 114 | \preg_replace('/\s+/', '', $message), |
| 109 | 115 | \preg_replace('/\s+/', '', $e->getMessage()) |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | public readonly string $alias, |
| 14 | 14 | public readonly string $information, |
| 15 | 15 | public ?string $context = null |
| 16 | - ) { |
|
| 16 | + ){ |
|
| 17 | 17 | $this->context ??= '-'; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function __toString(): string |
| 21 | 21 | { |
| 22 | 22 | $result = []; |
| 23 | - $result[] = '- ' . $this->alias; |
|
| 24 | - $result[] = ' Info: ' . $this->information; |
|
| 25 | - $result[] = ' Context: ' . $this->context; |
|
| 23 | + $result[] = '- '.$this->alias; |
|
| 24 | + $result[] = ' Info: '.$this->information; |
|
| 25 | + $result[] = ' Context: '.$this->context; |
|
| 26 | 26 | |
| 27 | 27 | return \implode(PHP_EOL, $result); |
| 28 | 28 | } |
@@ -43,10 +43,12 @@ |
||
| 43 | 43 | public function __toString(): string |
| 44 | 44 | { |
| 45 | 45 | $result = []; |
| 46 | - if ($this->traces !== []) { |
|
| 46 | + if ($this->traces !== []) |
|
| 47 | + { |
|
| 47 | 48 | $result[] = 'Container trace list:'; |
| 48 | 49 | |
| 49 | - foreach ($this->traces as $item) { |
|
| 50 | + foreach ($this->traces as $item) |
|
| 51 | + { |
|
| 50 | 52 | $result[] = (string) $item; |
| 51 | 53 | } |
| 52 | 54 | } |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | public function __toString(): string |
| 18 | 18 | { |
| 19 | 19 | $result = []; |
| 20 | - if ($this->traces !== []) { |
|
| 20 | + if ($this->traces !== []){ |
|
| 21 | 21 | $result[] = 'Container trace list:'; |
| 22 | 22 | |
| 23 | - foreach ($this->traces as $item) { |
|
| 24 | - $result[] = (string) $item; |
|
| 23 | + foreach ($this->traces as $item){ |
|
| 24 | + $result[] = (string)$item; |
|
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | 27 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $this->trace($alias, 'Autowiring', $context); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function traceBinding(string $alias, string|array|object $binding, string $context = null): void |
|
| 36 | + public function traceBinding(string $alias, string | array | object $binding, string $context = null): void |
|
| 37 | 37 | { |
| 38 | 38 | $message = match (true) { |
| 39 | 39 | \is_string($binding) => \sprintf('Binding found `%s`', $binding), |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | int $code = 0, |
| 19 | 19 | ?\Throwable $previous = null, |
| 20 | 20 | protected ?Tracer $tracer = null |
| 21 | - ) { |
|
| 22 | - parent::__construct($tracer !== null ? $message . PHP_EOL . $tracer : $message, $code, $previous); |
|
| 21 | + ){ |
|
| 22 | + parent::__construct($tracer !== null ? $message.PHP_EOL.$tracer : $message, $code, $previous); |
|
| 23 | 23 | } |
| 24 | 24 | } |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | public readonly string $binder = Binder::class, |
| 41 | 41 | public readonly string $invoker = Invoker::class, |
| 42 | 42 | public readonly string $tracer = Tracer::class, |
| 43 | - ) { |
|
| 43 | + ){ |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public function getIterator(): Traversable |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function make(string $alias, array $parameters = [], string $context = null): mixed |
| 55 | 55 | { |
| 56 | - if (!isset($this->state->bindings[$alias])) { |
|
| 56 | + if (!isset($this->state->bindings[$alias])){ |
|
| 57 | 57 | $this->tracer->traceAutowire($alias, $context); |
| 58 | 58 | //No direct instructions how to construct class, make is automatically |
| 59 | 59 | return $this->autowire($alias, $parameters, $context); |
@@ -62,9 +62,9 @@ discard block |
||
| 62 | 62 | $binding = $this->state->bindings[$alias]; |
| 63 | 63 | $this->tracer->traceBinding($alias, $binding, $context); |
| 64 | 64 | |
| 65 | - if (\is_object($binding)) { |
|
| 66 | - if ($binding::class === WeakReference::class) { |
|
| 67 | - if ($binding->get() === null && \class_exists($alias)) { |
|
| 65 | + if (\is_object($binding)){ |
|
| 66 | + if ($binding::class === WeakReference::class){ |
|
| 67 | + if ($binding->get() === null && \class_exists($alias)){ |
|
| 68 | 68 | $object = $this->createInstance($alias, $parameters, $context); |
| 69 | 69 | $binding = $this->state->bindings[$alias] = WeakReference::create($object); |
| 70 | 70 | } |
@@ -74,23 +74,23 @@ discard block |
||
| 74 | 74 | return $binding; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if (\is_string($binding)) { |
|
| 77 | + if (\is_string($binding)){ |
|
| 78 | 78 | //Binding is pointing to something else |
| 79 | 79 | return $this->make($binding, $parameters, $context); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | unset($this->state->bindings[$alias]); |
| 83 | - try { |
|
| 83 | + try{ |
|
| 84 | 84 | $instance = $binding[0] === $alias |
| 85 | 85 | ? $this->autowire($alias, $parameters, $context) |
| 86 | 86 | : $this->evaluateBinding($alias, $binding[0], $parameters, $context); |
| 87 | - } finally { |
|
| 87 | + }finally{ |
|
| 88 | 88 | /** @psalm-var class-string $alias */ |
| 89 | 89 | $this->state->bindings[$alias] = $binding; |
| 90 | 90 | $this->tracer->clean(); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ($binding[1]) { |
|
| 93 | + if ($binding[1]){ |
|
| 94 | 94 | // Indicates singleton |
| 95 | 95 | /** @psalm-var class-string $alias */ |
| 96 | 96 | $this->state->bindings[$alias] = $instance; |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | private function autowire(string $class, array $parameters, string $context = null): object |
| 111 | 111 | { |
| 112 | - if (!\class_exists($class) && !isset($this->state->injectors[$class])) { |
|
| 112 | + if (!\class_exists($class) && !isset($this->state->injectors[$class])){ |
|
| 113 | 113 | throw new NotFoundException(\sprintf( |
| 114 | 114 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
| 115 | 115 | $this->tracer->getRootConstructedClass(), |
@@ -136,18 +136,18 @@ discard block |
||
| 136 | 136 | array $parameters, |
| 137 | 137 | string $context = null |
| 138 | 138 | ): mixed { |
| 139 | - if (\is_string($target)) { |
|
| 139 | + if (\is_string($target)){ |
|
| 140 | 140 | // Reference |
| 141 | 141 | return $this->make($target, $parameters, $context); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ($target instanceof Autowire) { |
|
| 144 | + if ($target instanceof Autowire){ |
|
| 145 | 145 | return $target->resolve($this, $parameters); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - try { |
|
| 148 | + try{ |
|
| 149 | 149 | return $this->invoker->invoke($target, $parameters); |
| 150 | - } catch (NotCallableException $e) { |
|
| 150 | + }catch (NotCallableException $e){ |
|
| 151 | 151 | throw new ContainerException( |
| 152 | 152 | \sprintf('Invalid binding for `%s`.', $alias), |
| 153 | 153 | $e->getCode(), |
@@ -172,20 +172,20 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | private function createInstance(string $class, array $parameters, string $context = null): object |
| 174 | 174 | { |
| 175 | - try { |
|
| 175 | + try{ |
|
| 176 | 176 | $reflection = new \ReflectionClass($class); |
| 177 | - } catch (\ReflectionException $e) { |
|
| 177 | + }catch (\ReflectionException $e){ |
|
| 178 | 178 | throw new ContainerException($e->getMessage(), $e->getCode(), $e, $this->tracer); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | //We have to construct class using external injector when we know exact context |
| 182 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
| 182 | + if ($parameters === [] && $this->binder->hasInjector($class)){ |
|
| 183 | 183 | $injector = $this->state->injectors[$reflection->getName()]; |
| 184 | 184 | |
| 185 | - try { |
|
| 185 | + try{ |
|
| 186 | 186 | $injectorInstance = $this->container->get($injector); |
| 187 | 187 | |
| 188 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 188 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
| 189 | 189 | throw new InjectionException( |
| 190 | 190 | \sprintf( |
| 191 | 191 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | |
| 198 | 198 | /** @var InjectorInterface<TObject> $injectorInstance */ |
| 199 | 199 | $instance = $injectorInstance->createInjection($reflection, $context); |
| 200 | - if (!$reflection->isInstance($instance)) { |
|
| 200 | + if (!$reflection->isInstance($instance)){ |
|
| 201 | 201 | throw new InjectionException( |
| 202 | 202 | \sprintf( |
| 203 | 203 | "Invalid injection response for '%s'.", |
@@ -207,12 +207,12 @@ discard block |
||
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | return $instance; |
| 210 | - } finally { |
|
| 210 | + }finally{ |
|
| 211 | 211 | $this->state->injectors[$reflection->getName()] = $injector; |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - if (!$reflection->isInstantiable()) { |
|
| 215 | + if (!$reflection->isInstantiable()){ |
|
| 216 | 216 | $itIs = match (true) { |
| 217 | 217 | $reflection->isEnum() => 'Enum', |
| 218 | 218 | $reflection->isAbstract() => 'Abstract class', |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | $constructor = $reflection->getConstructor(); |
| 230 | 230 | |
| 231 | - if ($constructor !== null) { |
|
| 232 | - try { |
|
| 231 | + if ($constructor !== null){ |
|
| 232 | + try{ |
|
| 233 | 233 | // Using constructor with resolved arguments |
| 234 | 234 | $instance = new $class(...$this->resolver->resolveArguments($constructor, $parameters)); |
| 235 | - } catch (\TypeError $e) { |
|
| 235 | + }catch (\TypeError $e){ |
|
| 236 | 236 | throw new WrongTypeException($constructor, $e); |
| 237 | 237 | } |
| 238 | - } else { |
|
| 238 | + }else{ |
|
| 239 | 239 | // No constructor specified |
| 240 | 240 | $instance = $reflection->newInstance(); |
| 241 | 241 | } |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | private function registerInstance(object $instance, array $parameters): object |
| 254 | 254 | { |
| 255 | 255 | //Declarative singletons (only when class received via direct get) |
| 256 | - if ($parameters === [] && $instance instanceof SingletonInterface) { |
|
| 256 | + if ($parameters === [] && $instance instanceof SingletonInterface){ |
|
| 257 | 257 | $alias = $instance::class; |
| 258 | - if (!isset($this->state->bindings[$alias])) { |
|
| 258 | + if (!isset($this->state->bindings[$alias])){ |
|
| 259 | 259 | $this->state->bindings[$alias] = $instance; |
| 260 | 260 | } |
| 261 | 261 | } |
@@ -53,7 +53,8 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function make(string $alias, array $parameters = [], string $context = null): mixed |
| 55 | 55 | { |
| 56 | - if (!isset($this->state->bindings[$alias])) { |
|
| 56 | + if (!isset($this->state->bindings[$alias])) |
|
| 57 | + { |
|
| 57 | 58 | $this->tracer->traceAutowire($alias, $context); |
| 58 | 59 | //No direct instructions how to construct class, make is automatically |
| 59 | 60 | return $this->autowire($alias, $parameters, $context); |
@@ -62,9 +63,12 @@ discard block |
||
| 62 | 63 | $binding = $this->state->bindings[$alias]; |
| 63 | 64 | $this->tracer->traceBinding($alias, $binding, $context); |
| 64 | 65 | |
| 65 | - if (\is_object($binding)) { |
|
| 66 | - if ($binding::class === WeakReference::class) { |
|
| 67 | - if ($binding->get() === null && \class_exists($alias)) { |
|
| 66 | + if (\is_object($binding)) |
|
| 67 | + { |
|
| 68 | + if ($binding::class === WeakReference::class) |
|
| 69 | + { |
|
| 70 | + if ($binding->get() === null && \class_exists($alias)) |
|
| 71 | + { |
|
| 68 | 72 | $object = $this->createInstance($alias, $parameters, $context); |
| 69 | 73 | $binding = $this->state->bindings[$alias] = WeakReference::create($object); |
| 70 | 74 | } |
@@ -74,23 +78,28 @@ discard block |
||
| 74 | 78 | return $binding; |
| 75 | 79 | } |
| 76 | 80 | |
| 77 | - if (\is_string($binding)) { |
|
| 81 | + if (\is_string($binding)) |
|
| 82 | + { |
|
| 78 | 83 | //Binding is pointing to something else |
| 79 | 84 | return $this->make($binding, $parameters, $context); |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | 87 | unset($this->state->bindings[$alias]); |
| 83 | - try { |
|
| 88 | + try |
|
| 89 | + { |
|
| 84 | 90 | $instance = $binding[0] === $alias |
| 85 | 91 | ? $this->autowire($alias, $parameters, $context) |
| 86 | 92 | : $this->evaluateBinding($alias, $binding[0], $parameters, $context); |
| 87 | - } finally { |
|
| 93 | + } |
|
| 94 | + finally |
|
| 95 | + { |
|
| 88 | 96 | /** @psalm-var class-string $alias */ |
| 89 | 97 | $this->state->bindings[$alias] = $binding; |
| 90 | 98 | $this->tracer->clean(); |
| 91 | 99 | } |
| 92 | 100 | |
| 93 | - if ($binding[1]) { |
|
| 101 | + if ($binding[1]) |
|
| 102 | + { |
|
| 94 | 103 | // Indicates singleton |
| 95 | 104 | /** @psalm-var class-string $alias */ |
| 96 | 105 | $this->state->bindings[$alias] = $instance; |
@@ -109,7 +118,8 @@ discard block |
||
| 109 | 118 | */ |
| 110 | 119 | private function autowire(string $class, array $parameters, string $context = null): object |
| 111 | 120 | { |
| 112 | - if (!\class_exists($class) && !isset($this->state->injectors[$class])) { |
|
| 121 | + if (!\class_exists($class) && !isset($this->state->injectors[$class])) |
|
| 122 | + { |
|
| 113 | 123 | throw new NotFoundException(\sprintf( |
| 114 | 124 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
| 115 | 125 | $this->tracer->getRootConstructedClass(), |
@@ -136,18 +146,23 @@ discard block |
||
| 136 | 146 | array $parameters, |
| 137 | 147 | string $context = null |
| 138 | 148 | ): mixed { |
| 139 | - if (\is_string($target)) { |
|
| 149 | + if (\is_string($target)) |
|
| 150 | + { |
|
| 140 | 151 | // Reference |
| 141 | 152 | return $this->make($target, $parameters, $context); |
| 142 | 153 | } |
| 143 | 154 | |
| 144 | - if ($target instanceof Autowire) { |
|
| 155 | + if ($target instanceof Autowire) |
|
| 156 | + { |
|
| 145 | 157 | return $target->resolve($this, $parameters); |
| 146 | 158 | } |
| 147 | 159 | |
| 148 | - try { |
|
| 160 | + try |
|
| 161 | + { |
|
| 149 | 162 | return $this->invoker->invoke($target, $parameters); |
| 150 | - } catch (NotCallableException $e) { |
|
| 163 | + } |
|
| 164 | + catch (NotCallableException $e) |
|
| 165 | + { |
|
| 151 | 166 | throw new ContainerException( |
| 152 | 167 | \sprintf('Invalid binding for `%s`.', $alias), |
| 153 | 168 | $e->getCode(), |
@@ -172,20 +187,26 @@ discard block |
||
| 172 | 187 | */ |
| 173 | 188 | private function createInstance(string $class, array $parameters, string $context = null): object |
| 174 | 189 | { |
| 175 | - try { |
|
| 190 | + try |
|
| 191 | + { |
|
| 176 | 192 | $reflection = new \ReflectionClass($class); |
| 177 | - } catch (\ReflectionException $e) { |
|
| 193 | + } |
|
| 194 | + catch (\ReflectionException $e) |
|
| 195 | + { |
|
| 178 | 196 | throw new ContainerException($e->getMessage(), $e->getCode(), $e, $this->tracer); |
| 179 | 197 | } |
| 180 | 198 | |
| 181 | 199 | //We have to construct class using external injector when we know exact context |
| 182 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
| 200 | + if ($parameters === [] && $this->binder->hasInjector($class)) |
|
| 201 | + { |
|
| 183 | 202 | $injector = $this->state->injectors[$reflection->getName()]; |
| 184 | 203 | |
| 185 | - try { |
|
| 204 | + try |
|
| 205 | + { |
|
| 186 | 206 | $injectorInstance = $this->container->get($injector); |
| 187 | 207 | |
| 188 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 208 | + if (!$injectorInstance instanceof InjectorInterface) |
|
| 209 | + { |
|
| 189 | 210 | throw new InjectionException( |
| 190 | 211 | \sprintf( |
| 191 | 212 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -197,7 +218,8 @@ discard block |
||
| 197 | 218 | |
| 198 | 219 | /** @var InjectorInterface<TObject> $injectorInstance */ |
| 199 | 220 | $instance = $injectorInstance->createInjection($reflection, $context); |
| 200 | - if (!$reflection->isInstance($instance)) { |
|
| 221 | + if (!$reflection->isInstance($instance)) |
|
| 222 | + { |
|
| 201 | 223 | throw new InjectionException( |
| 202 | 224 | \sprintf( |
| 203 | 225 | "Invalid injection response for '%s'.", |
@@ -207,12 +229,15 @@ discard block |
||
| 207 | 229 | } |
| 208 | 230 | |
| 209 | 231 | return $instance; |
| 210 | - } finally { |
|
| 232 | + } |
|
| 233 | + finally |
|
| 234 | + { |
|
| 211 | 235 | $this->state->injectors[$reflection->getName()] = $injector; |
| 212 | 236 | } |
| 213 | 237 | } |
| 214 | 238 | |
| 215 | - if (!$reflection->isInstantiable()) { |
|
| 239 | + if (!$reflection->isInstantiable()) |
|
| 240 | + { |
|
| 216 | 241 | $itIs = match (true) { |
| 217 | 242 | $reflection->isEnum() => 'Enum', |
| 218 | 243 | $reflection->isAbstract() => 'Abstract class', |
@@ -228,14 +253,20 @@ discard block |
||
| 228 | 253 | |
| 229 | 254 | $constructor = $reflection->getConstructor(); |
| 230 | 255 | |
| 231 | - if ($constructor !== null) { |
|
| 232 | - try { |
|
| 256 | + if ($constructor !== null) |
|
| 257 | + { |
|
| 258 | + try |
|
| 259 | + { |
|
| 233 | 260 | // Using constructor with resolved arguments |
| 234 | 261 | $instance = new $class(...$this->resolver->resolveArguments($constructor, $parameters)); |
| 235 | - } catch (\TypeError $e) { |
|
| 262 | + } |
|
| 263 | + catch (\TypeError $e) |
|
| 264 | + { |
|
| 236 | 265 | throw new WrongTypeException($constructor, $e); |
| 237 | 266 | } |
| 238 | - } else { |
|
| 267 | + } |
|
| 268 | + else |
|
| 269 | + { |
|
| 239 | 270 | // No constructor specified |
| 240 | 271 | $instance = $reflection->newInstance(); |
| 241 | 272 | } |
@@ -253,9 +284,11 @@ discard block |
||
| 253 | 284 | private function registerInstance(object $instance, array $parameters): object |
| 254 | 285 | { |
| 255 | 286 | //Declarative singletons (only when class received via direct get) |
| 256 | - if ($parameters === [] && $instance instanceof SingletonInterface) { |
|
| 287 | + if ($parameters === [] && $instance instanceof SingletonInterface) |
|
| 288 | + { |
|
| 257 | 289 | $alias = $instance::class; |
| 258 | - if (!isset($this->state->bindings[$alias])) { |
|
| 290 | + if (!isset($this->state->bindings[$alias])) |
|
| 291 | + { |
|
| 259 | 292 | $this->state->bindings[$alias] = $instance; |
| 260 | 293 | } |
| 261 | 294 | } |