@@ -31,7 +31,7 @@ |
||
| 31 | 31 | $option->checkScope = true; |
| 32 | 32 | yield [$option]; |
| 33 | 33 | |
| 34 | - $option = new class extends Options { |
|
| 34 | + $option = new class extends Options{ |
|
| 35 | 35 | public int $customOption = 3; |
| 36 | 36 | }; |
| 37 | 37 | $option->customOption = 5; |
@@ -31,7 +31,8 @@ |
||
| 31 | 31 | $option->checkScope = true; |
| 32 | 32 | yield [$option]; |
| 33 | 33 | |
| 34 | - $option = new class extends Options { |
|
| 34 | + $option = new class extends Options |
|
| 35 | + { |
|
| 35 | 36 | public int $customOption = 3; |
| 36 | 37 | }; |
| 37 | 38 | $option->customOption = 5; |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | $root = self::makeContainer(); |
| 42 | 42 | |
| 43 | - $root->runScoped(static function (Container $c1) { |
|
| 43 | + $root->runScoped(static function (Container $c1){ |
|
| 44 | 44 | $c1->runScoped(static function (Container $c2) use ($c1) { |
| 45 | 45 | $obj1 = $c1->get(AttrScopeFooSingleton::class); |
| 46 | 46 | $obj2 = $c2->get(AttrScopeFooSingleton::class); |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | $root = self::makeContainer(); |
| 56 | 56 | $root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo()); |
| 57 | 57 | |
| 58 | - $root->runScoped(static function (Container $fooScope) { |
|
| 59 | - $fooScope->runScoped(static function (Container $container) { |
|
| 58 | + $root->runScoped(static function (Container $fooScope){ |
|
| 59 | + $fooScope->runScoped(static function (Container $container){ |
|
| 60 | 60 | self::assertInstanceOf(AttrScopeFoo::class, $container->get('binding')); |
| 61 | 61 | }, name: 'bar'); |
| 62 | 62 | }, name: 'foo'); |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | $root = self::makeContainer(); |
| 71 | 71 | $root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo()); |
| 72 | 72 | |
| 73 | - $root->runScoped(static function (Container $fooScope) { |
|
| 74 | - $fooScope->runScoped(static function (Container $container) { |
|
| 73 | + $root->runScoped(static function (Container $fooScope){ |
|
| 74 | + $fooScope->runScoped(static function (Container $container){ |
|
| 75 | 75 | $container->get('binding'); |
| 76 | 76 | }, name: 'bar'); |
| 77 | 77 | }, name: 'baz'); |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | $root = self::makeContainer(false); |
| 83 | 83 | $root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo()); |
| 84 | 84 | |
| 85 | - $root->runScoped(static function (Container $fooScope) { |
|
| 86 | - $fooScope->runScoped(static function (Container $container) { |
|
| 85 | + $root->runScoped(static function (Container $fooScope){ |
|
| 86 | + $fooScope->runScoped(static function (Container $container){ |
|
| 87 | 87 | self::assertInstanceOf(AttrScopeFoo::class, $container->get('binding')); |
| 88 | 88 | }, name: 'bar'); |
| 89 | 89 | }, name: 'baz'); |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | $root = self::makeContainer(); |
| 103 | 103 | $root->bind('foo', self::makeFooScopeObject(...)); |
| 104 | 104 | |
| 105 | - $root->runScoped(static function (Container $c1) { |
|
| 106 | - $c1->runScoped(static function (Container $c2) { |
|
| 105 | + $root->runScoped(static function (Container $c1){ |
|
| 106 | + $c1->runScoped(static function (Container $c2){ |
|
| 107 | 107 | $c2->get('foo'); |
| 108 | 108 | }, name: 'foo'); |
| 109 | 109 | }); |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | $root = self::makeContainer(false); |
| 116 | 116 | $root->bind('foo', self::makeFooScopeObject(...)); |
| 117 | 117 | |
| 118 | - $root->runScoped(static function (Container $c1) { |
|
| 119 | - $c1->runScoped(static function (Container $c2) { |
|
| 118 | + $root->runScoped(static function (Container $c1){ |
|
| 119 | + $c1->runScoped(static function (Container $c2){ |
|
| 120 | 120 | self::assertInstanceOf(AttrScopeFoo::class, $c2->get('foo')); |
| 121 | 121 | }, name: 'foo'); |
| 122 | 122 | }); |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | $root = self::makeContainer(); |
| 135 | 135 | $root->bind('foo', self::makeFooScopeObject(...)); |
| 136 | 136 | |
| 137 | - $root->runScoped(static function (Container $c1) { |
|
| 138 | - $c1->runScoped(static function (Container $c2) { |
|
| 137 | + $root->runScoped(static function (Container $c1){ |
|
| 138 | + $c1->runScoped(static function (Container $c2){ |
|
| 139 | 139 | $c2->get('foo'); |
| 140 | 140 | }); |
| 141 | 141 | }); |
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | $root = self::makeContainer(false); |
| 148 | 148 | $root->bind('foo', self::makeFooScopeObject(...)); |
| 149 | 149 | |
| 150 | - $root->runScoped(static function (Container $c1) { |
|
| 151 | - $c1->runScoped(static function (Container $c2) { |
|
| 150 | + $root->runScoped(static function (Container $c1){ |
|
| 151 | + $c1->runScoped(static function (Container $c2){ |
|
| 152 | 152 | self::assertInstanceOf(AttrScopeFoo::class, $c2->get('foo')); |
| 153 | 153 | }); |
| 154 | 154 | }); |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | $root = self::makeContainer(); |
| 168 | 168 | |
| 169 | - try { |
|
| 170 | - $root->runScoped(static function (Container $c1) { |
|
| 171 | - $c1->runScoped(static function (Container $c2) { |
|
| 172 | - $c2->runScoped(static function (Container $c3) { |
|
| 169 | + try{ |
|
| 170 | + $root->runScoped(static function (Container $c1){ |
|
| 171 | + $c1->runScoped(static function (Container $c2){ |
|
| 172 | + $c2->runScoped(static function (Container $c3){ |
|
| 173 | 173 | // do nothing |
| 174 | 174 | }, name: 'root'); |
| 175 | 175 | }); |
| 176 | 176 | }); |
| 177 | - } catch (NamedScopeDuplicationException $e) { |
|
| 177 | + }catch (NamedScopeDuplicationException $e){ |
|
| 178 | 178 | self::assertSame('root', $e->getScope()); |
| 179 | 179 | throw $e; |
| 180 | 180 | } |
@@ -189,14 +189,14 @@ discard block |
||
| 189 | 189 | { |
| 190 | 190 | self::expectException(BadScopeException::class); |
| 191 | 191 | |
| 192 | - try { |
|
| 192 | + try{ |
|
| 193 | 193 | $root = self::makeContainer(); |
| 194 | - $root->runScoped(static function (Container $c1) { |
|
| 195 | - $c1->runScoped(static function (Container $c2) { |
|
| 194 | + $root->runScoped(static function (Container $c1){ |
|
| 195 | + $c1->runScoped(static function (Container $c2){ |
|
| 196 | 196 | $c2->get(AttrScopeFoo::class); |
| 197 | 197 | }); |
| 198 | 198 | }, name: 'bar'); |
| 199 | - } catch (BadScopeException $e) { |
|
| 199 | + }catch (BadScopeException $e){ |
|
| 200 | 200 | self::assertSame('foo', $e->getScope()); |
| 201 | 201 | throw $e; |
| 202 | 202 | } |
@@ -40,8 +40,10 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | $root = self::makeContainer(); |
| 42 | 42 | |
| 43 | - $root->runScoped(static function (Container $c1) { |
|
| 44 | - $c1->runScoped(static function (Container $c2) use ($c1) { |
|
| 43 | + $root->runScoped(static function (Container $c1) |
|
| 44 | + { |
|
| 45 | + $c1->runScoped(static function (Container $c2) use ($c1) |
|
| 46 | + { |
|
| 45 | 47 | $obj1 = $c1->get(AttrScopeFooSingleton::class); |
| 46 | 48 | $obj2 = $c2->get(AttrScopeFooSingleton::class); |
| 47 | 49 | |
@@ -55,8 +57,10 @@ discard block |
||
| 55 | 57 | $root = self::makeContainer(); |
| 56 | 58 | $root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo()); |
| 57 | 59 | |
| 58 | - $root->runScoped(static function (Container $fooScope) { |
|
| 59 | - $fooScope->runScoped(static function (Container $container) { |
|
| 60 | + $root->runScoped(static function (Container $fooScope) |
|
| 61 | + { |
|
| 62 | + $fooScope->runScoped(static function (Container $container) |
|
| 63 | + { |
|
| 60 | 64 | self::assertInstanceOf(AttrScopeFoo::class, $container->get('binding')); |
| 61 | 65 | }, name: 'bar'); |
| 62 | 66 | }, name: 'foo'); |
@@ -70,8 +74,10 @@ discard block |
||
| 70 | 74 | $root = self::makeContainer(); |
| 71 | 75 | $root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo()); |
| 72 | 76 | |
| 73 | - $root->runScoped(static function (Container $fooScope) { |
|
| 74 | - $fooScope->runScoped(static function (Container $container) { |
|
| 77 | + $root->runScoped(static function (Container $fooScope) |
|
| 78 | + { |
|
| 79 | + $fooScope->runScoped(static function (Container $container) |
|
| 80 | + { |
|
| 75 | 81 | $container->get('binding'); |
| 76 | 82 | }, name: 'bar'); |
| 77 | 83 | }, name: 'baz'); |
@@ -82,8 +88,10 @@ discard block |
||
| 82 | 88 | $root = self::makeContainer(false); |
| 83 | 89 | $root->getBinder('bar')->bindSingleton('binding', static fn () => new AttrScopeFoo()); |
| 84 | 90 | |
| 85 | - $root->runScoped(static function (Container $fooScope) { |
|
| 86 | - $fooScope->runScoped(static function (Container $container) { |
|
| 91 | + $root->runScoped(static function (Container $fooScope) |
|
| 92 | + { |
|
| 93 | + $fooScope->runScoped(static function (Container $container) |
|
| 94 | + { |
|
| 87 | 95 | self::assertInstanceOf(AttrScopeFoo::class, $container->get('binding')); |
| 88 | 96 | }, name: 'bar'); |
| 89 | 97 | }, name: 'baz'); |
@@ -102,8 +110,10 @@ discard block |
||
| 102 | 110 | $root = self::makeContainer(); |
| 103 | 111 | $root->bind('foo', self::makeFooScopeObject(...)); |
| 104 | 112 | |
| 105 | - $root->runScoped(static function (Container $c1) { |
|
| 106 | - $c1->runScoped(static function (Container $c2) { |
|
| 113 | + $root->runScoped(static function (Container $c1) |
|
| 114 | + { |
|
| 115 | + $c1->runScoped(static function (Container $c2) |
|
| 116 | + { |
|
| 107 | 117 | $c2->get('foo'); |
| 108 | 118 | }, name: 'foo'); |
| 109 | 119 | }); |
@@ -115,8 +125,10 @@ discard block |
||
| 115 | 125 | $root = self::makeContainer(false); |
| 116 | 126 | $root->bind('foo', self::makeFooScopeObject(...)); |
| 117 | 127 | |
| 118 | - $root->runScoped(static function (Container $c1) { |
|
| 119 | - $c1->runScoped(static function (Container $c2) { |
|
| 128 | + $root->runScoped(static function (Container $c1) |
|
| 129 | + { |
|
| 130 | + $c1->runScoped(static function (Container $c2) |
|
| 131 | + { |
|
| 120 | 132 | self::assertInstanceOf(AttrScopeFoo::class, $c2->get('foo')); |
| 121 | 133 | }, name: 'foo'); |
| 122 | 134 | }); |
@@ -134,8 +146,10 @@ discard block |
||
| 134 | 146 | $root = self::makeContainer(); |
| 135 | 147 | $root->bind('foo', self::makeFooScopeObject(...)); |
| 136 | 148 | |
| 137 | - $root->runScoped(static function (Container $c1) { |
|
| 138 | - $c1->runScoped(static function (Container $c2) { |
|
| 149 | + $root->runScoped(static function (Container $c1) |
|
| 150 | + { |
|
| 151 | + $c1->runScoped(static function (Container $c2) |
|
| 152 | + { |
|
| 139 | 153 | $c2->get('foo'); |
| 140 | 154 | }); |
| 141 | 155 | }); |
@@ -147,8 +161,10 @@ discard block |
||
| 147 | 161 | $root = self::makeContainer(false); |
| 148 | 162 | $root->bind('foo', self::makeFooScopeObject(...)); |
| 149 | 163 | |
| 150 | - $root->runScoped(static function (Container $c1) { |
|
| 151 | - $c1->runScoped(static function (Container $c2) { |
|
| 164 | + $root->runScoped(static function (Container $c1) |
|
| 165 | + { |
|
| 166 | + $c1->runScoped(static function (Container $c2) |
|
| 167 | + { |
|
| 152 | 168 | self::assertInstanceOf(AttrScopeFoo::class, $c2->get('foo')); |
| 153 | 169 | }); |
| 154 | 170 | }); |
@@ -166,15 +182,21 @@ discard block |
||
| 166 | 182 | |
| 167 | 183 | $root = self::makeContainer(); |
| 168 | 184 | |
| 169 | - try { |
|
| 170 | - $root->runScoped(static function (Container $c1) { |
|
| 171 | - $c1->runScoped(static function (Container $c2) { |
|
| 172 | - $c2->runScoped(static function (Container $c3) { |
|
| 185 | + try |
|
| 186 | + { |
|
| 187 | + $root->runScoped(static function (Container $c1) |
|
| 188 | + { |
|
| 189 | + $c1->runScoped(static function (Container $c2) |
|
| 190 | + { |
|
| 191 | + $c2->runScoped(static function (Container $c3) |
|
| 192 | + { |
|
| 173 | 193 | // do nothing |
| 174 | 194 | }, name: 'root'); |
| 175 | 195 | }); |
| 176 | 196 | }); |
| 177 | - } catch (NamedScopeDuplicationException $e) { |
|
| 197 | + } |
|
| 198 | + catch (NamedScopeDuplicationException $e) |
|
| 199 | + { |
|
| 178 | 200 | self::assertSame('root', $e->getScope()); |
| 179 | 201 | throw $e; |
| 180 | 202 | } |
@@ -189,14 +211,19 @@ discard block |
||
| 189 | 211 | { |
| 190 | 212 | self::expectException(BadScopeException::class); |
| 191 | 213 | |
| 192 | - try { |
|
| 214 | + try |
|
| 215 | + { |
|
| 193 | 216 | $root = self::makeContainer(); |
| 194 | - $root->runScoped(static function (Container $c1) { |
|
| 195 | - $c1->runScoped(static function (Container $c2) { |
|
| 217 | + $root->runScoped(static function (Container $c1) |
|
| 218 | + { |
|
| 219 | + $c1->runScoped(static function (Container $c2) |
|
| 220 | + { |
|
| 196 | 221 | $c2->get(AttrScopeFoo::class); |
| 197 | 222 | }); |
| 198 | 223 | }, name: 'bar'); |
| 199 | - } catch (BadScopeException $e) { |
|
| 224 | + } |
|
| 225 | + catch (BadScopeException $e) |
|
| 226 | + { |
|
| 200 | 227 | self::assertSame('foo', $e->getScope()); |
| 201 | 228 | throw $e; |
| 202 | 229 | } |
@@ -66,19 +66,19 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @throws \Throwable |
| 68 | 68 | */ |
| 69 | - public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed |
|
| 69 | + public function make(string $alias, array $parameters = [], Stringable | string | null $context = null): mixed |
|
| 70 | 70 | { |
| 71 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
| 71 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){ |
|
| 72 | 72 | return $this->state->singletons[$alias]; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $binding = $this->state->bindings[$alias] ?? null; |
| 76 | 76 | |
| 77 | - if ($binding === null) { |
|
| 77 | + if ($binding === null){ |
|
| 78 | 78 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - try { |
|
| 81 | + try{ |
|
| 82 | 82 | $this->tracer->push( |
| 83 | 83 | false, |
| 84 | 84 | action: 'resolve from binding', |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
| 109 | 109 | default => $binding, |
| 110 | 110 | }; |
| 111 | - } finally { |
|
| 111 | + }finally{ |
|
| 112 | 112 | $this->state->bindings[$alias] ??= $binding; |
| 113 | 113 | $this->tracer->pop(true); |
| 114 | 114 | $this->tracer->pop(false); |
@@ -122,18 +122,18 @@ discard block |
||
| 122 | 122 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments) |
| 123 | 123 | { |
| 124 | 124 | $context = $ctx->context; |
| 125 | - try { |
|
| 125 | + try{ |
|
| 126 | 126 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
| 127 | - } catch (\ReflectionException $e) { |
|
| 127 | + }catch (\ReflectionException $e){ |
|
| 128 | 128 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | $injector = $binding->injector; |
| 132 | 132 | |
| 133 | - try { |
|
| 133 | + try{ |
|
| 134 | 134 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 135 | 135 | |
| 136 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 136 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
| 137 | 137 | throw new InjectionException( |
| 138 | 138 | \sprintf( |
| 139 | 139 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | default => (string)$context, |
| 161 | 161 | }); |
| 162 | 162 | |
| 163 | - if (!$reflection->isInstance($instance)) { |
|
| 163 | + if (!$reflection->isInstance($instance)){ |
|
| 164 | 164 | throw new InjectionException( |
| 165 | 165 | \sprintf( |
| 166 | 166 | "Invalid injection response for '%s'.", |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | return $instance; |
| 173 | - } finally { |
|
| 173 | + }finally{ |
|
| 174 | 174 | $this->state->bindings[$ctx->class] ??= $binding; |
| 175 | 175 | } |
| 176 | 176 | } |
@@ -178,29 +178,29 @@ discard block |
||
| 178 | 178 | private function resolveAlias( |
| 179 | 179 | Config\Alias $binding, |
| 180 | 180 | string $alias, |
| 181 | - Stringable|string|null $context, |
|
| 181 | + Stringable | string | null $context, |
|
| 182 | 182 | array $arguments, |
| 183 | 183 | ): mixed { |
| 184 | 184 | $result = $binding->alias === $alias |
| 185 | 185 | ? $this->autowire( |
| 186 | - new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton), |
|
| 186 | + new Ctx(alias : $alias, class : $binding->alias, context : $context, singleton : $binding->singleton), |
|
| 187 | 187 | $arguments, |
| 188 | 188 | ) |
| 189 | 189 | //Binding is pointing to something else |
| 190 | 190 | : $this->make($binding->alias, $arguments, $context); |
| 191 | 191 | |
| 192 | - if ($binding->singleton && $arguments === []) { |
|
| 192 | + if ($binding->singleton && $arguments === []){ |
|
| 193 | 193 | $this->state->singletons[$alias] = $result; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | return $result; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - private function resolveProxy(Config\Proxy $binding, string $alias, Stringable|string|null $context): mixed |
|
| 199 | + private function resolveProxy(Config\Proxy $binding, string $alias, Stringable | string | null $context): mixed |
|
| 200 | 200 | { |
| 201 | 201 | $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy()); |
| 202 | 202 | |
| 203 | - if ($binding->singleton) { |
|
| 203 | + if ($binding->singleton){ |
|
| 204 | 204 | $this->state->singletons[$alias] = $result; |
| 205 | 205 | } |
| 206 | 206 | |
@@ -210,13 +210,13 @@ discard block |
||
| 210 | 210 | private function resolveShared( |
| 211 | 211 | Config\Shared $binding, |
| 212 | 212 | string $alias, |
| 213 | - Stringable|string|null $context, |
|
| 213 | + Stringable | string | null $context, |
|
| 214 | 214 | array $arguments, |
| 215 | 215 | ): object { |
| 216 | 216 | $avoidCache = $arguments !== []; |
| 217 | 217 | return $avoidCache |
| 218 | 218 | ? $this->createInstance( |
| 219 | - new Ctx(alias: $alias, class: $binding->value::class, context: $context), |
|
| 219 | + new Ctx(alias : $alias, class : $binding->value::class, context : $context), |
|
| 220 | 220 | $arguments, |
| 221 | 221 | ) |
| 222 | 222 | : $binding->value; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | private function resolveAutowire( |
| 226 | 226 | Config\Autowire $binding, |
| 227 | 227 | string $alias, |
| 228 | - Stringable|string|null $context, |
|
| 228 | + Stringable | string | null $context, |
|
| 229 | 229 | array $arguments, |
| 230 | 230 | ): mixed { |
| 231 | 231 | $instance = $binding->autowire->resolve($this, $arguments); |
@@ -235,17 +235,17 @@ discard block |
||
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | private function resolveFactory( |
| 238 | - Config\Factory|Config\DeferredFactory $binding, |
|
| 238 | + Config\Factory | Config\DeferredFactory $binding, |
|
| 239 | 239 | string $alias, |
| 240 | - Stringable|string|null $context, |
|
| 240 | + Stringable | string | null $context, |
|
| 241 | 241 | array $arguments, |
| 242 | 242 | ): mixed { |
| 243 | 243 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
| 244 | - try { |
|
| 244 | + try{ |
|
| 245 | 245 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
| 246 | 246 | ? ($binding->factory)() |
| 247 | 247 | : $this->invoker->invoke($binding->factory, $arguments); |
| 248 | - } catch (NotCallableException $e) { |
|
| 248 | + }catch (NotCallableException $e){ |
|
| 249 | 249 | throw new ContainerException( |
| 250 | 250 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
| 251 | 251 | $e->getCode(), |
@@ -259,24 +259,24 @@ discard block |
||
| 259 | 259 | private function resolveWeakReference( |
| 260 | 260 | Config\WeakReference $binding, |
| 261 | 261 | string $alias, |
| 262 | - Stringable|string|null $context, |
|
| 262 | + Stringable | string | null $context, |
|
| 263 | 263 | array $arguments, |
| 264 | 264 | ): ?object { |
| 265 | 265 | $avoidCache = $arguments !== []; |
| 266 | 266 | |
| 267 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 268 | - try { |
|
| 267 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){ |
|
| 268 | + try{ |
|
| 269 | 269 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
| 270 | 270 | |
| 271 | 271 | $object = $this->createInstance( |
| 272 | 272 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 273 | 273 | $arguments, |
| 274 | 274 | ); |
| 275 | - if ($avoidCache) { |
|
| 275 | + if ($avoidCache){ |
|
| 276 | 276 | return $object; |
| 277 | 277 | } |
| 278 | 278 | $binding->reference = WeakReference::create($object); |
| 279 | - } catch (\Throwable) { |
|
| 279 | + }catch (\Throwable){ |
|
| 280 | 280 | throw new ContainerException( |
| 281 | 281 | $this->tracer->combineTraceMessage( |
| 282 | 282 | \sprintf( |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | ) |
| 287 | 287 | ) |
| 288 | 288 | ); |
| 289 | - } finally { |
|
| 289 | + }finally{ |
|
| 290 | 290 | $this->tracer->pop(); |
| 291 | 291 | } |
| 292 | 292 | } |
@@ -297,23 +297,23 @@ discard block |
||
| 297 | 297 | private function resolveWithoutBinding( |
| 298 | 298 | string $alias, |
| 299 | 299 | array $parameters = [], |
| 300 | - Stringable|string|null $context = null |
|
| 300 | + Stringable | string | null $context = null |
|
| 301 | 301 | ): mixed { |
| 302 | 302 | $parent = $this->scope->getParentFactory(); |
| 303 | 303 | |
| 304 | - if ($parent !== null) { |
|
| 305 | - try { |
|
| 304 | + if ($parent !== null){ |
|
| 305 | + try{ |
|
| 306 | 306 | $this->tracer->push(false, ...[ |
| 307 | 307 | 'current scope' => $this->scope->getScopeName(), |
| 308 | 308 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
| 309 | 309 | ]); |
| 310 | 310 | /** @psalm-suppress TooManyArguments */ |
| 311 | 311 | return $parent->make($alias, $parameters, $context); |
| 312 | - } catch (BadScopeException $e) { |
|
| 313 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
| 312 | + }catch (BadScopeException $e){ |
|
| 313 | + if ($this->scope->getScopeName() !== $e->getScope()){ |
|
| 314 | 314 | throw $e; |
| 315 | 315 | } |
| 316 | - } catch (ContainerExceptionInterface $e) { |
|
| 316 | + }catch (ContainerExceptionInterface $e){ |
|
| 317 | 317 | $className = match (true) { |
| 318 | 318 | $e instanceof NotFoundException => NotFoundException::class, |
| 319 | 319 | default => ContainerException::class, |
@@ -322,19 +322,19 @@ discard block |
||
| 322 | 322 | 'Can\'t resolve `%s`.', |
| 323 | 323 | $alias, |
| 324 | 324 | )), previous: $e); |
| 325 | - } finally { |
|
| 325 | + }finally{ |
|
| 326 | 326 | $this->tracer->pop(false); |
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
| 331 | - try { |
|
| 331 | + try{ |
|
| 332 | 332 | //No direct instructions how to construct class, make is automatically |
| 333 | 333 | return $this->autowire( |
| 334 | 334 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 335 | 335 | $parameters, |
| 336 | 336 | ); |
| 337 | - } finally { |
|
| 337 | + }finally{ |
|
| 338 | 338 | $this->tracer->pop(false); |
| 339 | 339 | } |
| 340 | 340 | } |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | && |
| 356 | 356 | (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class)) |
| 357 | 357 | )) |
| 358 | - ) { |
|
| 358 | + ){ |
|
| 359 | 359 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
| 360 | 360 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
| 361 | 361 | $this->tracer->getRootAlias(), |
@@ -384,9 +384,9 @@ discard block |
||
| 384 | 384 | // Check scope name |
| 385 | 385 | $ctx->reflection = new \ReflectionClass($instance); |
| 386 | 386 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 387 | - if ($scopeName !== null && $this->options->checkScope) { |
|
| 387 | + if ($scopeName !== null && $this->options->checkScope){ |
|
| 388 | 388 | $scope = $this->scope; |
| 389 | - while ($scope->getScopeName() !== $scopeName) { |
|
| 389 | + while ($scope->getScopeName() !== $scopeName){ |
|
| 390 | 390 | $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class); |
| 391 | 391 | } |
| 392 | 392 | } |
@@ -414,24 +414,24 @@ discard block |
||
| 414 | 414 | array $arguments, |
| 415 | 415 | ): object { |
| 416 | 416 | $class = $ctx->class; |
| 417 | - try { |
|
| 417 | + try{ |
|
| 418 | 418 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 419 | - } catch (\ReflectionException $e) { |
|
| 419 | + }catch (\ReflectionException $e){ |
|
| 420 | 420 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | // Check scope name |
| 424 | 424 | $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 425 | - if ($this->options->checkScope && $scope !== null && $scope !== $this->scope->getScopeName()) { |
|
| 425 | + if ($this->options->checkScope && $scope !== null && $scope !== $this->scope->getScopeName()){ |
|
| 426 | 426 | throw new BadScopeException($scope, $class); |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | // We have to construct class using external injector when we know the exact context |
| 430 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
| 430 | + if ($arguments === [] && $this->binder->hasInjector($class)){ |
|
| 431 | 431 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments); |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - if (!$reflection->isInstantiable()) { |
|
| 434 | + if (!$reflection->isInstantiable()){ |
|
| 435 | 435 | $itIs = match (true) { |
| 436 | 436 | $reflection->isEnum() => 'Enum', |
| 437 | 437 | $reflection->isAbstract() => 'Abstract class', |
@@ -444,12 +444,12 @@ discard block |
||
| 444 | 444 | |
| 445 | 445 | $constructor = $reflection->getConstructor(); |
| 446 | 446 | |
| 447 | - if ($constructor !== null) { |
|
| 448 | - try { |
|
| 447 | + if ($constructor !== null){ |
|
| 448 | + try{ |
|
| 449 | 449 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
| 450 | 450 | $this->tracer->push(true); |
| 451 | 451 | $args = $this->resolver->resolveArguments($constructor, $arguments); |
| 452 | - } catch (ValidationException $e) { |
|
| 452 | + }catch (ValidationException $e){ |
|
| 453 | 453 | throw new ContainerException( |
| 454 | 454 | $this->tracer->combineTraceMessage( |
| 455 | 455 | \sprintf( |
@@ -459,22 +459,22 @@ discard block |
||
| 459 | 459 | ) |
| 460 | 460 | ), |
| 461 | 461 | ); |
| 462 | - } finally { |
|
| 462 | + }finally{ |
|
| 463 | 463 | $this->tracer->pop(true); |
| 464 | 464 | $this->tracer->pop(false); |
| 465 | 465 | } |
| 466 | - try { |
|
| 466 | + try{ |
|
| 467 | 467 | // Using constructor with resolved arguments |
| 468 | 468 | $this->tracer->push(false, call: "$class::__construct", arguments: $args); |
| 469 | 469 | $this->tracer->push(true); |
| 470 | 470 | $instance = new $class(...$args); |
| 471 | - } catch (\TypeError $e) { |
|
| 471 | + }catch (\TypeError $e){ |
|
| 472 | 472 | throw new WrongTypeException($constructor, $e); |
| 473 | - } finally { |
|
| 473 | + }finally{ |
|
| 474 | 474 | $this->tracer->pop(true); |
| 475 | 475 | $this->tracer->pop(false); |
| 476 | 476 | } |
| 477 | - } else { |
|
| 477 | + }else{ |
|
| 478 | 478 | // No constructor specified |
| 479 | 479 | $instance = $reflection->newInstance(); |
| 480 | 480 | } |
@@ -492,13 +492,13 @@ discard block |
||
| 492 | 492 | $instance = $this->runInflector($instance); |
| 493 | 493 | |
| 494 | 494 | //Declarative singletons |
| 495 | - if ($this->isSingleton($ctx)) { |
|
| 495 | + if ($this->isSingleton($ctx)){ |
|
| 496 | 496 | $this->state->singletons[$ctx->alias] = $instance; |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | // Register finalizer |
| 500 | 500 | $finalizer = $this->getFinalizer($ctx, $instance); |
| 501 | - if ($finalizer !== null) { |
|
| 501 | + if ($finalizer !== null){ |
|
| 502 | 502 | $this->state->finalizers[] = $finalizer; |
| 503 | 503 | } |
| 504 | 504 | |
@@ -510,12 +510,12 @@ discard block |
||
| 510 | 510 | */ |
| 511 | 511 | private function isSingleton(Ctx $ctx): bool |
| 512 | 512 | { |
| 513 | - if ($ctx->singleton === true) { |
|
| 513 | + if ($ctx->singleton === true){ |
|
| 514 | 514 | return true; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 518 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 518 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
| 519 | 519 | return true; |
| 520 | 520 | } |
| 521 | 521 | |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | * @var Attribute\Finalize|null $attribute |
| 530 | 530 | */ |
| 531 | 531 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
| 532 | - if ($attribute === null) { |
|
| 532 | + if ($attribute === null){ |
|
| 533 | 533 | return null; |
| 534 | 534 | } |
| 535 | 535 | |
@@ -543,10 +543,10 @@ discard block |
||
| 543 | 543 | { |
| 544 | 544 | $scope = $this->scope; |
| 545 | 545 | |
| 546 | - while ($scope !== null) { |
|
| 547 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 548 | - if ($instance instanceof $class) { |
|
| 549 | - foreach ($inflectors as $inflector) { |
|
| 546 | + while ($scope !== null){ |
|
| 547 | + foreach ($this->state->inflectors as $class => $inflectors){ |
|
| 548 | + if ($instance instanceof $class){ |
|
| 549 | + foreach ($inflectors as $inflector){ |
|
| 550 | 550 | $instance = $inflector->getParametersCount() > 1 |
| 551 | 551 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 552 | 552 | : ($inflector->inflector)($instance); |
@@ -562,9 +562,9 @@ discard block |
||
| 562 | 562 | |
| 563 | 563 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
| 564 | 564 | { |
| 565 | - try { |
|
| 565 | + try{ |
|
| 566 | 566 | $this->resolver->validateArguments($reflection, $arguments); |
| 567 | - } catch (\Throwable) { |
|
| 567 | + }catch (\Throwable){ |
|
| 568 | 568 | return false; |
| 569 | 569 | } |
| 570 | 570 | |
@@ -68,17 +68,20 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed |
| 70 | 70 | { |
| 71 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
| 71 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) |
|
| 72 | + { |
|
| 72 | 73 | return $this->state->singletons[$alias]; |
| 73 | 74 | } |
| 74 | 75 | |
| 75 | 76 | $binding = $this->state->bindings[$alias] ?? null; |
| 76 | 77 | |
| 77 | - if ($binding === null) { |
|
| 78 | + if ($binding === null) |
|
| 79 | + { |
|
| 78 | 80 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
| 79 | 81 | } |
| 80 | 82 | |
| 81 | - try { |
|
| 83 | + try |
|
| 84 | + { |
|
| 82 | 85 | $this->tracer->push( |
| 83 | 86 | false, |
| 84 | 87 | action: 'resolve from binding', |
@@ -108,7 +111,9 @@ discard block |
||
| 108 | 111 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
| 109 | 112 | default => $binding, |
| 110 | 113 | }; |
| 111 | - } finally { |
|
| 114 | + } |
|
| 115 | + finally |
|
| 116 | + { |
|
| 112 | 117 | $this->state->bindings[$alias] ??= $binding; |
| 113 | 118 | $this->tracer->pop(true); |
| 114 | 119 | $this->tracer->pop(false); |
@@ -122,18 +127,23 @@ discard block |
||
| 122 | 127 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments) |
| 123 | 128 | { |
| 124 | 129 | $context = $ctx->context; |
| 125 | - try { |
|
| 130 | + try |
|
| 131 | + { |
|
| 126 | 132 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
| 127 | - } catch (\ReflectionException $e) { |
|
| 133 | + } |
|
| 134 | + catch (\ReflectionException $e) |
|
| 135 | + { |
|
| 128 | 136 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 129 | 137 | } |
| 130 | 138 | |
| 131 | 139 | $injector = $binding->injector; |
| 132 | 140 | |
| 133 | - try { |
|
| 141 | + try |
|
| 142 | + { |
|
| 134 | 143 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
| 135 | 144 | |
| 136 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
| 145 | + if (!$injectorInstance instanceof InjectorInterface) |
|
| 146 | + { |
|
| 137 | 147 | throw new InjectionException( |
| 138 | 148 | \sprintf( |
| 139 | 149 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -160,7 +170,8 @@ discard block |
||
| 160 | 170 | default => (string)$context, |
| 161 | 171 | }); |
| 162 | 172 | |
| 163 | - if (!$reflection->isInstance($instance)) { |
|
| 173 | + if (!$reflection->isInstance($instance)) |
|
| 174 | + { |
|
| 164 | 175 | throw new InjectionException( |
| 165 | 176 | \sprintf( |
| 166 | 177 | "Invalid injection response for '%s'.", |
@@ -170,7 +181,9 @@ discard block |
||
| 170 | 181 | } |
| 171 | 182 | |
| 172 | 183 | return $instance; |
| 173 | - } finally { |
|
| 184 | + } |
|
| 185 | + finally |
|
| 186 | + { |
|
| 174 | 187 | $this->state->bindings[$ctx->class] ??= $binding; |
| 175 | 188 | } |
| 176 | 189 | } |
@@ -189,7 +202,8 @@ discard block |
||
| 189 | 202 | //Binding is pointing to something else |
| 190 | 203 | : $this->make($binding->alias, $arguments, $context); |
| 191 | 204 | |
| 192 | - if ($binding->singleton && $arguments === []) { |
|
| 205 | + if ($binding->singleton && $arguments === []) |
|
| 206 | + { |
|
| 193 | 207 | $this->state->singletons[$alias] = $result; |
| 194 | 208 | } |
| 195 | 209 | |
@@ -200,7 +214,8 @@ discard block |
||
| 200 | 214 | { |
| 201 | 215 | $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy()); |
| 202 | 216 | |
| 203 | - if ($binding->singleton) { |
|
| 217 | + if ($binding->singleton) |
|
| 218 | + { |
|
| 204 | 219 | $this->state->singletons[$alias] = $result; |
| 205 | 220 | } |
| 206 | 221 | |
@@ -241,11 +256,14 @@ discard block |
||
| 241 | 256 | array $arguments, |
| 242 | 257 | ): mixed { |
| 243 | 258 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
| 244 | - try { |
|
| 259 | + try |
|
| 260 | + { |
|
| 245 | 261 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
| 246 | 262 | ? ($binding->factory)() |
| 247 | 263 | : $this->invoker->invoke($binding->factory, $arguments); |
| 248 | - } catch (NotCallableException $e) { |
|
| 264 | + } |
|
| 265 | + catch (NotCallableException $e) |
|
| 266 | + { |
|
| 249 | 267 | throw new ContainerException( |
| 250 | 268 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
| 251 | 269 | $e->getCode(), |
@@ -264,19 +282,24 @@ discard block |
||
| 264 | 282 | ): ?object { |
| 265 | 283 | $avoidCache = $arguments !== []; |
| 266 | 284 | |
| 267 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
| 268 | - try { |
|
| 285 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) |
|
| 286 | + { |
|
| 287 | + try |
|
| 288 | + { |
|
| 269 | 289 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
| 270 | 290 | |
| 271 | 291 | $object = $this->createInstance( |
| 272 | 292 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 273 | 293 | $arguments, |
| 274 | 294 | ); |
| 275 | - if ($avoidCache) { |
|
| 295 | + if ($avoidCache) |
|
| 296 | + { |
|
| 276 | 297 | return $object; |
| 277 | 298 | } |
| 278 | 299 | $binding->reference = WeakReference::create($object); |
| 279 | - } catch (\Throwable) { |
|
| 300 | + } |
|
| 301 | + catch (\Throwable) |
|
| 302 | + { |
|
| 280 | 303 | throw new ContainerException( |
| 281 | 304 | $this->tracer->combineTraceMessage( |
| 282 | 305 | \sprintf( |
@@ -286,7 +309,9 @@ discard block |
||
| 286 | 309 | ) |
| 287 | 310 | ) |
| 288 | 311 | ); |
| 289 | - } finally { |
|
| 312 | + } |
|
| 313 | + finally |
|
| 314 | + { |
|
| 290 | 315 | $this->tracer->pop(); |
| 291 | 316 | } |
| 292 | 317 | } |
@@ -301,19 +326,26 @@ discard block |
||
| 301 | 326 | ): mixed { |
| 302 | 327 | $parent = $this->scope->getParentFactory(); |
| 303 | 328 | |
| 304 | - if ($parent !== null) { |
|
| 305 | - try { |
|
| 329 | + if ($parent !== null) |
|
| 330 | + { |
|
| 331 | + try |
|
| 332 | + { |
|
| 306 | 333 | $this->tracer->push(false, ...[ |
| 307 | 334 | 'current scope' => $this->scope->getScopeName(), |
| 308 | 335 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
| 309 | 336 | ]); |
| 310 | 337 | /** @psalm-suppress TooManyArguments */ |
| 311 | 338 | return $parent->make($alias, $parameters, $context); |
| 312 | - } catch (BadScopeException $e) { |
|
| 313 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
| 339 | + } |
|
| 340 | + catch (BadScopeException $e) |
|
| 341 | + { |
|
| 342 | + if ($this->scope->getScopeName() !== $e->getScope()) |
|
| 343 | + { |
|
| 314 | 344 | throw $e; |
| 315 | 345 | } |
| 316 | - } catch (ContainerExceptionInterface $e) { |
|
| 346 | + } |
|
| 347 | + catch (ContainerExceptionInterface $e) |
|
| 348 | + { |
|
| 317 | 349 | $className = match (true) { |
| 318 | 350 | $e instanceof NotFoundException => NotFoundException::class, |
| 319 | 351 | default => ContainerException::class, |
@@ -322,19 +354,24 @@ discard block |
||
| 322 | 354 | 'Can\'t resolve `%s`.', |
| 323 | 355 | $alias, |
| 324 | 356 | )), previous: $e); |
| 325 | - } finally { |
|
| 357 | + } |
|
| 358 | + finally |
|
| 359 | + { |
|
| 326 | 360 | $this->tracer->pop(false); |
| 327 | 361 | } |
| 328 | 362 | } |
| 329 | 363 | |
| 330 | 364 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
| 331 | - try { |
|
| 365 | + try |
|
| 366 | + { |
|
| 332 | 367 | //No direct instructions how to construct class, make is automatically |
| 333 | 368 | return $this->autowire( |
| 334 | 369 | new Ctx(alias: $alias, class: $alias, context: $context), |
| 335 | 370 | $parameters, |
| 336 | 371 | ); |
| 337 | - } finally { |
|
| 372 | + } |
|
| 373 | + finally |
|
| 374 | + { |
|
| 338 | 375 | $this->tracer->pop(false); |
| 339 | 376 | } |
| 340 | 377 | } |
@@ -384,9 +421,11 @@ discard block |
||
| 384 | 421 | // Check scope name |
| 385 | 422 | $ctx->reflection = new \ReflectionClass($instance); |
| 386 | 423 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 387 | - if ($scopeName !== null && $this->options->checkScope) { |
|
| 424 | + if ($scopeName !== null && $this->options->checkScope) |
|
| 425 | + { |
|
| 388 | 426 | $scope = $this->scope; |
| 389 | - while ($scope->getScopeName() !== $scopeName) { |
|
| 427 | + while ($scope->getScopeName() !== $scopeName) |
|
| 428 | + { |
|
| 390 | 429 | $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class); |
| 391 | 430 | } |
| 392 | 431 | } |
@@ -414,24 +453,30 @@ discard block |
||
| 414 | 453 | array $arguments, |
| 415 | 454 | ): object { |
| 416 | 455 | $class = $ctx->class; |
| 417 | - try { |
|
| 456 | + try |
|
| 457 | + { |
|
| 418 | 458 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
| 419 | - } catch (\ReflectionException $e) { |
|
| 459 | + } |
|
| 460 | + catch (\ReflectionException $e) |
|
| 461 | + { |
|
| 420 | 462 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
| 421 | 463 | } |
| 422 | 464 | |
| 423 | 465 | // Check scope name |
| 424 | 466 | $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
| 425 | - if ($this->options->checkScope && $scope !== null && $scope !== $this->scope->getScopeName()) { |
|
| 467 | + if ($this->options->checkScope && $scope !== null && $scope !== $this->scope->getScopeName()) |
|
| 468 | + { |
|
| 426 | 469 | throw new BadScopeException($scope, $class); |
| 427 | 470 | } |
| 428 | 471 | |
| 429 | 472 | // We have to construct class using external injector when we know the exact context |
| 430 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
| 473 | + if ($arguments === [] && $this->binder->hasInjector($class)) |
|
| 474 | + { |
|
| 431 | 475 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments); |
| 432 | 476 | } |
| 433 | 477 | |
| 434 | - if (!$reflection->isInstantiable()) { |
|
| 478 | + if (!$reflection->isInstantiable()) |
|
| 479 | + { |
|
| 435 | 480 | $itIs = match (true) { |
| 436 | 481 | $reflection->isEnum() => 'Enum', |
| 437 | 482 | $reflection->isAbstract() => 'Abstract class', |
@@ -444,12 +489,16 @@ discard block |
||
| 444 | 489 | |
| 445 | 490 | $constructor = $reflection->getConstructor(); |
| 446 | 491 | |
| 447 | - if ($constructor !== null) { |
|
| 448 | - try { |
|
| 492 | + if ($constructor !== null) |
|
| 493 | + { |
|
| 494 | + try |
|
| 495 | + { |
|
| 449 | 496 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
| 450 | 497 | $this->tracer->push(true); |
| 451 | 498 | $args = $this->resolver->resolveArguments($constructor, $arguments); |
| 452 | - } catch (ValidationException $e) { |
|
| 499 | + } |
|
| 500 | + catch (ValidationException $e) |
|
| 501 | + { |
|
| 453 | 502 | throw new ContainerException( |
| 454 | 503 | $this->tracer->combineTraceMessage( |
| 455 | 504 | \sprintf( |
@@ -459,22 +508,31 @@ discard block |
||
| 459 | 508 | ) |
| 460 | 509 | ), |
| 461 | 510 | ); |
| 462 | - } finally { |
|
| 511 | + } |
|
| 512 | + finally |
|
| 513 | + { |
|
| 463 | 514 | $this->tracer->pop(true); |
| 464 | 515 | $this->tracer->pop(false); |
| 465 | 516 | } |
| 466 | - try { |
|
| 517 | + try |
|
| 518 | + { |
|
| 467 | 519 | // Using constructor with resolved arguments |
| 468 | 520 | $this->tracer->push(false, call: "$class::__construct", arguments: $args); |
| 469 | 521 | $this->tracer->push(true); |
| 470 | 522 | $instance = new $class(...$args); |
| 471 | - } catch (\TypeError $e) { |
|
| 523 | + } |
|
| 524 | + catch (\TypeError $e) |
|
| 525 | + { |
|
| 472 | 526 | throw new WrongTypeException($constructor, $e); |
| 473 | - } finally { |
|
| 527 | + } |
|
| 528 | + finally |
|
| 529 | + { |
|
| 474 | 530 | $this->tracer->pop(true); |
| 475 | 531 | $this->tracer->pop(false); |
| 476 | 532 | } |
| 477 | - } else { |
|
| 533 | + } |
|
| 534 | + else |
|
| 535 | + { |
|
| 478 | 536 | // No constructor specified |
| 479 | 537 | $instance = $reflection->newInstance(); |
| 480 | 538 | } |
@@ -492,13 +550,15 @@ discard block |
||
| 492 | 550 | $instance = $this->runInflector($instance); |
| 493 | 551 | |
| 494 | 552 | //Declarative singletons |
| 495 | - if ($this->isSingleton($ctx)) { |
|
| 553 | + if ($this->isSingleton($ctx)) |
|
| 554 | + { |
|
| 496 | 555 | $this->state->singletons[$ctx->alias] = $instance; |
| 497 | 556 | } |
| 498 | 557 | |
| 499 | 558 | // Register finalizer |
| 500 | 559 | $finalizer = $this->getFinalizer($ctx, $instance); |
| 501 | - if ($finalizer !== null) { |
|
| 560 | + if ($finalizer !== null) |
|
| 561 | + { |
|
| 502 | 562 | $this->state->finalizers[] = $finalizer; |
| 503 | 563 | } |
| 504 | 564 | |
@@ -510,12 +570,14 @@ discard block |
||
| 510 | 570 | */ |
| 511 | 571 | private function isSingleton(Ctx $ctx): bool |
| 512 | 572 | { |
| 513 | - if ($ctx->singleton === true) { |
|
| 573 | + if ($ctx->singleton === true) |
|
| 574 | + { |
|
| 514 | 575 | return true; |
| 515 | 576 | } |
| 516 | 577 | |
| 517 | 578 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
| 518 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
| 579 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)) |
|
| 580 | + { |
|
| 519 | 581 | return true; |
| 520 | 582 | } |
| 521 | 583 | |
@@ -529,7 +591,8 @@ discard block |
||
| 529 | 591 | * @var Attribute\Finalize|null $attribute |
| 530 | 592 | */ |
| 531 | 593 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
| 532 | - if ($attribute === null) { |
|
| 594 | + if ($attribute === null) |
|
| 595 | + { |
|
| 533 | 596 | return null; |
| 534 | 597 | } |
| 535 | 598 | |
@@ -543,10 +606,14 @@ discard block |
||
| 543 | 606 | { |
| 544 | 607 | $scope = $this->scope; |
| 545 | 608 | |
| 546 | - while ($scope !== null) { |
|
| 547 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
| 548 | - if ($instance instanceof $class) { |
|
| 549 | - foreach ($inflectors as $inflector) { |
|
| 609 | + while ($scope !== null) |
|
| 610 | + { |
|
| 611 | + foreach ($this->state->inflectors as $class => $inflectors) |
|
| 612 | + { |
|
| 613 | + if ($instance instanceof $class) |
|
| 614 | + { |
|
| 615 | + foreach ($inflectors as $inflector) |
|
| 616 | + { |
|
| 550 | 617 | $instance = $inflector->getParametersCount() > 1 |
| 551 | 618 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
| 552 | 619 | : ($inflector->inflector)($instance); |
@@ -562,9 +629,12 @@ discard block |
||
| 562 | 629 | |
| 563 | 630 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
| 564 | 631 | { |
| 565 | - try { |
|
| 632 | + try |
|
| 633 | + { |
|
| 566 | 634 | $this->resolver->validateArguments($reflection, $arguments); |
| 567 | - } catch (\Throwable) { |
|
| 635 | + } |
|
| 636 | + catch (\Throwable) |
|
| 637 | + { |
|
| 568 | 638 | return false; |
| 569 | 639 | } |
| 570 | 640 | |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | private Config $config, |
| 20 | 20 | private array $objects = [], |
| 21 | 21 | private Options $options = new Options(), |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function set(string $name, object $value): void |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | public const DEFAULT_ROOT_SCOPE_NAME = 'root'; |
| 48 | 48 | |
| 49 | 49 | private Internal\State $state; |
| 50 | - private ResolverInterface|Internal\Resolver $resolver; |
|
| 51 | - private FactoryInterface|Internal\Factory $factory; |
|
| 52 | - private ContainerInterface|Internal\Container $container; |
|
| 53 | - private BinderInterface|Internal\Binder $binder; |
|
| 54 | - private InvokerInterface|Internal\Invoker $invoker; |
|
| 50 | + private ResolverInterface | Internal\Resolver $resolver; |
|
| 51 | + private FactoryInterface | Internal\Factory $factory; |
|
| 52 | + private ContainerInterface | Internal\Container $container; |
|
| 53 | + private BinderInterface | Internal\Binder $binder; |
|
| 54 | + private InvokerInterface | Internal\Invoker $invoker; |
|
| 55 | 55 | private Internal\Scope $scope; |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | private Config $config = new Config(), |
| 62 | 62 | ?string $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
| 63 | 63 | private Options $options = new Options(), |
| 64 | - ) { |
|
| 64 | + ){ |
|
| 65 | 65 | $this->initServices($this, $scopeName); |
| 66 | 66 | |
| 67 | 67 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @throws \Throwable |
| 114 | 114 | * @psalm-suppress TooManyArguments |
| 115 | 115 | */ |
| 116 | - public function make(string $alias, array $parameters = [], \Stringable|string|null $context = null): mixed |
|
| 116 | + public function make(string $alias, array $parameters = [], \Stringable | string | null $context = null): mixed |
|
| 117 | 117 | { |
| 118 | 118 | return ContainerScope::getContainer() === $this |
| 119 | 119 | ? $this->factory->make($alias, $parameters, $context) |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @throws \Throwable |
| 140 | 140 | * @psalm-suppress TooManyArguments |
| 141 | 141 | */ |
| 142 | - public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed |
|
| 142 | + public function get(string | Autowire $id, \Stringable | string | null $context = null): mixed |
|
| 143 | 143 | { |
| 144 | 144 | return ContainerScope::getContainer() === $this |
| 145 | 145 | ? $this->container->get($id, $context) |
@@ -169,25 +169,25 @@ discard block |
||
| 169 | 169 | /** |
| 170 | 170 | * @throws \Throwable |
| 171 | 171 | */ |
| 172 | - public function runScope(Scope|array $bindings, callable $scope): mixed |
|
| 172 | + public function runScope(Scope | array $bindings, callable $scope): mixed |
|
| 173 | 173 | { |
| 174 | - if (!\is_array($bindings)) { |
|
| 174 | + if (!\is_array($bindings)){ |
|
| 175 | 175 | return $this->runIsolatedScope($bindings, $scope); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | $binds = &$this->state->bindings; |
| 179 | 179 | $singletons = &$this->state->singletons; |
| 180 | 180 | $cleanup = $previous = $prevSin = []; |
| 181 | - foreach ($bindings as $alias => $resolver) { |
|
| 181 | + foreach ($bindings as $alias => $resolver){ |
|
| 182 | 182 | // Store previous bindings |
| 183 | - if (isset($binds[$alias])) { |
|
| 183 | + if (isset($binds[$alias])){ |
|
| 184 | 184 | $previous[$alias] = $binds[$alias]; |
| 185 | - } else { |
|
| 185 | + }else{ |
|
| 186 | 186 | // Store bindings to be removed |
| 187 | 187 | $cleanup[] = $alias; |
| 188 | 188 | } |
| 189 | 189 | // Store previous singletons |
| 190 | - if (isset($singletons[$alias])) { |
|
| 190 | + if (isset($singletons[$alias])){ |
|
| 191 | 191 | $prevSin[$alias] = $singletons[$alias]; |
| 192 | 192 | unset($singletons[$alias]); |
| 193 | 193 | } |
@@ -195,21 +195,21 @@ discard block |
||
| 195 | 195 | $this->binder->bind($alias, $resolver); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - try { |
|
| 198 | + try{ |
|
| 199 | 199 | return ContainerScope::getContainer() !== $this |
| 200 | 200 | ? ContainerScope::runScope($this, $scope) |
| 201 | 201 | : $scope($this); |
| 202 | - } finally { |
|
| 202 | + }finally{ |
|
| 203 | 203 | // Remove new bindings |
| 204 | - foreach ($cleanup as $alias) { |
|
| 204 | + foreach ($cleanup as $alias){ |
|
| 205 | 205 | unset($binds[$alias], $singletons[$alias]); |
| 206 | 206 | } |
| 207 | 207 | // Restore previous bindings |
| 208 | - foreach ($previous as $alias => $resolver) { |
|
| 208 | + foreach ($previous as $alias => $resolver){ |
|
| 209 | 209 | $binds[$alias] = $resolver; |
| 210 | 210 | } |
| 211 | 211 | // Restore singletons |
| 212 | - foreach ($prevSin as $alias => $instance) { |
|
| 212 | + foreach ($prevSin as $alias => $instance){ |
|
| 213 | 213 | $singletons[$alias] = $instance; |
| 214 | 214 | } |
| 215 | 215 | } |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * @param bool $force If the value is false, an exception will be thrown when attempting |
| 256 | 256 | * to bind an already constructed singleton. |
| 257 | 257 | */ |
| 258 | - public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void |
|
| 258 | + public function bindSingleton(string $alias, string | array | callable | object $resolver, bool $force = true): void |
|
| 259 | 259 | { |
| 260 | - if ($force) { |
|
| 260 | + if ($force){ |
|
| 261 | 261 | $this->binder->removeBinding($alias); |
| 262 | 262 | } |
| 263 | 263 | |
@@ -328,8 +328,8 @@ discard block |
||
| 328 | 328 | ], $this->options); |
| 329 | 329 | |
| 330 | 330 | // Create container services |
| 331 | - foreach ($container->config as $property => $class) { |
|
| 332 | - if (\property_exists($container, $property)) { |
|
| 331 | + foreach ($container->config as $property => $class){ |
|
| 332 | + if (\property_exists($container, $property)){ |
|
| 333 | 333 | $container->$property = $constructor->get($property, $class); |
| 334 | 334 | } |
| 335 | 335 | } |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | private function closeScope(): void |
| 344 | 344 | { |
| 345 | 345 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
| 346 | - if (!isset($this->scope)) { |
|
| 346 | + if (!isset($this->scope)){ |
|
| 347 | 347 | $this->destruct(); |
| 348 | 348 | return; |
| 349 | 349 | } |
@@ -352,10 +352,10 @@ discard block |
||
| 352 | 352 | |
| 353 | 353 | // Run finalizers |
| 354 | 354 | $errors = []; |
| 355 | - foreach ($this->state->finalizers as $finalizer) { |
|
| 356 | - try { |
|
| 355 | + foreach ($this->state->finalizers as $finalizer){ |
|
| 356 | + try{ |
|
| 357 | 357 | $this->invoker->invoke($finalizer); |
| 358 | - } catch (\Throwable $e) { |
|
| 358 | + }catch (\Throwable $e){ |
|
| 359 | 359 | $errors[] = $e; |
| 360 | 360 | } |
| 361 | 361 | } |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | $this->destruct(); |
| 365 | 365 | |
| 366 | 366 | // Throw collected errors |
| 367 | - if ($errors !== []) { |
|
| 367 | + if ($errors !== []){ |
|
| 368 | 368 | throw new FinalizersException($scopeName, $errors); |
| 369 | 369 | } |
| 370 | 370 | } |
@@ -386,18 +386,18 @@ discard block |
||
| 386 | 386 | $container->scope->setParent($this, $this->scope, $this->factory); |
| 387 | 387 | |
| 388 | 388 | // Add specific bindings |
| 389 | - foreach ($config->bindings as $alias => $resolver) { |
|
| 389 | + foreach ($config->bindings as $alias => $resolver){ |
|
| 390 | 390 | $container->binder->bind($alias, $resolver); |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | return ContainerScope::runScope( |
| 394 | 394 | $container, |
| 395 | 395 | static function (self $container) use ($config, $closure): mixed { |
| 396 | - try { |
|
| 396 | + try{ |
|
| 397 | 397 | return $config->autowire |
| 398 | 398 | ? $container->invoke($closure) |
| 399 | 399 | : $closure($container); |
| 400 | - } finally { |
|
| 400 | + }finally{ |
|
| 401 | 401 | $container->closeScope(); |
| 402 | 402 | } |
| 403 | 403 | } |
@@ -171,23 +171,29 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | public function runScope(Scope|array $bindings, callable $scope): mixed |
| 173 | 173 | { |
| 174 | - if (!\is_array($bindings)) { |
|
| 174 | + if (!\is_array($bindings)) |
|
| 175 | + { |
|
| 175 | 176 | return $this->runIsolatedScope($bindings, $scope); |
| 176 | 177 | } |
| 177 | 178 | |
| 178 | 179 | $binds = &$this->state->bindings; |
| 179 | 180 | $singletons = &$this->state->singletons; |
| 180 | 181 | $cleanup = $previous = $prevSin = []; |
| 181 | - foreach ($bindings as $alias => $resolver) { |
|
| 182 | + foreach ($bindings as $alias => $resolver) |
|
| 183 | + { |
|
| 182 | 184 | // Store previous bindings |
| 183 | - if (isset($binds[$alias])) { |
|
| 185 | + if (isset($binds[$alias])) |
|
| 186 | + { |
|
| 184 | 187 | $previous[$alias] = $binds[$alias]; |
| 185 | - } else { |
|
| 188 | + } |
|
| 189 | + else |
|
| 190 | + { |
|
| 186 | 191 | // Store bindings to be removed |
| 187 | 192 | $cleanup[] = $alias; |
| 188 | 193 | } |
| 189 | 194 | // Store previous singletons |
| 190 | - if (isset($singletons[$alias])) { |
|
| 195 | + if (isset($singletons[$alias])) |
|
| 196 | + { |
|
| 191 | 197 | $prevSin[$alias] = $singletons[$alias]; |
| 192 | 198 | unset($singletons[$alias]); |
| 193 | 199 | } |
@@ -195,21 +201,27 @@ discard block |
||
| 195 | 201 | $this->binder->bind($alias, $resolver); |
| 196 | 202 | } |
| 197 | 203 | |
| 198 | - try { |
|
| 204 | + try |
|
| 205 | + { |
|
| 199 | 206 | return ContainerScope::getContainer() !== $this |
| 200 | 207 | ? ContainerScope::runScope($this, $scope) |
| 201 | 208 | : $scope($this); |
| 202 | - } finally { |
|
| 209 | + } |
|
| 210 | + finally |
|
| 211 | + { |
|
| 203 | 212 | // Remove new bindings |
| 204 | - foreach ($cleanup as $alias) { |
|
| 213 | + foreach ($cleanup as $alias) |
|
| 214 | + { |
|
| 205 | 215 | unset($binds[$alias], $singletons[$alias]); |
| 206 | 216 | } |
| 207 | 217 | // Restore previous bindings |
| 208 | - foreach ($previous as $alias => $resolver) { |
|
| 218 | + foreach ($previous as $alias => $resolver) |
|
| 219 | + { |
|
| 209 | 220 | $binds[$alias] = $resolver; |
| 210 | 221 | } |
| 211 | 222 | // Restore singletons |
| 212 | - foreach ($prevSin as $alias => $instance) { |
|
| 223 | + foreach ($prevSin as $alias => $instance) |
|
| 224 | + { |
|
| 213 | 225 | $singletons[$alias] = $instance; |
| 214 | 226 | } |
| 215 | 227 | } |
@@ -257,7 +269,8 @@ discard block |
||
| 257 | 269 | */ |
| 258 | 270 | public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void |
| 259 | 271 | { |
| 260 | - if ($force) { |
|
| 272 | + if ($force) |
|
| 273 | + { |
|
| 261 | 274 | $this->binder->removeBinding($alias); |
| 262 | 275 | } |
| 263 | 276 | |
@@ -328,8 +341,10 @@ discard block |
||
| 328 | 341 | ], $this->options); |
| 329 | 342 | |
| 330 | 343 | // Create container services |
| 331 | - foreach ($container->config as $property => $class) { |
|
| 332 | - if (\property_exists($container, $property)) { |
|
| 344 | + foreach ($container->config as $property => $class) |
|
| 345 | + { |
|
| 346 | + if (\property_exists($container, $property)) |
|
| 347 | + { |
|
| 333 | 348 | $container->$property = $constructor->get($property, $class); |
| 334 | 349 | } |
| 335 | 350 | } |
@@ -343,7 +358,8 @@ discard block |
||
| 343 | 358 | private function closeScope(): void |
| 344 | 359 | { |
| 345 | 360 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
| 346 | - if (!isset($this->scope)) { |
|
| 361 | + if (!isset($this->scope)) |
|
| 362 | + { |
|
| 347 | 363 | $this->destruct(); |
| 348 | 364 | return; |
| 349 | 365 | } |
@@ -352,10 +368,14 @@ discard block |
||
| 352 | 368 | |
| 353 | 369 | // Run finalizers |
| 354 | 370 | $errors = []; |
| 355 | - foreach ($this->state->finalizers as $finalizer) { |
|
| 356 | - try { |
|
| 371 | + foreach ($this->state->finalizers as $finalizer) |
|
| 372 | + { |
|
| 373 | + try |
|
| 374 | + { |
|
| 357 | 375 | $this->invoker->invoke($finalizer); |
| 358 | - } catch (\Throwable $e) { |
|
| 376 | + } |
|
| 377 | + catch (\Throwable $e) |
|
| 378 | + { |
|
| 359 | 379 | $errors[] = $e; |
| 360 | 380 | } |
| 361 | 381 | } |
@@ -364,7 +384,8 @@ discard block |
||
| 364 | 384 | $this->destruct(); |
| 365 | 385 | |
| 366 | 386 | // Throw collected errors |
| 367 | - if ($errors !== []) { |
|
| 387 | + if ($errors !== []) |
|
| 388 | + { |
|
| 368 | 389 | throw new FinalizersException($scopeName, $errors); |
| 369 | 390 | } |
| 370 | 391 | } |
@@ -386,18 +407,22 @@ discard block |
||
| 386 | 407 | $container->scope->setParent($this, $this->scope, $this->factory); |
| 387 | 408 | |
| 388 | 409 | // Add specific bindings |
| 389 | - foreach ($config->bindings as $alias => $resolver) { |
|
| 410 | + foreach ($config->bindings as $alias => $resolver) |
|
| 411 | + { |
|
| 390 | 412 | $container->binder->bind($alias, $resolver); |
| 391 | 413 | } |
| 392 | 414 | |
| 393 | 415 | return ContainerScope::runScope( |
| 394 | 416 | $container, |
| 395 | 417 | static function (self $container) use ($config, $closure): mixed { |
| 396 | - try { |
|
| 418 | + try |
|
| 419 | + { |
|
| 397 | 420 | return $config->autowire |
| 398 | 421 | ? $container->invoke($closure) |
| 399 | 422 | : $closure($container); |
| 400 | - } finally { |
|
| 423 | + } |
|
| 424 | + finally |
|
| 425 | + { |
|
| 401 | 426 | $container->closeScope(); |
| 402 | 427 | } |
| 403 | 428 | } |