@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | protected readonly ExceptionHandlerInterface $exceptionHandler, |
| 62 | 62 | protected readonly BootloadManagerInterface $bootloader, |
| 63 | 63 | array $directories |
| 64 | - ) { |
|
| 64 | + ){ |
|
| 65 | 65 | $container->bindSingleton(ExceptionHandlerInterface::class, $exceptionHandler); |
| 66 | 66 | $container->bindSingleton(ExceptionRendererInterface::class, $exceptionHandler); |
| 67 | 67 | $container->bindSingleton(ExceptionReporterInterface::class, $exceptionHandler); |
@@ -100,21 +100,21 @@ discard block |
||
| 100 | 100 | final public static function create( |
| 101 | 101 | array $directories, |
| 102 | 102 | bool $handleErrors = true, |
| 103 | - ExceptionHandlerInterface|string|null $exceptionHandler = null, |
|
| 103 | + ExceptionHandlerInterface | string | null $exceptionHandler = null, |
|
| 104 | 104 | Container $container = new Container(), |
| 105 | 105 | ?BootloadManagerInterface $bootloadManager = null |
| 106 | 106 | ): static { |
| 107 | 107 | $exceptionHandler ??= ExceptionHandler::class; |
| 108 | 108 | |
| 109 | - if (\is_string($exceptionHandler)) { |
|
| 109 | + if (\is_string($exceptionHandler)){ |
|
| 110 | 110 | $exceptionHandler = $container->make($exceptionHandler); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - if ($handleErrors) { |
|
| 113 | + if ($handleErrors){ |
|
| 114 | 114 | $exceptionHandler->register(); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if (!$container->has(InitializerInterface::class)) { |
|
| 117 | + if (!$container->has(InitializerInterface::class)){ |
|
| 118 | 118 | $container->bind(InitializerInterface::class, Initializer::class); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | $this->fireCallbacks($this->runningCallbacks); |
| 151 | 151 | |
| 152 | - try { |
|
| 152 | + try{ |
|
| 153 | 153 | // will protect any against env overwrite action |
| 154 | 154 | $this->container->runScope( |
| 155 | 155 | [EnvironmentInterface::class => $environment], |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $this->fireCallbacks($this->bootstrappedCallbacks); |
| 161 | 161 | } |
| 162 | 162 | ); |
| 163 | - } catch (\Throwable $e) { |
|
| 163 | + }catch (\Throwable $e){ |
|
| 164 | 164 | $this->exceptionHandler->handleGlobalException($e); |
| 165 | 165 | |
| 166 | 166 | return null; |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | public function running(Closure ...$callbacks): void |
| 183 | 183 | { |
| 184 | - foreach ($callbacks as $callback) { |
|
| 184 | + foreach ($callbacks as $callback){ |
|
| 185 | 185 | $this->runningCallbacks[] = $callback; |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public function booting(Closure ...$callbacks): void |
| 198 | 198 | { |
| 199 | - foreach ($callbacks as $callback) { |
|
| 199 | + foreach ($callbacks as $callback){ |
|
| 200 | 200 | $this->bootingCallbacks[] = $callback; |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | public function booted(Closure ...$callbacks): void |
| 213 | 213 | { |
| 214 | - foreach ($callbacks as $callback) { |
|
| 214 | + foreach ($callbacks as $callback){ |
|
| 215 | 215 | $this->bootedCallbacks[] = $callback; |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | */ |
| 228 | 228 | public function bootstrapped(Closure ...$callbacks): void |
| 229 | 229 | { |
| 230 | - foreach ($callbacks as $callback) { |
|
| 230 | + foreach ($callbacks as $callback){ |
|
| 231 | 231 | $this->bootstrappedCallbacks[] = $callback; |
| 232 | 232 | } |
| 233 | 233 | } |
@@ -255,8 +255,8 @@ discard block |
||
| 255 | 255 | $eventDispatcher = $this->getEventDispatcher(); |
| 256 | 256 | $eventDispatcher?->dispatch(new Serving()); |
| 257 | 257 | |
| 258 | - foreach ($this->dispatchers as $dispatcher) { |
|
| 259 | - if ($dispatcher->canServe()) { |
|
| 258 | + foreach ($this->dispatchers as $dispatcher){ |
|
| 259 | + if ($dispatcher->canServe()){ |
|
| 260 | 260 | return $this->container->runScope( |
| 261 | 261 | [DispatcherInterface::class => $dispatcher], |
| 262 | 262 | static function () use ($dispatcher, $eventDispatcher): mixed { |
@@ -297,13 +297,13 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | protected function fireCallbacks(array &$callbacks): void |
| 299 | 299 | { |
| 300 | - if ($callbacks === []) { |
|
| 300 | + if ($callbacks === []){ |
|
| 301 | 301 | return; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - do { |
|
| 304 | + do{ |
|
| 305 | 305 | $this->container->invoke(\current($callbacks)); |
| 306 | - } while (\next($callbacks)); |
|
| 306 | + }while (\next($callbacks)); |
|
| 307 | 307 | |
| 308 | 308 | $callbacks = []; |
| 309 | 309 | } |
@@ -106,15 +106,18 @@ discard block |
||
| 106 | 106 | ): static { |
| 107 | 107 | $exceptionHandler ??= ExceptionHandler::class; |
| 108 | 108 | |
| 109 | - if (\is_string($exceptionHandler)) { |
|
| 109 | + if (\is_string($exceptionHandler)) |
|
| 110 | + { |
|
| 110 | 111 | $exceptionHandler = $container->make($exceptionHandler); |
| 111 | 112 | } |
| 112 | 113 | |
| 113 | - if ($handleErrors) { |
|
| 114 | + if ($handleErrors) |
|
| 115 | + { |
|
| 114 | 116 | $exceptionHandler->register(); |
| 115 | 117 | } |
| 116 | 118 | |
| 117 | - if (!$container->has(InitializerInterface::class)) { |
|
| 119 | + if (!$container->has(InitializerInterface::class)) |
|
| 120 | + { |
|
| 118 | 121 | $container->bind(InitializerInterface::class, Initializer::class); |
| 119 | 122 | } |
| 120 | 123 | |
@@ -149,7 +152,8 @@ discard block |
||
| 149 | 152 | |
| 150 | 153 | $this->fireCallbacks($this->runningCallbacks); |
| 151 | 154 | |
| 152 | - try { |
|
| 155 | + try |
|
| 156 | + { |
|
| 153 | 157 | // will protect any against env overwrite action |
| 154 | 158 | $this->container->runScope( |
| 155 | 159 | [EnvironmentInterface::class => $environment], |
@@ -160,7 +164,9 @@ discard block |
||
| 160 | 164 | $this->fireCallbacks($this->bootstrappedCallbacks); |
| 161 | 165 | } |
| 162 | 166 | ); |
| 163 | - } catch (\Throwable $e) { |
|
| 167 | + } |
|
| 168 | + catch (\Throwable $e) |
|
| 169 | + { |
|
| 164 | 170 | $this->exceptionHandler->handleGlobalException($e); |
| 165 | 171 | |
| 166 | 172 | return null; |
@@ -181,7 +187,8 @@ discard block |
||
| 181 | 187 | */ |
| 182 | 188 | public function running(Closure ...$callbacks): void |
| 183 | 189 | { |
| 184 | - foreach ($callbacks as $callback) { |
|
| 190 | + foreach ($callbacks as $callback) |
|
| 191 | + { |
|
| 185 | 192 | $this->runningCallbacks[] = $callback; |
| 186 | 193 | } |
| 187 | 194 | } |
@@ -196,7 +203,8 @@ discard block |
||
| 196 | 203 | */ |
| 197 | 204 | public function booting(Closure ...$callbacks): void |
| 198 | 205 | { |
| 199 | - foreach ($callbacks as $callback) { |
|
| 206 | + foreach ($callbacks as $callback) |
|
| 207 | + { |
|
| 200 | 208 | $this->bootingCallbacks[] = $callback; |
| 201 | 209 | } |
| 202 | 210 | } |
@@ -211,7 +219,8 @@ discard block |
||
| 211 | 219 | */ |
| 212 | 220 | public function booted(Closure ...$callbacks): void |
| 213 | 221 | { |
| 214 | - foreach ($callbacks as $callback) { |
|
| 222 | + foreach ($callbacks as $callback) |
|
| 223 | + { |
|
| 215 | 224 | $this->bootedCallbacks[] = $callback; |
| 216 | 225 | } |
| 217 | 226 | } |
@@ -227,7 +236,8 @@ discard block |
||
| 227 | 236 | */ |
| 228 | 237 | public function bootstrapped(Closure ...$callbacks): void |
| 229 | 238 | { |
| 230 | - foreach ($callbacks as $callback) { |
|
| 239 | + foreach ($callbacks as $callback) |
|
| 240 | + { |
|
| 231 | 241 | $this->bootstrappedCallbacks[] = $callback; |
| 232 | 242 | } |
| 233 | 243 | } |
@@ -255,8 +265,10 @@ discard block |
||
| 255 | 265 | $eventDispatcher = $this->getEventDispatcher(); |
| 256 | 266 | $eventDispatcher?->dispatch(new Serving()); |
| 257 | 267 | |
| 258 | - foreach ($this->dispatchers as $dispatcher) { |
|
| 259 | - if ($dispatcher->canServe()) { |
|
| 268 | + foreach ($this->dispatchers as $dispatcher) |
|
| 269 | + { |
|
| 270 | + if ($dispatcher->canServe()) |
|
| 271 | + { |
|
| 260 | 272 | return $this->container->runScope( |
| 261 | 273 | [DispatcherInterface::class => $dispatcher], |
| 262 | 274 | static function () use ($dispatcher, $eventDispatcher): mixed { |
@@ -297,11 +309,13 @@ discard block |
||
| 297 | 309 | */ |
| 298 | 310 | protected function fireCallbacks(array &$callbacks): void |
| 299 | 311 | { |
| 300 | - if ($callbacks === []) { |
|
| 312 | + if ($callbacks === []) |
|
| 313 | + { |
|
| 301 | 314 | return; |
| 302 | 315 | } |
| 303 | 316 | |
| 304 | - do { |
|
| 317 | + do |
|
| 318 | + { |
|
| 305 | 319 | $this->container->invoke(\current($callbacks)); |
| 306 | 320 | } while (\next($callbacks)); |
| 307 | 321 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | protected readonly ContainerInterface $container, |
| 24 | 24 | protected readonly BinderInterface $binder, |
| 25 | 25 | protected readonly ClassesRegistry $bootloaders = new ClassesRegistry() |
| 26 | - ) { |
|
| 26 | + ){ |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -33,34 +33,34 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public function init(array $classes): \Generator |
| 35 | 35 | { |
| 36 | - foreach ($classes as $bootloader => $options) { |
|
| 36 | + foreach ($classes as $bootloader => $options){ |
|
| 37 | 37 | // default bootload syntax as simple array |
| 38 | - if (\is_string($options) || $options instanceof BootloaderInterface) { |
|
| 38 | + if (\is_string($options) || $options instanceof BootloaderInterface){ |
|
| 39 | 39 | $bootloader = $options; |
| 40 | 40 | $options = []; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // Replace class aliases with source classes |
| 44 | - try { |
|
| 44 | + try{ |
|
| 45 | 45 | $ref = (new \ReflectionClass($bootloader)); |
| 46 | 46 | $className = $ref->getName(); |
| 47 | - } catch (\ReflectionException) { |
|
| 47 | + }catch (\ReflectionException){ |
|
| 48 | 48 | throw new ClassNotFoundException( |
| 49 | 49 | \sprintf('Bootloader class `%s` is not exist.', $bootloader) |
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if ($this->bootloaders->isBooted($className) || $ref->isAbstract()) { |
|
| 53 | + if ($this->bootloaders->isBooted($className) || $ref->isAbstract()){ |
|
| 54 | 54 | continue; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | $this->bootloaders->register($className); |
| 58 | 58 | |
| 59 | - if (!$bootloader instanceof BootloaderInterface) { |
|
| 59 | + if (!$bootloader instanceof BootloaderInterface){ |
|
| 60 | 60 | $bootloader = $this->container->get($bootloader); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - if (!$this->isBootloader($bootloader)) { |
|
| 63 | + if (!$this->isBootloader($bootloader)){ |
|
| 64 | 64 | continue; |
| 65 | 65 | } |
| 66 | 66 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | protected function initBootloader(BootloaderInterface $bootloader): iterable |
| 82 | 82 | { |
| 83 | - if ($bootloader instanceof DependedInterface) { |
|
| 83 | + if ($bootloader instanceof DependedInterface){ |
|
| 84 | 84 | yield from $this->init($this->getDependencies($bootloader)); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | protected function initBindings(array $bindings, array $singletons): void |
| 100 | 100 | { |
| 101 | - foreach ($bindings as $aliases => $resolver) { |
|
| 101 | + foreach ($bindings as $aliases => $resolver){ |
|
| 102 | 102 | $this->binder->bind($aliases, $resolver); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - foreach ($singletons as $aliases => $resolver) { |
|
| 105 | + foreach ($singletons as $aliases => $resolver){ |
|
| 106 | 106 | $this->binder->bindSingleton($aliases, $resolver); |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | $methodsDeps = []; |
| 117 | 117 | |
| 118 | - foreach (Methods::cases() as $method) { |
|
| 119 | - if ($reflectionClass->hasMethod($method->value)) { |
|
| 118 | + foreach (Methods::cases() as $method){ |
|
| 119 | + if ($reflectionClass->hasMethod($method->value)){ |
|
| 120 | 120 | $methodsDeps[] = $this->findBootloaderClassesInMethod( |
| 121 | 121 | $reflectionClass->getMethod($method->value) |
| 122 | 122 | ); |
@@ -129,9 +129,9 @@ discard block |
||
| 129 | 129 | protected function findBootloaderClassesInMethod(\ReflectionMethod $method): array |
| 130 | 130 | { |
| 131 | 131 | $args = []; |
| 132 | - foreach ($method->getParameters() as $parameter) { |
|
| 132 | + foreach ($method->getParameters() as $parameter){ |
|
| 133 | 133 | $type = $parameter->getType(); |
| 134 | - if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type)) { |
|
| 134 | + if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type)){ |
|
| 135 | 135 | $args[] = $type->getName(); |
| 136 | 136 | } |
| 137 | 137 | } |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @psalm-pure |
| 154 | 154 | * @psalm-assert-if-true TClass $class |
| 155 | 155 | */ |
| 156 | - protected function isBootloader(string|object $class): bool |
|
| 156 | + protected function isBootloader(string | object $class): bool |
|
| 157 | 157 | { |
| 158 | 158 | return \is_subclass_of($class, BootloaderInterface::class); |
| 159 | 159 | } |
@@ -33,34 +33,42 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public function init(array $classes): \Generator |
| 35 | 35 | { |
| 36 | - foreach ($classes as $bootloader => $options) { |
|
| 36 | + foreach ($classes as $bootloader => $options) |
|
| 37 | + { |
|
| 37 | 38 | // default bootload syntax as simple array |
| 38 | - if (\is_string($options) || $options instanceof BootloaderInterface) { |
|
| 39 | + if (\is_string($options) || $options instanceof BootloaderInterface) |
|
| 40 | + { |
|
| 39 | 41 | $bootloader = $options; |
| 40 | 42 | $options = []; |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | 45 | // Replace class aliases with source classes |
| 44 | - try { |
|
| 46 | + try |
|
| 47 | + { |
|
| 45 | 48 | $ref = (new \ReflectionClass($bootloader)); |
| 46 | 49 | $className = $ref->getName(); |
| 47 | - } catch (\ReflectionException) { |
|
| 50 | + } |
|
| 51 | + catch (\ReflectionException) |
|
| 52 | + { |
|
| 48 | 53 | throw new ClassNotFoundException( |
| 49 | 54 | \sprintf('Bootloader class `%s` is not exist.', $bootloader) |
| 50 | 55 | ); |
| 51 | 56 | } |
| 52 | 57 | |
| 53 | - if ($this->bootloaders->isBooted($className) || $ref->isAbstract()) { |
|
| 58 | + if ($this->bootloaders->isBooted($className) || $ref->isAbstract()) |
|
| 59 | + { |
|
| 54 | 60 | continue; |
| 55 | 61 | } |
| 56 | 62 | |
| 57 | 63 | $this->bootloaders->register($className); |
| 58 | 64 | |
| 59 | - if (!$bootloader instanceof BootloaderInterface) { |
|
| 65 | + if (!$bootloader instanceof BootloaderInterface) |
|
| 66 | + { |
|
| 60 | 67 | $bootloader = $this->container->get($bootloader); |
| 61 | 68 | } |
| 62 | 69 | |
| 63 | - if (!$this->isBootloader($bootloader)) { |
|
| 70 | + if (!$this->isBootloader($bootloader)) |
|
| 71 | + { |
|
| 64 | 72 | continue; |
| 65 | 73 | } |
| 66 | 74 | |
@@ -80,7 +88,8 @@ discard block |
||
| 80 | 88 | */ |
| 81 | 89 | protected function initBootloader(BootloaderInterface $bootloader): iterable |
| 82 | 90 | { |
| 83 | - if ($bootloader instanceof DependedInterface) { |
|
| 91 | + if ($bootloader instanceof DependedInterface) |
|
| 92 | + { |
|
| 84 | 93 | yield from $this->init($this->getDependencies($bootloader)); |
| 85 | 94 | } |
| 86 | 95 | |
@@ -98,11 +107,13 @@ discard block |
||
| 98 | 107 | */ |
| 99 | 108 | protected function initBindings(array $bindings, array $singletons): void |
| 100 | 109 | { |
| 101 | - foreach ($bindings as $aliases => $resolver) { |
|
| 110 | + foreach ($bindings as $aliases => $resolver) |
|
| 111 | + { |
|
| 102 | 112 | $this->binder->bind($aliases, $resolver); |
| 103 | 113 | } |
| 104 | 114 | |
| 105 | - foreach ($singletons as $aliases => $resolver) { |
|
| 115 | + foreach ($singletons as $aliases => $resolver) |
|
| 116 | + { |
|
| 106 | 117 | $this->binder->bindSingleton($aliases, $resolver); |
| 107 | 118 | } |
| 108 | 119 | } |
@@ -115,8 +126,10 @@ discard block |
||
| 115 | 126 | |
| 116 | 127 | $methodsDeps = []; |
| 117 | 128 | |
| 118 | - foreach (Methods::cases() as $method) { |
|
| 119 | - if ($reflectionClass->hasMethod($method->value)) { |
|
| 129 | + foreach (Methods::cases() as $method) |
|
| 130 | + { |
|
| 131 | + if ($reflectionClass->hasMethod($method->value)) |
|
| 132 | + { |
|
| 120 | 133 | $methodsDeps[] = $this->findBootloaderClassesInMethod( |
| 121 | 134 | $reflectionClass->getMethod($method->value) |
| 122 | 135 | ); |
@@ -129,9 +142,11 @@ discard block |
||
| 129 | 142 | protected function findBootloaderClassesInMethod(\ReflectionMethod $method): array |
| 130 | 143 | { |
| 131 | 144 | $args = []; |
| 132 | - foreach ($method->getParameters() as $parameter) { |
|
| 145 | + foreach ($method->getParameters() as $parameter) |
|
| 146 | + { |
|
| 133 | 147 | $type = $parameter->getType(); |
| 134 | - if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type)) { |
|
| 148 | + if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type)) |
|
| 149 | + { |
|
| 135 | 150 | $args[] = $type->getName(); |
| 136 | 151 | } |
| 137 | 152 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | private readonly InvokerInterface $invoker, |
| 24 | 24 | private readonly ResolverInterface $resolver, |
| 25 | 25 | private readonly InitializerInterface $initializer |
| 26 | - ) { |
|
| 26 | + ){ |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | public function getClasses(): array |
@@ -52,13 +52,13 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $bootloaders = \iterator_to_array($this->initializer->init($classes)); |
| 54 | 54 | |
| 55 | - foreach ($bootloaders as $data) { |
|
| 55 | + foreach ($bootloaders as $data){ |
|
| 56 | 56 | $this->invokeBootloader($data['bootloader'], Methods::INIT, $data['options']); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | $this->fireCallbacks($bootingCallbacks); |
| 60 | 60 | |
| 61 | - foreach ($bootloaders as $data) { |
|
| 61 | + foreach ($bootloaders as $data){ |
|
| 62 | 62 | $this->invokeBootloader($data['bootloader'], Methods::BOOT, $data['options']); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | private function invokeBootloader(BootloaderInterface $bootloader, Methods $method, array $options): void |
| 69 | 69 | { |
| 70 | 70 | $refl = new \ReflectionClass($bootloader); |
| 71 | - if (!$refl->hasMethod($method->value)) { |
|
| 71 | + if (!$refl->hasMethod($method->value)){ |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $method = $refl->getMethod($method->value); |
| 76 | 76 | |
| 77 | 77 | $args = $this->resolver->resolveArguments($method); |
| 78 | - if (!isset($args['boot'])) { |
|
| 78 | + if (!isset($args['boot'])){ |
|
| 79 | 79 | $args['boot'] = $options; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | private function fireCallbacks(array $callbacks): void |
| 89 | 89 | { |
| 90 | - foreach ($callbacks as $callback) { |
|
| 90 | + foreach ($callbacks as $callback){ |
|
| 91 | 91 | $this->invoker->invoke($callback); |
| 92 | 92 | } |
| 93 | 93 | } |