@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | private readonly bool $useAnnotations = false, |
| 30 | 30 | private readonly bool $namedArguments = true, |
| 31 | 31 | private readonly bool $scanParents = false, |
| 32 | - ) { |
|
| 32 | + ){ |
|
| 33 | 33 | parent::__construct($scope); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -45,25 +45,25 @@ discard block |
||
| 45 | 45 | ? (new Factory())->create() |
| 46 | 46 | : new AttributeReader($this->namedArguments ? new NamedArgumentsInstantiator() : null); |
| 47 | 47 | |
| 48 | - if ($attribute === null) { |
|
| 48 | + if ($attribute === null){ |
|
| 49 | 49 | return; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $attribute = $attribute->newInstance(); |
| 53 | 53 | |
| 54 | - foreach ($classes as $class) { |
|
| 54 | + foreach ($classes as $class){ |
|
| 55 | 55 | // If attribute is defined on class level and class has target attribute |
| 56 | 56 | // then we can add it to the list of classes |
| 57 | - if ($attribute->flags & \Attribute::TARGET_CLASS) { |
|
| 58 | - if ($reader->firstClassMetadata($class, $target->getName())) { |
|
| 57 | + if ($attribute->flags & \Attribute::TARGET_CLASS){ |
|
| 58 | + if ($reader->firstClassMetadata($class, $target->getName())){ |
|
| 59 | 59 | yield $class->getName(); |
| 60 | 60 | continue; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - if ($this->scanParents) { |
|
| 63 | + if ($this->scanParents){ |
|
| 64 | 64 | // Interfaces |
| 65 | - foreach ($class->getInterfaces() as $interface) { |
|
| 66 | - if ($reader->firstClassMetadata($interface, $target->getName())) { |
|
| 65 | + foreach ($class->getInterfaces() as $interface){ |
|
| 66 | + if ($reader->firstClassMetadata($interface, $target->getName())){ |
|
| 67 | 67 | yield $class->getName(); |
| 68 | 68 | continue 2; |
| 69 | 69 | } |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | // Parents |
| 73 | 73 | $parent = $class->getParentClass(); |
| 74 | - while ($parent !== false) { |
|
| 75 | - if ($reader->firstClassMetadata($parent, $target->getName())) { |
|
| 74 | + while ($parent !== false){ |
|
| 75 | + if ($reader->firstClassMetadata($parent, $target->getName())){ |
|
| 76 | 76 | yield $class->getName(); |
| 77 | 77 | continue 2; |
| 78 | 78 | } |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | // If attribute is defined on method level and class methods has target attribute |
| 85 | 85 | // then we can add it to the list of classes |
| 86 | - if ($attribute->flags & \Attribute::TARGET_METHOD) { |
|
| 87 | - foreach ($class->getMethods() as $method) { |
|
| 88 | - if ($reader->firstFunctionMetadata($method, $target->getName())) { |
|
| 86 | + if ($attribute->flags & \Attribute::TARGET_METHOD){ |
|
| 87 | + foreach ($class->getMethods() as $method){ |
|
| 88 | + if ($reader->firstFunctionMetadata($method, $target->getName())){ |
|
| 89 | 89 | yield $class->getName(); |
| 90 | 90 | continue 2; |
| 91 | 91 | } |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | // If attribute is defined on property level and class properties has target attribute |
| 96 | 96 | // then we can add it to the list of classes |
| 97 | - if ($attribute->flags & \Attribute::TARGET_PROPERTY) { |
|
| 98 | - foreach ($class->getProperties() as $property) { |
|
| 99 | - if ($reader->firstPropertyMetadata($property, $target->getName())) { |
|
| 97 | + if ($attribute->flags & \Attribute::TARGET_PROPERTY){ |
|
| 98 | + foreach ($class->getProperties() as $property){ |
|
| 99 | + if ($reader->firstPropertyMetadata($property, $target->getName())){ |
|
| 100 | 100 | yield $class->getName(); |
| 101 | 101 | continue 2; |
| 102 | 102 | } |
@@ -106,9 +106,9 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | // If attribute is defined on constant level and class constants has target attribute |
| 108 | 108 | // then we can add it to the list of classes |
| 109 | - if ($attribute->flags & \Attribute::TARGET_CLASS_CONSTANT) { |
|
| 110 | - foreach ($class->getReflectionConstants() as $constant) { |
|
| 111 | - if ($reader->firstConstantMetadata($constant, $target->getName())) { |
|
| 109 | + if ($attribute->flags & \Attribute::TARGET_CLASS_CONSTANT){ |
|
| 110 | + foreach ($class->getReflectionConstants() as $constant){ |
|
| 111 | + if ($reader->firstConstantMetadata($constant, $target->getName())){ |
|
| 112 | 112 | yield $class->getName(); |
| 113 | 113 | continue 2; |
| 114 | 114 | } |
@@ -118,10 +118,10 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | // If attribute is defined on method parameters level and class method parameter has target attribute |
| 120 | 120 | // then we can add it to the list of classes |
| 121 | - if ($attribute->flags & \Attribute::TARGET_PARAMETER) { |
|
| 122 | - foreach ($class->getMethods() as $method) { |
|
| 123 | - foreach ($method->getParameters() as $parameter) { |
|
| 124 | - if ($reader->firstParameterMetadata($parameter, $target->getName())) { |
|
| 121 | + if ($attribute->flags & \Attribute::TARGET_PARAMETER){ |
|
| 122 | + foreach ($class->getMethods() as $method){ |
|
| 123 | + foreach ($method->getParameters() as $parameter){ |
|
| 124 | + if ($reader->firstParameterMetadata($parameter, $target->getName())){ |
|
| 125 | 125 | yield $class->getName(); |
| 126 | 126 | continue 3; |
| 127 | 127 | } |
@@ -45,25 +45,32 @@ discard block |
||
| 45 | 45 | ? (new Factory())->create() |
| 46 | 46 | : new AttributeReader($this->namedArguments ? new NamedArgumentsInstantiator() : null); |
| 47 | 47 | |
| 48 | - if ($attribute === null) { |
|
| 48 | + if ($attribute === null) |
|
| 49 | + { |
|
| 49 | 50 | return; |
| 50 | 51 | } |
| 51 | 52 | |
| 52 | 53 | $attribute = $attribute->newInstance(); |
| 53 | 54 | |
| 54 | - foreach ($classes as $class) { |
|
| 55 | + foreach ($classes as $class) |
|
| 56 | + { |
|
| 55 | 57 | // If attribute is defined on class level and class has target attribute |
| 56 | 58 | // then we can add it to the list of classes |
| 57 | - if ($attribute->flags & \Attribute::TARGET_CLASS) { |
|
| 58 | - if ($reader->firstClassMetadata($class, $target->getName())) { |
|
| 59 | + if ($attribute->flags & \Attribute::TARGET_CLASS) |
|
| 60 | + { |
|
| 61 | + if ($reader->firstClassMetadata($class, $target->getName())) |
|
| 62 | + { |
|
| 59 | 63 | yield $class->getName(); |
| 60 | 64 | continue; |
| 61 | 65 | } |
| 62 | 66 | |
| 63 | - if ($this->scanParents) { |
|
| 67 | + if ($this->scanParents) |
|
| 68 | + { |
|
| 64 | 69 | // Interfaces |
| 65 | - foreach ($class->getInterfaces() as $interface) { |
|
| 66 | - if ($reader->firstClassMetadata($interface, $target->getName())) { |
|
| 70 | + foreach ($class->getInterfaces() as $interface) |
|
| 71 | + { |
|
| 72 | + if ($reader->firstClassMetadata($interface, $target->getName())) |
|
| 73 | + { |
|
| 67 | 74 | yield $class->getName(); |
| 68 | 75 | continue 2; |
| 69 | 76 | } |
@@ -71,8 +78,10 @@ discard block |
||
| 71 | 78 | |
| 72 | 79 | // Parents |
| 73 | 80 | $parent = $class->getParentClass(); |
| 74 | - while ($parent !== false) { |
|
| 75 | - if ($reader->firstClassMetadata($parent, $target->getName())) { |
|
| 81 | + while ($parent !== false) |
|
| 82 | + { |
|
| 83 | + if ($reader->firstClassMetadata($parent, $target->getName())) |
|
| 84 | + { |
|
| 76 | 85 | yield $class->getName(); |
| 77 | 86 | continue 2; |
| 78 | 87 | } |
@@ -83,9 +92,12 @@ discard block |
||
| 83 | 92 | |
| 84 | 93 | // If attribute is defined on method level and class methods has target attribute |
| 85 | 94 | // then we can add it to the list of classes |
| 86 | - if ($attribute->flags & \Attribute::TARGET_METHOD) { |
|
| 87 | - foreach ($class->getMethods() as $method) { |
|
| 88 | - if ($reader->firstFunctionMetadata($method, $target->getName())) { |
|
| 95 | + if ($attribute->flags & \Attribute::TARGET_METHOD) |
|
| 96 | + { |
|
| 97 | + foreach ($class->getMethods() as $method) |
|
| 98 | + { |
|
| 99 | + if ($reader->firstFunctionMetadata($method, $target->getName())) |
|
| 100 | + { |
|
| 89 | 101 | yield $class->getName(); |
| 90 | 102 | continue 2; |
| 91 | 103 | } |
@@ -94,9 +106,12 @@ discard block |
||
| 94 | 106 | |
| 95 | 107 | // If attribute is defined on property level and class properties has target attribute |
| 96 | 108 | // then we can add it to the list of classes |
| 97 | - if ($attribute->flags & \Attribute::TARGET_PROPERTY) { |
|
| 98 | - foreach ($class->getProperties() as $property) { |
|
| 99 | - if ($reader->firstPropertyMetadata($property, $target->getName())) { |
|
| 109 | + if ($attribute->flags & \Attribute::TARGET_PROPERTY) |
|
| 110 | + { |
|
| 111 | + foreach ($class->getProperties() as $property) |
|
| 112 | + { |
|
| 113 | + if ($reader->firstPropertyMetadata($property, $target->getName())) |
|
| 114 | + { |
|
| 100 | 115 | yield $class->getName(); |
| 101 | 116 | continue 2; |
| 102 | 117 | } |
@@ -106,9 +121,12 @@ discard block |
||
| 106 | 121 | |
| 107 | 122 | // If attribute is defined on constant level and class constants has target attribute |
| 108 | 123 | // then we can add it to the list of classes |
| 109 | - if ($attribute->flags & \Attribute::TARGET_CLASS_CONSTANT) { |
|
| 110 | - foreach ($class->getReflectionConstants() as $constant) { |
|
| 111 | - if ($reader->firstConstantMetadata($constant, $target->getName())) { |
|
| 124 | + if ($attribute->flags & \Attribute::TARGET_CLASS_CONSTANT) |
|
| 125 | + { |
|
| 126 | + foreach ($class->getReflectionConstants() as $constant) |
|
| 127 | + { |
|
| 128 | + if ($reader->firstConstantMetadata($constant, $target->getName())) |
|
| 129 | + { |
|
| 112 | 130 | yield $class->getName(); |
| 113 | 131 | continue 2; |
| 114 | 132 | } |
@@ -118,10 +136,14 @@ discard block |
||
| 118 | 136 | |
| 119 | 137 | // If attribute is defined on method parameters level and class method parameter has target attribute |
| 120 | 138 | // then we can add it to the list of classes |
| 121 | - if ($attribute->flags & \Attribute::TARGET_PARAMETER) { |
|
| 122 | - foreach ($class->getMethods() as $method) { |
|
| 123 | - foreach ($method->getParameters() as $parameter) { |
|
| 124 | - if ($reader->firstParameterMetadata($parameter, $target->getName())) { |
|
| 139 | + if ($attribute->flags & \Attribute::TARGET_PARAMETER) |
|
| 140 | + { |
|
| 141 | + foreach ($class->getMethods() as $method) |
|
| 142 | + { |
|
| 143 | + foreach ($method->getParameters() as $parameter) |
|
| 144 | + { |
|
| 145 | + if ($reader->firstParameterMetadata($parameter, $target->getName())) |
|
| 146 | + { |
|
| 125 | 147 | yield $class->getName(); |
| 126 | 148 | continue 3; |
| 127 | 149 | } |
@@ -20,10 +20,10 @@ |
||
| 20 | 20 | public function testToString(): void |
| 21 | 21 | { |
| 22 | 22 | $attribute = new TargetAttribute('foo'); |
| 23 | - $this->assertSame('3dc18b19eed74479a03c069dec2e8724', (string) $attribute); |
|
| 23 | + $this->assertSame('3dc18b19eed74479a03c069dec2e8724', (string)$attribute); |
|
| 24 | 24 | |
| 25 | 25 | $attribute = new TargetAttribute('foo', 'bar'); |
| 26 | - $this->assertSame('52ec767c53f3898bf6de6f6e88125dc8', (string) $attribute); |
|
| 26 | + $this->assertSame('52ec767c53f3898bf6de6f6e88125dc8', (string)$attribute); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | public function testFilterAttrWithArgs(): void |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | protected readonly ExceptionHandlerInterface $exceptionHandler, |
| 78 | 78 | protected readonly BootloadManagerInterface $bootloader, |
| 79 | 79 | array $directories |
| 80 | - ) { |
|
| 80 | + ){ |
|
| 81 | 81 | $container->bindSingleton(ExceptionHandlerInterface::class, $exceptionHandler); |
| 82 | 82 | $container->bindSingleton(ExceptionRendererInterface::class, $exceptionHandler); |
| 83 | 83 | $container->bindSingleton(ExceptionReporterInterface::class, $exceptionHandler); |
@@ -114,35 +114,35 @@ discard block |
||
| 114 | 114 | final public static function create( |
| 115 | 115 | array $directories, |
| 116 | 116 | bool $handleErrors = true, |
| 117 | - ExceptionHandlerInterface|string|null $exceptionHandler = null, |
|
| 117 | + ExceptionHandlerInterface | string | null $exceptionHandler = null, |
|
| 118 | 118 | Container $container = new Container(), |
| 119 | - BootloadManagerInterface|Autowire|null $bootloadManager = null |
|
| 119 | + BootloadManagerInterface | Autowire | null $bootloadManager = null |
|
| 120 | 120 | ): static { |
| 121 | 121 | $exceptionHandler ??= ExceptionHandler::class; |
| 122 | 122 | |
| 123 | - if (\is_string($exceptionHandler)) { |
|
| 123 | + if (\is_string($exceptionHandler)){ |
|
| 124 | 124 | $exceptionHandler = $container->make($exceptionHandler); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if ($handleErrors) { |
|
| 127 | + if ($handleErrors){ |
|
| 128 | 128 | $exceptionHandler->register(); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - if (!$container->has(InitializerInterface::class)) { |
|
| 131 | + if (!$container->has(InitializerInterface::class)){ |
|
| 132 | 132 | $container->bind(InitializerInterface::class, Initializer::class); |
| 133 | 133 | } |
| 134 | - if (!$container->has(InvokerStrategyInterface::class)) { |
|
| 134 | + if (!$container->has(InvokerStrategyInterface::class)){ |
|
| 135 | 135 | $container->bind(InvokerStrategyInterface::class, DefaultInvokerStrategy::class); |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - if ($bootloadManager instanceof Autowire) { |
|
| 138 | + if ($bootloadManager instanceof Autowire){ |
|
| 139 | 139 | $bootloadManager = $bootloadManager->resolve($container); |
| 140 | 140 | } |
| 141 | 141 | $bootloadManager ??= $container->make(StrategyBasedBootloadManager::class); |
| 142 | 142 | \assert($bootloadManager instanceof BootloadManagerInterface); |
| 143 | 143 | $container->bind(BootloadManagerInterface::class, $bootloadManager); |
| 144 | 144 | |
| 145 | - if (!$container->has(BootloaderRegistryInterface::class)) { |
|
| 145 | + if (!$container->has(BootloaderRegistryInterface::class)){ |
|
| 146 | 146 | /** @psalm-suppress InvalidArgument */ |
| 147 | 147 | $container->bindSingleton(BootloaderRegistryInterface::class, [self::class, 'initBootloaderRegistry']); |
| 148 | 148 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | $environment ??= new Environment(); |
| 173 | 173 | $this->container->bindSingleton(EnvironmentInterface::class, $environment); |
| 174 | 174 | |
| 175 | - try { |
|
| 175 | + try{ |
|
| 176 | 176 | // will protect any against env overwrite action |
| 177 | 177 | $this->container->runScope( |
| 178 | 178 | [EnvironmentInterface::class => $environment], |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $this->fireCallbacks($this->bootstrappedCallbacks); |
| 190 | 190 | } |
| 191 | 191 | ); |
| 192 | - } catch (\Throwable $e) { |
|
| 192 | + }catch (\Throwable $e){ |
|
| 193 | 193 | $this->exceptionHandler->handleGlobalException($e); |
| 194 | 194 | |
| 195 | 195 | return null; |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | public function running(Closure ...$callbacks): void |
| 212 | 212 | { |
| 213 | - foreach ($callbacks as $callback) { |
|
| 213 | + foreach ($callbacks as $callback){ |
|
| 214 | 214 | $this->runningCallbacks[] = $callback; |
| 215 | 215 | } |
| 216 | 216 | } |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | public function booting(Closure ...$callbacks): void |
| 227 | 227 | { |
| 228 | - foreach ($callbacks as $callback) { |
|
| 228 | + foreach ($callbacks as $callback){ |
|
| 229 | 229 | $this->bootingCallbacks[] = $callback; |
| 230 | 230 | } |
| 231 | 231 | } |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | public function booted(Closure ...$callbacks): void |
| 242 | 242 | { |
| 243 | - foreach ($callbacks as $callback) { |
|
| 243 | + foreach ($callbacks as $callback){ |
|
| 244 | 244 | $this->bootedCallbacks[] = $callback; |
| 245 | 245 | } |
| 246 | 246 | } |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public function bootstrapped(Closure ...$callbacks): void |
| 258 | 258 | { |
| 259 | - foreach ($callbacks as $callback) { |
|
| 259 | + foreach ($callbacks as $callback){ |
|
| 260 | 260 | $this->bootstrappedCallbacks[] = $callback; |
| 261 | 261 | } |
| 262 | 262 | } |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | * @param class-string<DispatcherInterface>|DispatcherInterface $dispatcher The class name or instance |
| 269 | 269 | * of the dispatcher. Since v4.0, it will only accept the class name. |
| 270 | 270 | */ |
| 271 | - public function addDispatcher(string|DispatcherInterface $dispatcher): self |
|
| 271 | + public function addDispatcher(string | DispatcherInterface $dispatcher): self |
|
| 272 | 272 | { |
| 273 | - if (\is_object($dispatcher)) { |
|
| 273 | + if (\is_object($dispatcher)){ |
|
| 274 | 274 | $dispatcher = $dispatcher::class; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -292,19 +292,19 @@ discard block |
||
| 292 | 292 | $eventDispatcher?->dispatch(new Serving()); |
| 293 | 293 | |
| 294 | 294 | $serving = $servingScope = null; |
| 295 | - foreach ($this->dispatchers as $dispatcher) { |
|
| 295 | + foreach ($this->dispatchers as $dispatcher){ |
|
| 296 | 296 | $reflection = new \ReflectionClass($dispatcher); |
| 297 | 297 | |
| 298 | 298 | $scope = ($reflection->getAttributes(DispatcherScope::class)[0] ?? null)?->newInstance()->scope; |
| 299 | 299 | $this->container->getBinder($scope)->bind($dispatcher, $dispatcher); |
| 300 | 300 | |
| 301 | - if ($serving === null && $this->canServe($reflection)) { |
|
| 301 | + if ($serving === null && $this->canServe($reflection)){ |
|
| 302 | 302 | $serving = $dispatcher; |
| 303 | 303 | $servingScope = $scope; |
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - if ($serving === null) { |
|
| 307 | + if ($serving === null){ |
|
| 308 | 308 | $eventDispatcher?->dispatch(new DispatcherNotFound()); |
| 309 | 309 | throw new BootException('Unable to locate active dispatcher.'); |
| 310 | 310 | } |
@@ -353,13 +353,13 @@ discard block |
||
| 353 | 353 | */ |
| 354 | 354 | protected function fireCallbacks(array &$callbacks): void |
| 355 | 355 | { |
| 356 | - if ($callbacks === []) { |
|
| 356 | + if ($callbacks === []){ |
|
| 357 | 357 | return; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - do { |
|
| 360 | + do{ |
|
| 361 | 361 | $this->container->invoke(\current($callbacks)); |
| 362 | - } while (\next($callbacks)); |
|
| 362 | + }while (\next($callbacks)); |
|
| 363 | 363 | |
| 364 | 364 | $callbacks = []; |
| 365 | 365 | } |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | */ |
| 400 | 400 | private function canServe(\ReflectionClass $reflection): bool |
| 401 | 401 | { |
| 402 | - if (!$reflection->hasMethod('canServe')) { |
|
| 402 | + if (!$reflection->hasMethod('canServe')){ |
|
| 403 | 403 | throw new BootException('Dispatcher must implement static `canServe` method.'); |
| 404 | 404 | } |
| 405 | 405 | |
@@ -120,29 +120,35 @@ discard block |
||
| 120 | 120 | ): static { |
| 121 | 121 | $exceptionHandler ??= ExceptionHandler::class; |
| 122 | 122 | |
| 123 | - if (\is_string($exceptionHandler)) { |
|
| 123 | + if (\is_string($exceptionHandler)) |
|
| 124 | + { |
|
| 124 | 125 | $exceptionHandler = $container->make($exceptionHandler); |
| 125 | 126 | } |
| 126 | 127 | |
| 127 | - if ($handleErrors) { |
|
| 128 | + if ($handleErrors) |
|
| 129 | + { |
|
| 128 | 130 | $exceptionHandler->register(); |
| 129 | 131 | } |
| 130 | 132 | |
| 131 | - if (!$container->has(InitializerInterface::class)) { |
|
| 133 | + if (!$container->has(InitializerInterface::class)) |
|
| 134 | + { |
|
| 132 | 135 | $container->bind(InitializerInterface::class, Initializer::class); |
| 133 | 136 | } |
| 134 | - if (!$container->has(InvokerStrategyInterface::class)) { |
|
| 137 | + if (!$container->has(InvokerStrategyInterface::class)) |
|
| 138 | + { |
|
| 135 | 139 | $container->bind(InvokerStrategyInterface::class, DefaultInvokerStrategy::class); |
| 136 | 140 | } |
| 137 | 141 | |
| 138 | - if ($bootloadManager instanceof Autowire) { |
|
| 142 | + if ($bootloadManager instanceof Autowire) |
|
| 143 | + { |
|
| 139 | 144 | $bootloadManager = $bootloadManager->resolve($container); |
| 140 | 145 | } |
| 141 | 146 | $bootloadManager ??= $container->make(StrategyBasedBootloadManager::class); |
| 142 | 147 | \assert($bootloadManager instanceof BootloadManagerInterface); |
| 143 | 148 | $container->bind(BootloadManagerInterface::class, $bootloadManager); |
| 144 | 149 | |
| 145 | - if (!$container->has(BootloaderRegistryInterface::class)) { |
|
| 150 | + if (!$container->has(BootloaderRegistryInterface::class)) |
|
| 151 | + { |
|
| 146 | 152 | /** @psalm-suppress InvalidArgument */ |
| 147 | 153 | $container->bindSingleton(BootloaderRegistryInterface::class, [self::class, 'initBootloaderRegistry']); |
| 148 | 154 | } |
@@ -172,7 +178,8 @@ discard block |
||
| 172 | 178 | $environment ??= new Environment(); |
| 173 | 179 | $this->container->bindSingleton(EnvironmentInterface::class, $environment); |
| 174 | 180 | |
| 175 | - try { |
|
| 181 | + try |
|
| 182 | + { |
|
| 176 | 183 | // will protect any against env overwrite action |
| 177 | 184 | $this->container->runScope( |
| 178 | 185 | [EnvironmentInterface::class => $environment], |
@@ -189,7 +196,9 @@ discard block |
||
| 189 | 196 | $this->fireCallbacks($this->bootstrappedCallbacks); |
| 190 | 197 | } |
| 191 | 198 | ); |
| 192 | - } catch (\Throwable $e) { |
|
| 199 | + } |
|
| 200 | + catch (\Throwable $e) |
|
| 201 | + { |
|
| 193 | 202 | $this->exceptionHandler->handleGlobalException($e); |
| 194 | 203 | |
| 195 | 204 | return null; |
@@ -210,7 +219,8 @@ discard block |
||
| 210 | 219 | */ |
| 211 | 220 | public function running(Closure ...$callbacks): void |
| 212 | 221 | { |
| 213 | - foreach ($callbacks as $callback) { |
|
| 222 | + foreach ($callbacks as $callback) |
|
| 223 | + { |
|
| 214 | 224 | $this->runningCallbacks[] = $callback; |
| 215 | 225 | } |
| 216 | 226 | } |
@@ -225,7 +235,8 @@ discard block |
||
| 225 | 235 | */ |
| 226 | 236 | public function booting(Closure ...$callbacks): void |
| 227 | 237 | { |
| 228 | - foreach ($callbacks as $callback) { |
|
| 238 | + foreach ($callbacks as $callback) |
|
| 239 | + { |
|
| 229 | 240 | $this->bootingCallbacks[] = $callback; |
| 230 | 241 | } |
| 231 | 242 | } |
@@ -240,7 +251,8 @@ discard block |
||
| 240 | 251 | */ |
| 241 | 252 | public function booted(Closure ...$callbacks): void |
| 242 | 253 | { |
| 243 | - foreach ($callbacks as $callback) { |
|
| 254 | + foreach ($callbacks as $callback) |
|
| 255 | + { |
|
| 244 | 256 | $this->bootedCallbacks[] = $callback; |
| 245 | 257 | } |
| 246 | 258 | } |
@@ -256,7 +268,8 @@ discard block |
||
| 256 | 268 | */ |
| 257 | 269 | public function bootstrapped(Closure ...$callbacks): void |
| 258 | 270 | { |
| 259 | - foreach ($callbacks as $callback) { |
|
| 271 | + foreach ($callbacks as $callback) |
|
| 272 | + { |
|
| 260 | 273 | $this->bootstrappedCallbacks[] = $callback; |
| 261 | 274 | } |
| 262 | 275 | } |
@@ -270,7 +283,8 @@ discard block |
||
| 270 | 283 | */ |
| 271 | 284 | public function addDispatcher(string|DispatcherInterface $dispatcher): self |
| 272 | 285 | { |
| 273 | - if (\is_object($dispatcher)) { |
|
| 286 | + if (\is_object($dispatcher)) |
|
| 287 | + { |
|
| 274 | 288 | $dispatcher = $dispatcher::class; |
| 275 | 289 | } |
| 276 | 290 | |
@@ -292,19 +306,22 @@ discard block |
||
| 292 | 306 | $eventDispatcher?->dispatch(new Serving()); |
| 293 | 307 | |
| 294 | 308 | $serving = $servingScope = null; |
| 295 | - foreach ($this->dispatchers as $dispatcher) { |
|
| 309 | + foreach ($this->dispatchers as $dispatcher) |
|
| 310 | + { |
|
| 296 | 311 | $reflection = new \ReflectionClass($dispatcher); |
| 297 | 312 | |
| 298 | 313 | $scope = ($reflection->getAttributes(DispatcherScope::class)[0] ?? null)?->newInstance()->scope; |
| 299 | 314 | $this->container->getBinder($scope)->bind($dispatcher, $dispatcher); |
| 300 | 315 | |
| 301 | - if ($serving === null && $this->canServe($reflection)) { |
|
| 316 | + if ($serving === null && $this->canServe($reflection)) |
|
| 317 | + { |
|
| 302 | 318 | $serving = $dispatcher; |
| 303 | 319 | $servingScope = $scope; |
| 304 | 320 | } |
| 305 | 321 | } |
| 306 | 322 | |
| 307 | - if ($serving === null) { |
|
| 323 | + if ($serving === null) |
|
| 324 | + { |
|
| 308 | 325 | $eventDispatcher?->dispatch(new DispatcherNotFound()); |
| 309 | 326 | throw new BootException('Unable to locate active dispatcher.'); |
| 310 | 327 | } |
@@ -353,11 +370,13 @@ discard block |
||
| 353 | 370 | */ |
| 354 | 371 | protected function fireCallbacks(array &$callbacks): void |
| 355 | 372 | { |
| 356 | - if ($callbacks === []) { |
|
| 373 | + if ($callbacks === []) |
|
| 374 | + { |
|
| 357 | 375 | return; |
| 358 | 376 | } |
| 359 | 377 | |
| 360 | - do { |
|
| 378 | + do |
|
| 379 | + { |
|
| 361 | 380 | $this->container->invoke(\current($callbacks)); |
| 362 | 381 | } while (\next($callbacks)); |
| 363 | 382 | |
@@ -399,7 +418,8 @@ discard block |
||
| 399 | 418 | */ |
| 400 | 419 | private function canServe(\ReflectionClass $reflection): bool |
| 401 | 420 | { |
| 402 | - if (!$reflection->hasMethod('canServe')) { |
|
| 421 | + if (!$reflection->hasMethod('canServe')) |
|
| 422 | + { |
|
| 403 | 423 | throw new BootException('Dispatcher must implement static `canServe` method.'); |
| 404 | 424 | } |
| 405 | 425 | |