@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | public const DEFAULT_ROOT_SCOPE_NAME = 'root'; |
| 49 | 49 | |
| 50 | 50 | private Internal\State $state; |
| 51 | - private ResolverInterface|Internal\Resolver $resolver; |
|
| 52 | - private FactoryInterface|Internal\Factory $factory; |
|
| 53 | - private ContainerInterface|Internal\Container $container; |
|
| 54 | - private BinderInterface|Internal\Binder $binder; |
|
| 55 | - private InvokerInterface|Internal\Invoker $invoker; |
|
| 51 | + private ResolverInterface | Internal\Resolver $resolver; |
|
| 52 | + private FactoryInterface | Internal\Factory $factory; |
|
| 53 | + private ContainerInterface | Internal\Container $container; |
|
| 54 | + private BinderInterface | Internal\Binder $binder; |
|
| 55 | + private InvokerInterface | Internal\Invoker $invoker; |
|
| 56 | 56 | private Internal\Scope $scope; |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function __construct( |
| 62 | 62 | private Config $config = new Config(), |
| 63 | - string|\BackedEnum|null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
|
| 63 | + string | \BackedEnum | null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
|
| 64 | 64 | private Options $options = new Options(), |
| 65 | - ) { |
|
| 66 | - if (\is_object($scopeName)) { |
|
| 67 | - $scopeName = (string) $scopeName->value; |
|
| 65 | + ){ |
|
| 66 | + if (\is_object($scopeName)){ |
|
| 67 | + $scopeName = (string)$scopeName->value; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | $this->initServices($this, $scopeName); |
@@ -118,11 +118,11 @@ discard block |
||
| 118 | 118 | * @throws \Throwable |
| 119 | 119 | * @psalm-suppress TooManyArguments |
| 120 | 120 | */ |
| 121 | - public function make(string $alias, array $parameters = [], \Stringable|string|null $context = null): mixed |
|
| 121 | + public function make(string $alias, array $parameters = [], \Stringable | string | null $context = null): mixed |
|
| 122 | 122 | { |
| 123 | 123 | return ContainerScope::getContainer() === $this |
| 124 | 124 | ? $this->factory->make($alias, $parameters, $context) |
| 125 | - : ContainerScope::runScope($this, fn (): mixed => $this->factory->make($alias, $parameters, $context)); |
|
| 125 | + : ContainerScope::runScope($this, fn () : mixed => $this->factory->make($alias, $parameters, $context)); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @throws \Throwable |
| 145 | 145 | * @psalm-suppress TooManyArguments |
| 146 | 146 | */ |
| 147 | - public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed |
|
| 147 | + public function get(string | Autowire $id, \Stringable | string | null $context = null): mixed |
|
| 148 | 148 | { |
| 149 | 149 | return ContainerScope::getContainer() === $this |
| 150 | 150 | ? $this->container->get($id, $context) |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | * If {@see string}, the default binder for the given scope will be returned. Default bindings won't affect |
| 165 | 165 | * already created Container instances except the case with the root one. |
| 166 | 166 | */ |
| 167 | - public function getBinder(string|\BackedEnum|null $scope = null): BinderInterface |
|
| 167 | + public function getBinder(string | \BackedEnum | null $scope = null): BinderInterface |
|
| 168 | 168 | { |
| 169 | - $scope = \is_object($scope) ? (string) $scope->value : $scope; |
|
| 169 | + $scope = \is_object($scope) ? (string)$scope->value : $scope; |
|
| 170 | 170 | |
| 171 | 171 | return $scope === null |
| 172 | 172 | ? $this->binder |
@@ -176,25 +176,25 @@ discard block |
||
| 176 | 176 | /** |
| 177 | 177 | * @throws \Throwable |
| 178 | 178 | */ |
| 179 | - public function runScope(Scope|array $bindings, callable $scope): mixed |
|
| 179 | + public function runScope(Scope | array $bindings, callable $scope): mixed |
|
| 180 | 180 | { |
| 181 | - if (!\is_array($bindings)) { |
|
| 181 | + if (!\is_array($bindings)){ |
|
| 182 | 182 | return $this->runIsolatedScope($bindings, $scope); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | $binds = &$this->state->bindings; |
| 186 | 186 | $singletons = &$this->state->singletons; |
| 187 | 187 | $cleanup = $previous = $prevSin = []; |
| 188 | - foreach ($bindings as $alias => $resolver) { |
|
| 188 | + foreach ($bindings as $alias => $resolver){ |
|
| 189 | 189 | // Store previous bindings |
| 190 | - if (isset($binds[$alias])) { |
|
| 190 | + if (isset($binds[$alias])){ |
|
| 191 | 191 | $previous[$alias] = $binds[$alias]; |
| 192 | - } else { |
|
| 192 | + }else{ |
|
| 193 | 193 | // Store bindings to be removed |
| 194 | 194 | $cleanup[] = $alias; |
| 195 | 195 | } |
| 196 | 196 | // Store previous singletons |
| 197 | - if (isset($singletons[$alias])) { |
|
| 197 | + if (isset($singletons[$alias])){ |
|
| 198 | 198 | $prevSin[$alias] = $singletons[$alias]; |
| 199 | 199 | unset($singletons[$alias]); |
| 200 | 200 | } |
@@ -202,21 +202,21 @@ discard block |
||
| 202 | 202 | $this->binder->bind($alias, $resolver); |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - try { |
|
| 205 | + try{ |
|
| 206 | 206 | return ContainerScope::getContainer() !== $this |
| 207 | 207 | ? ContainerScope::runScope($this, $scope) |
| 208 | 208 | : $scope($this); |
| 209 | - } finally { |
|
| 209 | + }finally{ |
|
| 210 | 210 | // Remove new bindings |
| 211 | - foreach ($cleanup as $alias) { |
|
| 211 | + foreach ($cleanup as $alias){ |
|
| 212 | 212 | unset($binds[$alias], $singletons[$alias]); |
| 213 | 213 | } |
| 214 | 214 | // Restore previous bindings |
| 215 | - foreach ($previous as $alias => $resolver) { |
|
| 215 | + foreach ($previous as $alias => $resolver){ |
|
| 216 | 216 | $binds[$alias] = $resolver; |
| 217 | 217 | } |
| 218 | 218 | // Restore singletons |
| 219 | - foreach ($prevSin as $alias => $instance) { |
|
| 219 | + foreach ($prevSin as $alias => $instance){ |
|
| 220 | 220 | $singletons[$alias] = $instance; |
| 221 | 221 | } |
| 222 | 222 | } |
@@ -264,9 +264,9 @@ discard block |
||
| 264 | 264 | * @throws SingletonOverloadException |
| 265 | 265 | * @throws \Throwable |
| 266 | 266 | */ |
| 267 | - public function bindSingleton(string $alias, string|array|callable|object $resolver, ?bool $force = null): void |
|
| 267 | + public function bindSingleton(string $alias, string | array | callable | object $resolver, ?bool $force = null): void |
|
| 268 | 268 | { |
| 269 | - if ($force ?? $this->options->allowSingletonsRebind) { |
|
| 269 | + if ($force ?? $this->options->allowSingletonsRebind){ |
|
| 270 | 270 | $this->binder->removeBinding($alias); |
| 271 | 271 | } |
| 272 | 272 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | { |
| 294 | 294 | return ContainerScope::getContainer() === $this |
| 295 | 295 | ? $this->invoker->invoke($target, $parameters) |
| 296 | - : ContainerScope::runScope($this, fn (): mixed => $this->invoker->invoke($target, $parameters)); |
|
| 296 | + : ContainerScope::runScope($this, fn () : mixed => $this->invoker->invoke($target, $parameters)); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | ], $this->options); |
| 338 | 338 | |
| 339 | 339 | // Create container services |
| 340 | - foreach ($container->config as $property => $class) { |
|
| 341 | - if (\property_exists($container, $property)) { |
|
| 340 | + foreach ($container->config as $property => $class){ |
|
| 341 | + if (\property_exists($container, $property)){ |
|
| 342 | 342 | $container->$property = $constructor->get($property, $class); |
| 343 | 343 | } |
| 344 | 344 | } |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | private function closeScope(): void |
| 353 | 353 | { |
| 354 | 354 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
| 355 | - if (!isset($this->scope)) { |
|
| 355 | + if (!isset($this->scope)){ |
|
| 356 | 356 | $this->destruct(); |
| 357 | 357 | return; |
| 358 | 358 | } |
@@ -361,10 +361,10 @@ discard block |
||
| 361 | 361 | |
| 362 | 362 | // Run finalizers |
| 363 | 363 | $errors = []; |
| 364 | - foreach ($this->state->finalizers as $finalizer) { |
|
| 365 | - try { |
|
| 364 | + foreach ($this->state->finalizers as $finalizer){ |
|
| 365 | + try{ |
|
| 366 | 366 | $this->invoker->invoke($finalizer); |
| 367 | - } catch (\Throwable $e) { |
|
| 367 | + }catch (\Throwable $e){ |
|
| 368 | 368 | $errors[] = $e; |
| 369 | 369 | } |
| 370 | 370 | } |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | $this->destruct(); |
| 374 | 374 | |
| 375 | 375 | // Throw collected errors |
| 376 | - if ($errors !== []) { |
|
| 376 | + if ($errors !== []){ |
|
| 377 | 377 | throw new FinalizersException($scopeName, $errors); |
| 378 | 378 | } |
| 379 | 379 | } |
@@ -395,18 +395,18 @@ discard block |
||
| 395 | 395 | $container->scope->setParent($this, $this->scope, $this->factory); |
| 396 | 396 | |
| 397 | 397 | // Add specific bindings |
| 398 | - foreach ($config->bindings as $alias => $resolver) { |
|
| 398 | + foreach ($config->bindings as $alias => $resolver){ |
|
| 399 | 399 | $container->binder->bind($alias, $resolver); |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | return ContainerScope::runScope( |
| 403 | 403 | $container, |
| 404 | 404 | static function (self $container) use ($config, $closure): mixed { |
| 405 | - try { |
|
| 405 | + try{ |
|
| 406 | 406 | return $config->autowire |
| 407 | 407 | ? $container->invoke($closure) |
| 408 | 408 | : $closure($container); |
| 409 | - } finally { |
|
| 409 | + }finally{ |
|
| 410 | 410 | $container->closeScope(); |
| 411 | 411 | } |
| 412 | 412 | } |