@@ -53,7 +53,7 @@ |
||
| 53 | 53 | public function resolve(object $attribute, object $service, \ReflectionMethod $method): void |
| 54 | 54 | { |
| 55 | 55 | $attributeClass = $attribute::class; |
| 56 | - if (!isset($this->resolvers[$attributeClass])) { |
|
| 56 | + if (!isset($this->resolvers[$attributeClass])){ |
|
| 57 | 57 | throw new \RuntimeException("No resolver for attribute {$attributeClass}"); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -53,7 +53,8 @@ |
||
| 53 | 53 | public function resolve(object $attribute, object $service, \ReflectionMethod $method): void |
| 54 | 54 | { |
| 55 | 55 | $attributeClass = $attribute::class; |
| 56 | - if (!isset($this->resolvers[$attributeClass])) { |
|
| 56 | + if (!isset($this->resolvers[$attributeClass])) |
|
| 57 | + { |
|
| 57 | 58 | throw new \RuntimeException("No resolver for attribute {$attributeClass}"); |
| 58 | 59 | } |
| 59 | 60 | |
@@ -38,7 +38,8 @@ discard block |
||
| 38 | 38 | protected readonly BinderInterface $binder, |
| 39 | 39 | protected readonly ClassesRegistry $bootloaders = new ClassesRegistry(), |
| 40 | 40 | ?BootloaderCheckerInterface $checker = null, |
| 41 | - ) {} |
|
| 41 | + ) { |
|
| 42 | +} |
|
| 42 | 43 | |
| 43 | 44 | /** |
| 44 | 45 | * Instantiate bootloader objects and resolve dependencies |
@@ -52,21 +53,25 @@ discard block |
||
| 52 | 53 | { |
| 53 | 54 | $this->checker ??= $this->initDefaultChecker(); |
| 54 | 55 | |
| 55 | - foreach ($classes as $bootloader => $options) { |
|
| 56 | + foreach ($classes as $bootloader => $options) |
|
| 57 | + { |
|
| 56 | 58 | // default bootload syntax as simple array |
| 57 | - if (\is_string($options) || $options instanceof BootloaderInterface) { |
|
| 59 | + if (\is_string($options) || $options instanceof BootloaderInterface) |
|
| 60 | + { |
|
| 58 | 61 | $bootloader = $options; |
| 59 | 62 | $options = []; |
| 60 | 63 | } |
| 61 | 64 | $options = $useConfig ? $this->getBootloadConfig($bootloader, $options) : []; |
| 62 | 65 | |
| 63 | - if (!$this->checker->canInitialize($bootloader, $useConfig ? $options : null)) { |
|
| 66 | + if (!$this->checker->canInitialize($bootloader, $useConfig ? $options : null)) |
|
| 67 | + { |
|
| 64 | 68 | continue; |
| 65 | 69 | } |
| 66 | 70 | |
| 67 | 71 | $this->bootloaders->register($bootloader instanceof BootloaderInterface ? $bootloader::class : $bootloader); |
| 68 | 72 | |
| 69 | - if (!$bootloader instanceof BootloaderInterface) { |
|
| 73 | + if (!$bootloader instanceof BootloaderInterface) |
|
| 74 | + { |
|
| 70 | 75 | $bootloader = $this->container->get($bootloader); |
| 71 | 76 | } |
| 72 | 77 | |
@@ -104,11 +109,13 @@ discard block |
||
| 104 | 109 | */ |
| 105 | 110 | private function initBootloader(BootloaderInterface $bootloader): void |
| 106 | 111 | { |
| 107 | - foreach ($bootloader->defineBindings() as $alias => $resolver) { |
|
| 112 | + foreach ($bootloader->defineBindings() as $alias => $resolver) |
|
| 113 | + { |
|
| 108 | 114 | $this->binder->bind($alias, $resolver); |
| 109 | 115 | } |
| 110 | 116 | |
| 111 | - foreach ($bootloader->defineSingletons() as $alias => $resolver) { |
|
| 117 | + foreach ($bootloader->defineSingletons() as $alias => $resolver) |
|
| 118 | + { |
|
| 112 | 119 | $this->binder->bindSingleton($alias, $resolver); |
| 113 | 120 | } |
| 114 | 121 | |
@@ -153,7 +160,8 @@ discard block |
||
| 153 | 160 | string|BootloaderInterface $bootloader, |
| 154 | 161 | array|callable|BootloadConfig $config, |
| 155 | 162 | ): BootloadConfig { |
| 156 | - if ($config instanceof \Closure) { |
|
| 163 | + if ($config instanceof \Closure) |
|
| 164 | + { |
|
| 157 | 165 | $config = $this->container instanceof ResolverInterface |
| 158 | 166 | ? $config(...$this->container->resolveArguments(new \ReflectionFunction($config))) |
| 159 | 167 | : $config(); |
@@ -189,12 +197,14 @@ discard block |
||
| 189 | 197 | private function getBootloadConfigAttribute(string|BootloaderInterface $bootloader): ?BootloadConfig |
| 190 | 198 | { |
| 191 | 199 | $attribute = null; |
| 192 | - if ($bootloader instanceof BootloaderInterface || \class_exists($bootloader)) { |
|
| 200 | + if ($bootloader instanceof BootloaderInterface || \class_exists($bootloader)) |
|
| 201 | + { |
|
| 193 | 202 | $ref = new \ReflectionClass($bootloader); |
| 194 | 203 | $attribute = $ref->getAttributes(BootloadConfig::class)[0] ?? null; |
| 195 | 204 | } |
| 196 | 205 | |
| 197 | - if ($attribute === null) { |
|
| 206 | + if ($attribute === null) |
|
| 207 | + { |
|
| 198 | 208 | return null; |
| 199 | 209 | } |
| 200 | 210 | |
@@ -216,13 +226,16 @@ discard block |
||
| 216 | 226 | $methods = $initialMethods; |
| 217 | 227 | |
| 218 | 228 | $refl = new \ReflectionClass($bootloader); |
| 219 | - foreach ($refl->getMethods() as $method) { |
|
| 220 | - if ($method->isStatic()) { |
|
| 229 | + foreach ($refl->getMethods() as $method) |
|
| 230 | + { |
|
| 231 | + if ($method->isStatic()) |
|
| 232 | + { |
|
| 221 | 233 | continue; |
| 222 | 234 | } |
| 223 | 235 | |
| 224 | 236 | $attrs = $method->getAttributes($attribute); |
| 225 | - if (\count($attrs) === 0) { |
|
| 237 | + if (\count($attrs) === 0) |
|
| 238 | + { |
|
| 226 | 239 | continue; |
| 227 | 240 | } |
| 228 | 241 | /** @var InitMethod|BootMethod $attr */ |
@@ -242,7 +255,8 @@ discard block |
||
| 242 | 255 | */ |
| 243 | 256 | private function resolveAttributeBindings(BootloaderInterface $bootloader): void |
| 244 | 257 | { |
| 245 | - if (!$this->container->has(AttributeResolver::class)) { |
|
| 258 | + if (!$this->container->has(AttributeResolver::class)) |
|
| 259 | + { |
|
| 246 | 260 | return; |
| 247 | 261 | } |
| 248 | 262 | |
@@ -252,14 +266,18 @@ discard block |
||
| 252 | 266 | $availableAttributes = $attributeResolver->getResolvers(); |
| 253 | 267 | |
| 254 | 268 | $refl = new \ReflectionClass($bootloader); |
| 255 | - foreach ($refl->getMethods() as $method) { |
|
| 256 | - if ($method->isStatic()) { |
|
| 269 | + foreach ($refl->getMethods() as $method) |
|
| 270 | + { |
|
| 271 | + if ($method->isStatic()) |
|
| 272 | + { |
|
| 257 | 273 | continue; |
| 258 | 274 | } |
| 259 | 275 | |
| 260 | - foreach ($availableAttributes as $attributeClass) { |
|
| 276 | + foreach ($availableAttributes as $attributeClass) |
|
| 277 | + { |
|
| 261 | 278 | $attrs = $method->getAttributes($attributeClass); |
| 262 | - foreach ($attrs as $attr) { |
|
| 279 | + foreach ($attrs as $attr) |
|
| 280 | + { |
|
| 263 | 281 | $instance = $attr->newInstance(); |
| 264 | 282 | $attributeResolver->resolve($instance, $bootloader, $method); |
| 265 | 283 | } |
@@ -276,7 +294,8 @@ discard block |
||
| 276 | 294 | private function resolveDependencies(BootloaderInterface $bootloader, array $bootloaderMethods): iterable |
| 277 | 295 | { |
| 278 | 296 | $deps = $this->findDependenciesInMethods($bootloader, $bootloaderMethods); |
| 279 | - if ($bootloader instanceof DependedInterface) { |
|
| 297 | + if ($bootloader instanceof DependedInterface) |
|
| 298 | + { |
|
| 280 | 299 | $deps = [...$deps, ...$bootloader->defineDependencies()]; |
| 281 | 300 | } |
| 282 | 301 | |
@@ -293,8 +312,10 @@ discard block |
||
| 293 | 312 | |
| 294 | 313 | $methodsDeps = []; |
| 295 | 314 | |
| 296 | - foreach ($methods as $method) { |
|
| 297 | - if ($reflectionClass->hasMethod($method)) { |
|
| 315 | + foreach ($methods as $method) |
|
| 316 | + { |
|
| 317 | + if ($reflectionClass->hasMethod($method)) |
|
| 318 | + { |
|
| 298 | 319 | $methodsDeps[] = $this->findBootloaderClassesInMethod( |
| 299 | 320 | $reflectionClass->getMethod($method), |
| 300 | 321 | ); |
@@ -310,9 +331,11 @@ discard block |
||
| 310 | 331 | private function findBootloaderClassesInMethod(\ReflectionMethod $method): array |
| 311 | 332 | { |
| 312 | 333 | $args = []; |
| 313 | - foreach ($method->getParameters() as $parameter) { |
|
| 334 | + foreach ($method->getParameters() as $parameter) |
|
| 335 | + { |
|
| 314 | 336 | $type = $parameter->getType(); |
| 315 | - if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type)) { |
|
| 337 | + if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type)) |
|
| 338 | + { |
|
| 316 | 339 | $args[] = $type->getName(); |
| 317 | 340 | } |
| 318 | 341 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | protected readonly BinderInterface $binder, |
| 39 | 39 | protected readonly ClassesRegistry $bootloaders = new ClassesRegistry(), |
| 40 | 40 | ?BootloaderCheckerInterface $checker = null, |
| 41 | - ) {} |
|
| 41 | + ){} |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Instantiate bootloader objects and resolve dependencies |
@@ -52,21 +52,21 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $this->checker ??= $this->initDefaultChecker(); |
| 54 | 54 | |
| 55 | - foreach ($classes as $bootloader => $options) { |
|
| 55 | + foreach ($classes as $bootloader => $options){ |
|
| 56 | 56 | // default bootload syntax as simple array |
| 57 | - if (\is_string($options) || $options instanceof BootloaderInterface) { |
|
| 57 | + if (\is_string($options) || $options instanceof BootloaderInterface){ |
|
| 58 | 58 | $bootloader = $options; |
| 59 | 59 | $options = []; |
| 60 | 60 | } |
| 61 | 61 | $options = $useConfig ? $this->getBootloadConfig($bootloader, $options) : []; |
| 62 | 62 | |
| 63 | - if (!$this->checker->canInitialize($bootloader, $useConfig ? $options : null)) { |
|
| 63 | + if (!$this->checker->canInitialize($bootloader, $useConfig ? $options : null)){ |
|
| 64 | 64 | continue; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | $this->bootloaders->register($bootloader instanceof BootloaderInterface ? $bootloader::class : $bootloader); |
| 68 | 68 | |
| 69 | - if (!$bootloader instanceof BootloaderInterface) { |
|
| 69 | + if (!$bootloader instanceof BootloaderInterface){ |
|
| 70 | 70 | $bootloader = $this->container->get($bootloader); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * @psalm-pure |
| 113 | 113 | * @psalm-assert-if-true TClass $class |
| 114 | 114 | */ |
| 115 | - protected function isBootloader(string|object $class): bool |
|
| 115 | + protected function isBootloader(string | object $class): bool |
|
| 116 | 116 | { |
| 117 | 117 | return \is_subclass_of($class, BootloaderInterface::class); |
| 118 | 118 | } |
@@ -132,11 +132,11 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | private function initBootloader(BootloaderInterface $bootloader): void |
| 134 | 134 | { |
| 135 | - foreach ($bootloader->defineBindings() as $alias => $resolver) { |
|
| 135 | + foreach ($bootloader->defineBindings() as $alias => $resolver){ |
|
| 136 | 136 | $this->binder->bind($alias, $resolver); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - foreach ($bootloader->defineSingletons() as $alias => $resolver) { |
|
| 139 | + foreach ($bootloader->defineSingletons() as $alias => $resolver){ |
|
| 140 | 140 | $this->binder->bindSingleton($alias, $resolver); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -150,10 +150,10 @@ discard block |
||
| 150 | 150 | * @throws \ReflectionException |
| 151 | 151 | */ |
| 152 | 152 | private function getBootloadConfig( |
| 153 | - string|BootloaderInterface $bootloader, |
|
| 154 | - array|callable|BootloadConfig $config, |
|
| 153 | + string | BootloaderInterface $bootloader, |
|
| 154 | + array | callable | BootloadConfig $config, |
|
| 155 | 155 | ): BootloadConfig { |
| 156 | - if ($config instanceof \Closure) { |
|
| 156 | + if ($config instanceof \Closure){ |
|
| 157 | 157 | $config = $this->container instanceof ResolverInterface |
| 158 | 158 | ? $config(...$this->container->resolveArguments(new \ReflectionFunction($config))) |
| 159 | 159 | : $config(); |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | $getArgument = static fn(string $key, bool $override, mixed $default = []): mixed => match (true) { |
| 165 | 165 | $config instanceof BootloadConfig && $override => $config->{$key}, |
| 166 | 166 | $config instanceof BootloadConfig && !$override && \is_array($default) => |
| 167 | - $config->{$key} + ($attr->{$key} ?? []), |
|
| 167 | + $config->{$key} +($attr->{$key} ?? []), |
|
| 168 | 168 | $config instanceof BootloadConfig && !$override && \is_bool($default) => $config->{$key}, |
| 169 | 169 | \is_array($config) && $config !== [] && $key === 'args' => $config, |
| 170 | 170 | default => $attr->{$key} ?? $default, |
@@ -186,15 +186,15 @@ discard block |
||
| 186 | 186 | * @param class-string<BootloaderInterface>|BootloaderInterface $bootloader |
| 187 | 187 | * @throws \ReflectionException |
| 188 | 188 | */ |
| 189 | - private function getBootloadConfigAttribute(string|BootloaderInterface $bootloader): ?BootloadConfig |
|
| 189 | + private function getBootloadConfigAttribute(string | BootloaderInterface $bootloader): ?BootloadConfig |
|
| 190 | 190 | { |
| 191 | 191 | $attribute = null; |
| 192 | - if ($bootloader instanceof BootloaderInterface || \class_exists($bootloader)) { |
|
| 192 | + if ($bootloader instanceof BootloaderInterface || \class_exists($bootloader)){ |
|
| 193 | 193 | $ref = new \ReflectionClass($bootloader); |
| 194 | 194 | $attribute = $ref->getAttributes(BootloadConfig::class)[0] ?? null; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - if ($attribute === null) { |
|
| 197 | + if ($attribute === null){ |
|
| 198 | 198 | return null; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -216,13 +216,13 @@ discard block |
||
| 216 | 216 | $methods = $initialMethods; |
| 217 | 217 | |
| 218 | 218 | $refl = new \ReflectionClass($bootloader); |
| 219 | - foreach ($refl->getMethods() as $method) { |
|
| 220 | - if ($method->isStatic()) { |
|
| 219 | + foreach ($refl->getMethods() as $method){ |
|
| 220 | + if ($method->isStatic()){ |
|
| 221 | 221 | continue; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | $attrs = $method->getAttributes($attribute); |
| 225 | - if (\count($attrs) === 0) { |
|
| 225 | + if (\count($attrs) === 0){ |
|
| 226 | 226 | continue; |
| 227 | 227 | } |
| 228 | 228 | /** @var InitMethod|BootMethod $attr */ |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | private function resolveAttributeBindings(BootloaderInterface $bootloader): void |
| 244 | 244 | { |
| 245 | - if (!$this->container->has(AttributeResolver::class)) { |
|
| 245 | + if (!$this->container->has(AttributeResolver::class)){ |
|
| 246 | 246 | return; |
| 247 | 247 | } |
| 248 | 248 | |
@@ -252,14 +252,14 @@ discard block |
||
| 252 | 252 | $availableAttributes = $attributeResolver->getResolvers(); |
| 253 | 253 | |
| 254 | 254 | $refl = new \ReflectionClass($bootloader); |
| 255 | - foreach ($refl->getMethods() as $method) { |
|
| 256 | - if ($method->isStatic()) { |
|
| 255 | + foreach ($refl->getMethods() as $method){ |
|
| 256 | + if ($method->isStatic()){ |
|
| 257 | 257 | continue; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - foreach ($availableAttributes as $attributeClass) { |
|
| 260 | + foreach ($availableAttributes as $attributeClass){ |
|
| 261 | 261 | $attrs = $method->getAttributes($attributeClass); |
| 262 | - foreach ($attrs as $attr) { |
|
| 262 | + foreach ($attrs as $attr){ |
|
| 263 | 263 | $instance = $attr->newInstance(); |
| 264 | 264 | $attributeResolver->resolve($instance, $bootloader, $method); |
| 265 | 265 | } |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | private function resolveDependencies(BootloaderInterface $bootloader, array $bootloaderMethods): iterable |
| 277 | 277 | { |
| 278 | 278 | $deps = $this->findDependenciesInMethods($bootloader, $bootloaderMethods); |
| 279 | - if ($bootloader instanceof DependedInterface) { |
|
| 279 | + if ($bootloader instanceof DependedInterface){ |
|
| 280 | 280 | $deps = [...$deps, ...$bootloader->defineDependencies()]; |
| 281 | 281 | } |
| 282 | 282 | |
@@ -293,8 +293,8 @@ discard block |
||
| 293 | 293 | |
| 294 | 294 | $methodsDeps = []; |
| 295 | 295 | |
| 296 | - foreach ($methods as $method) { |
|
| 297 | - if ($reflectionClass->hasMethod($method)) { |
|
| 296 | + foreach ($methods as $method){ |
|
| 297 | + if ($reflectionClass->hasMethod($method)){ |
|
| 298 | 298 | $methodsDeps[] = $this->findBootloaderClassesInMethod( |
| 299 | 299 | $reflectionClass->getMethod($method), |
| 300 | 300 | ); |
@@ -310,9 +310,9 @@ discard block |
||
| 310 | 310 | private function findBootloaderClassesInMethod(\ReflectionMethod $method): array |
| 311 | 311 | { |
| 312 | 312 | $args = []; |
| 313 | - foreach ($method->getParameters() as $parameter) { |
|
| 313 | + foreach ($method->getParameters() as $parameter){ |
|
| 314 | 314 | $type = $parameter->getType(); |
| 315 | - if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type)) { |
|
| 315 | + if ($type instanceof \ReflectionNamedType && $this->shouldBeBooted($type)){ |
|
| 316 | 316 | $args[] = $type->getName(); |
| 317 | 317 | } |
| 318 | 318 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | public function __construct( |
| 21 | 21 | private readonly BinderInterface $binder, |
| 22 | 22 | private readonly InvokerInterface $invoker, |
| 23 | - ) {} |
|
| 23 | + ){} |
|
| 24 | 24 | |
| 25 | 25 | public function resolve(object $attribute, object $service, \ReflectionMethod $method): void |
| 26 | 26 | { |
@@ -20,7 +20,8 @@ |
||
| 20 | 20 | public function __construct( |
| 21 | 21 | private readonly BinderInterface $binder, |
| 22 | 22 | private readonly InvokerInterface $invoker, |
| 23 | - ) {} |
|
| 23 | + ) { |
|
| 24 | +} |
|
| 24 | 25 | |
| 25 | 26 | public function resolve(object $attribute, object $service, \ReflectionMethod $method): void |
| 26 | 27 | { |
@@ -19,5 +19,5 @@ |
||
| 19 | 19 | * Add aliases from the return type of the method even if the method has an alias. |
| 20 | 20 | */ |
| 21 | 21 | public readonly bool $aliasesFromReturnType = false, |
| 22 | - ) {} |
|
| 22 | + ){} |
|
| 23 | 23 | } |
@@ -19,5 +19,6 @@ |
||
| 19 | 19 | * Add aliases from the return type of the method even if the method has an alias. |
| 20 | 20 | */ |
| 21 | 21 | public readonly bool $aliasesFromReturnType = false, |
| 22 | - ) {} |
|
| 22 | + ) { |
|
| 23 | +} |
|
| 23 | 24 | } |
@@ -4,4 +4,4 @@ |
||
| 4 | 4 | |
| 5 | 5 | namespace Spiral\Tests\Boot\Fixtures; |
| 6 | 6 | |
| 7 | -class SampleClass implements SampleClassInterface {} |
|
| 7 | +class SampleClass implements SampleClassInterface{} |
|
@@ -4,4 +4,6 @@ |
||
| 4 | 4 | |
| 5 | 5 | namespace Spiral\Tests\Boot\Fixtures; |
| 6 | 6 | |
| 7 | -class SampleClass implements SampleClassInterface {} |
|
| 7 | +class SampleClass implements SampleClassInterface |
|
| 8 | +{ |
|
| 9 | +} |
|
@@ -5,4 +5,4 @@ |
||
| 5 | 5 | namespace Spiral\Tests\Boot\Fixtures\Attribute; |
| 6 | 6 | |
| 7 | 7 | #[\Attribute(\Attribute::TARGET_METHOD)] |
| 8 | -final class SampleMethod extends \Spiral\Boot\Attribute\AbstractMethod {} |
|
| 8 | +final class SampleMethod extends \Spiral\Boot\Attribute\AbstractMethod{} |
|
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | private readonly InitializerInterface $initializer, |
| 15 | 15 | private readonly InvokerInterface $invoker, |
| 16 | 16 | private readonly ResolverInterface $resolver, |
| 17 | - ) {} |
|
| 17 | + ){} |
|
| 18 | 18 | |
| 19 | 19 | public function invokeBootloaders( |
| 20 | 20 | array $classes, |
@@ -25,16 +25,16 @@ discard block |
||
| 25 | 25 | /** @psalm-suppress TooManyArguments */ |
| 26 | 26 | $bootloaders = \iterator_to_array($this->initializer->init($classes, $useConfig)); |
| 27 | 27 | |
| 28 | - foreach ($bootloaders as $data) { |
|
| 29 | - foreach ($data['init_methods'] as $methodName) { |
|
| 28 | + foreach ($bootloaders as $data){ |
|
| 29 | + foreach ($data['init_methods'] as $methodName){ |
|
| 30 | 30 | $this->invokeBootloader($data['bootloader'], $methodName, $data['options']); |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $this->fireCallbacks($bootingCallbacks); |
| 35 | 35 | |
| 36 | - foreach ($bootloaders as $data) { |
|
| 37 | - foreach ($data['boot_methods'] as $methodName) { |
|
| 36 | + foreach ($bootloaders as $data){ |
|
| 37 | + foreach ($data['boot_methods'] as $methodName){ |
|
| 38 | 38 | $this->invokeBootloader($data['bootloader'], $methodName, $data['options']); |
| 39 | 39 | } |
| 40 | 40 | } |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | private function invokeBootloader(BootloaderInterface $bootloader, string $method, array $options): void |
| 46 | 46 | { |
| 47 | 47 | $refl = new \ReflectionClass($bootloader); |
| 48 | - if (!$refl->hasMethod($method)) { |
|
| 48 | + if (!$refl->hasMethod($method)){ |
|
| 49 | 49 | return; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $method = $refl->getMethod($method); |
| 53 | 53 | |
| 54 | 54 | $args = $this->resolver->resolveArguments($method); |
| 55 | - if (!isset($args['boot'])) { |
|
| 55 | + if (!isset($args['boot'])){ |
|
| 56 | 56 | $args['boot'] = $options; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | private function fireCallbacks(array $callbacks): void |
| 66 | 66 | { |
| 67 | - foreach ($callbacks as $callback) { |
|
| 67 | + foreach ($callbacks as $callback){ |
|
| 68 | 68 | $this->invoker->invoke($callback); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -14,7 +14,8 @@ discard block |
||
| 14 | 14 | private readonly InitializerInterface $initializer, |
| 15 | 15 | private readonly InvokerInterface $invoker, |
| 16 | 16 | private readonly ResolverInterface $resolver, |
| 17 | - ) {} |
|
| 17 | + ) { |
|
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | public function invokeBootloaders( |
| 20 | 21 | array $classes, |
@@ -25,16 +26,20 @@ discard block |
||
| 25 | 26 | /** @psalm-suppress TooManyArguments */ |
| 26 | 27 | $bootloaders = \iterator_to_array($this->initializer->init($classes, $useConfig)); |
| 27 | 28 | |
| 28 | - foreach ($bootloaders as $data) { |
|
| 29 | - foreach ($data['init_methods'] as $methodName) { |
|
| 29 | + foreach ($bootloaders as $data) |
|
| 30 | + { |
|
| 31 | + foreach ($data['init_methods'] as $methodName) |
|
| 32 | + { |
|
| 30 | 33 | $this->invokeBootloader($data['bootloader'], $methodName, $data['options']); |
| 31 | 34 | } |
| 32 | 35 | } |
| 33 | 36 | |
| 34 | 37 | $this->fireCallbacks($bootingCallbacks); |
| 35 | 38 | |
| 36 | - foreach ($bootloaders as $data) { |
|
| 37 | - foreach ($data['boot_methods'] as $methodName) { |
|
| 39 | + foreach ($bootloaders as $data) |
|
| 40 | + { |
|
| 41 | + foreach ($data['boot_methods'] as $methodName) |
|
| 42 | + { |
|
| 38 | 43 | $this->invokeBootloader($data['bootloader'], $methodName, $data['options']); |
| 39 | 44 | } |
| 40 | 45 | } |
@@ -45,14 +50,16 @@ discard block |
||
| 45 | 50 | private function invokeBootloader(BootloaderInterface $bootloader, string $method, array $options): void |
| 46 | 51 | { |
| 47 | 52 | $refl = new \ReflectionClass($bootloader); |
| 48 | - if (!$refl->hasMethod($method)) { |
|
| 53 | + if (!$refl->hasMethod($method)) |
|
| 54 | + { |
|
| 49 | 55 | return; |
| 50 | 56 | } |
| 51 | 57 | |
| 52 | 58 | $method = $refl->getMethod($method); |
| 53 | 59 | |
| 54 | 60 | $args = $this->resolver->resolveArguments($method); |
| 55 | - if (!isset($args['boot'])) { |
|
| 61 | + if (!isset($args['boot'])) |
|
| 62 | + { |
|
| 56 | 63 | $args['boot'] = $options; |
| 57 | 64 | } |
| 58 | 65 | |
@@ -64,7 +71,8 @@ discard block |
||
| 64 | 71 | */ |
| 65 | 72 | private function fireCallbacks(array $callbacks): void |
| 66 | 73 | { |
| 67 | - foreach ($callbacks as $callback) { |
|
| 74 | + foreach ($callbacks as $callback) |
|
| 75 | + { |
|
| 68 | 76 | $this->invoker->invoke($callback); |
| 69 | 77 | } |
| 70 | 78 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | protected readonly ExceptionHandlerInterface $exceptionHandler, |
| 79 | 79 | protected readonly BootloadManagerInterface $bootloader, |
| 80 | 80 | array $directories, |
| 81 | - ) { |
|
| 81 | + ){ |
|
| 82 | 82 | $container->bindSingleton(ExceptionHandlerInterface::class, $exceptionHandler); |
| 83 | 83 | $container->bindSingleton(ExceptionRendererInterface::class, $exceptionHandler); |
| 84 | 84 | $container->bindSingleton(ExceptionReporterInterface::class, $exceptionHandler); |
@@ -107,38 +107,38 @@ discard block |
||
| 107 | 107 | final public static function create( |
| 108 | 108 | array $directories, |
| 109 | 109 | bool $handleErrors = true, |
| 110 | - ExceptionHandlerInterface|string|null $exceptionHandler = null, |
|
| 110 | + ExceptionHandlerInterface | string | null $exceptionHandler = null, |
|
| 111 | 111 | Container $container = new Container(), |
| 112 | - BootloadManagerInterface|Autowire|null $bootloadManager = null, |
|
| 112 | + BootloadManagerInterface | Autowire | null $bootloadManager = null, |
|
| 113 | 113 | ): static { |
| 114 | 114 | $exceptionHandler ??= ExceptionHandler::class; |
| 115 | 115 | |
| 116 | - if (\is_string($exceptionHandler)) { |
|
| 116 | + if (\is_string($exceptionHandler)){ |
|
| 117 | 117 | $exceptionHandler = $container->make($exceptionHandler); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if ($handleErrors) { |
|
| 120 | + if ($handleErrors){ |
|
| 121 | 121 | $exceptionHandler->register(); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | $container->bind(AttributeResolverRegistryInterface::class, AttributeResolver::class); |
| 125 | 125 | |
| 126 | - if (!$container->has(InitializerInterface::class)) { |
|
| 126 | + if (!$container->has(InitializerInterface::class)){ |
|
| 127 | 127 | $container->bind(InitializerInterface::class, Initializer::class); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - if (!$container->has(InvokerStrategyInterface::class)) { |
|
| 130 | + if (!$container->has(InvokerStrategyInterface::class)){ |
|
| 131 | 131 | $container->bind(InvokerStrategyInterface::class, DefaultInvokerStrategy::class); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - if ($bootloadManager instanceof Autowire) { |
|
| 134 | + if ($bootloadManager instanceof Autowire){ |
|
| 135 | 135 | $bootloadManager = $bootloadManager->resolve($container); |
| 136 | 136 | } |
| 137 | 137 | $bootloadManager ??= $container->make(StrategyBasedBootloadManager::class); |
| 138 | 138 | \assert($bootloadManager instanceof BootloadManagerInterface); |
| 139 | 139 | $container->bind(BootloadManagerInterface::class, $bootloadManager); |
| 140 | 140 | |
| 141 | - if (!$container->has(BootloaderRegistryInterface::class)) { |
|
| 141 | + if (!$container->has(BootloaderRegistryInterface::class)){ |
|
| 142 | 142 | /** @psalm-suppress InvalidArgument */ |
| 143 | 143 | $container->bindSingleton(BootloaderRegistryInterface::class, [self::class, 'initBootloaderRegistry']); |
| 144 | 144 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | $environment ??= new Environment(); |
| 168 | 168 | $this->container->bindSingleton(EnvironmentInterface::class, $environment); |
| 169 | 169 | |
| 170 | - try { |
|
| 170 | + try{ |
|
| 171 | 171 | // will protect any against env overwrite action |
| 172 | 172 | $this->container->runScope( |
| 173 | 173 | [EnvironmentInterface::class => $environment], |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | $this->fireCallbacks($this->bootstrappedCallbacks); |
| 185 | 185 | }, |
| 186 | 186 | ); |
| 187 | - } catch (\Throwable $e) { |
|
| 187 | + }catch (\Throwable $e){ |
|
| 188 | 188 | $this->exceptionHandler->handleGlobalException($e); |
| 189 | 189 | |
| 190 | 190 | return null; |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | public function running(\Closure ...$callbacks): void |
| 207 | 207 | { |
| 208 | - foreach ($callbacks as $callback) { |
|
| 208 | + foreach ($callbacks as $callback){ |
|
| 209 | 209 | $this->runningCallbacks[] = $callback; |
| 210 | 210 | } |
| 211 | 211 | } |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | public function booting(\Closure ...$callbacks): void |
| 222 | 222 | { |
| 223 | - foreach ($callbacks as $callback) { |
|
| 223 | + foreach ($callbacks as $callback){ |
|
| 224 | 224 | $this->bootingCallbacks[] = $callback; |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | public function booted(\Closure ...$callbacks): void |
| 237 | 237 | { |
| 238 | - foreach ($callbacks as $callback) { |
|
| 238 | + foreach ($callbacks as $callback){ |
|
| 239 | 239 | $this->bootedCallbacks[] = $callback; |
| 240 | 240 | } |
| 241 | 241 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | public function bootstrapped(\Closure ...$callbacks): void |
| 252 | 252 | { |
| 253 | - foreach ($callbacks as $callback) { |
|
| 253 | + foreach ($callbacks as $callback){ |
|
| 254 | 254 | $this->bootstrappedCallbacks[] = $callback; |
| 255 | 255 | } |
| 256 | 256 | } |
@@ -262,9 +262,9 @@ discard block |
||
| 262 | 262 | * @param class-string<DispatcherInterface>|DispatcherInterface $dispatcher The class name or instance |
| 263 | 263 | * of the dispatcher. Since v4.0, it will only accept the class name. |
| 264 | 264 | */ |
| 265 | - public function addDispatcher(string|DispatcherInterface $dispatcher): self |
|
| 265 | + public function addDispatcher(string | DispatcherInterface $dispatcher): self |
|
| 266 | 266 | { |
| 267 | - if (\is_object($dispatcher)) { |
|
| 267 | + if (\is_object($dispatcher)){ |
|
| 268 | 268 | $dispatcher = $dispatcher::class; |
| 269 | 269 | } |
| 270 | 270 | |
@@ -286,19 +286,19 @@ discard block |
||
| 286 | 286 | $eventDispatcher?->dispatch(new Serving()); |
| 287 | 287 | |
| 288 | 288 | $serving = $servingScope = null; |
| 289 | - foreach ($this->dispatchers as $dispatcher) { |
|
| 289 | + foreach ($this->dispatchers as $dispatcher){ |
|
| 290 | 290 | $reflection = new \ReflectionClass($dispatcher); |
| 291 | 291 | |
| 292 | 292 | $scope = ($reflection->getAttributes(DispatcherScope::class)[0] ?? null)?->newInstance()->scope; |
| 293 | 293 | $this->container->getBinder($scope)->bind($dispatcher, $dispatcher); |
| 294 | 294 | |
| 295 | - if ($serving === null && $this->canServe($reflection)) { |
|
| 295 | + if ($serving === null && $this->canServe($reflection)){ |
|
| 296 | 296 | $serving = $dispatcher; |
| 297 | 297 | $servingScope = $scope; |
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if ($serving === null) { |
|
| 301 | + if ($serving === null){ |
|
| 302 | 302 | $eventDispatcher?->dispatch(new DispatcherNotFound()); |
| 303 | 303 | throw new BootException('Unable to locate active dispatcher.'); |
| 304 | 304 | } |
@@ -355,13 +355,13 @@ discard block |
||
| 355 | 355 | */ |
| 356 | 356 | protected function fireCallbacks(array &$callbacks): void |
| 357 | 357 | { |
| 358 | - if ($callbacks === []) { |
|
| 358 | + if ($callbacks === []){ |
|
| 359 | 359 | return; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - do { |
|
| 362 | + do{ |
|
| 363 | 363 | $this->container->invoke(\current($callbacks)); |
| 364 | - } while (\next($callbacks)); |
|
| 364 | + }while (\next($callbacks)); |
|
| 365 | 365 | |
| 366 | 366 | $callbacks = []; |
| 367 | 367 | } |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | */ |
| 402 | 402 | private function canServe(\ReflectionClass $reflection): bool |
| 403 | 403 | { |
| 404 | - if (!$reflection->hasMethod('canServe')) { |
|
| 404 | + if (!$reflection->hasMethod('canServe')){ |
|
| 405 | 405 | throw new BootException('Dispatcher must implement static `canServe` method.'); |
| 406 | 406 | } |
| 407 | 407 | |
@@ -113,32 +113,38 @@ discard block |
||
| 113 | 113 | ): static { |
| 114 | 114 | $exceptionHandler ??= ExceptionHandler::class; |
| 115 | 115 | |
| 116 | - if (\is_string($exceptionHandler)) { |
|
| 116 | + if (\is_string($exceptionHandler)) |
|
| 117 | + { |
|
| 117 | 118 | $exceptionHandler = $container->make($exceptionHandler); |
| 118 | 119 | } |
| 119 | 120 | |
| 120 | - if ($handleErrors) { |
|
| 121 | + if ($handleErrors) |
|
| 122 | + { |
|
| 121 | 123 | $exceptionHandler->register(); |
| 122 | 124 | } |
| 123 | 125 | |
| 124 | 126 | $container->bind(AttributeResolverRegistryInterface::class, AttributeResolver::class); |
| 125 | 127 | |
| 126 | - if (!$container->has(InitializerInterface::class)) { |
|
| 128 | + if (!$container->has(InitializerInterface::class)) |
|
| 129 | + { |
|
| 127 | 130 | $container->bind(InitializerInterface::class, Initializer::class); |
| 128 | 131 | } |
| 129 | 132 | |
| 130 | - if (!$container->has(InvokerStrategyInterface::class)) { |
|
| 133 | + if (!$container->has(InvokerStrategyInterface::class)) |
|
| 134 | + { |
|
| 131 | 135 | $container->bind(InvokerStrategyInterface::class, DefaultInvokerStrategy::class); |
| 132 | 136 | } |
| 133 | 137 | |
| 134 | - if ($bootloadManager instanceof Autowire) { |
|
| 138 | + if ($bootloadManager instanceof Autowire) |
|
| 139 | + { |
|
| 135 | 140 | $bootloadManager = $bootloadManager->resolve($container); |
| 136 | 141 | } |
| 137 | 142 | $bootloadManager ??= $container->make(StrategyBasedBootloadManager::class); |
| 138 | 143 | \assert($bootloadManager instanceof BootloadManagerInterface); |
| 139 | 144 | $container->bind(BootloadManagerInterface::class, $bootloadManager); |
| 140 | 145 | |
| 141 | - if (!$container->has(BootloaderRegistryInterface::class)) { |
|
| 146 | + if (!$container->has(BootloaderRegistryInterface::class)) |
|
| 147 | + { |
|
| 142 | 148 | /** @psalm-suppress InvalidArgument */ |
| 143 | 149 | $container->bindSingleton(BootloaderRegistryInterface::class, [self::class, 'initBootloaderRegistry']); |
| 144 | 150 | } |
@@ -167,7 +173,8 @@ discard block |
||
| 167 | 173 | $environment ??= new Environment(); |
| 168 | 174 | $this->container->bindSingleton(EnvironmentInterface::class, $environment); |
| 169 | 175 | |
| 170 | - try { |
|
| 176 | + try |
|
| 177 | + { |
|
| 171 | 178 | // will protect any against env overwrite action |
| 172 | 179 | $this->container->runScope( |
| 173 | 180 | [EnvironmentInterface::class => $environment], |
@@ -184,7 +191,9 @@ discard block |
||
| 184 | 191 | $this->fireCallbacks($this->bootstrappedCallbacks); |
| 185 | 192 | }, |
| 186 | 193 | ); |
| 187 | - } catch (\Throwable $e) { |
|
| 194 | + } |
|
| 195 | + catch (\Throwable $e) |
|
| 196 | + { |
|
| 188 | 197 | $this->exceptionHandler->handleGlobalException($e); |
| 189 | 198 | |
| 190 | 199 | return null; |
@@ -205,7 +214,8 @@ discard block |
||
| 205 | 214 | */ |
| 206 | 215 | public function running(\Closure ...$callbacks): void |
| 207 | 216 | { |
| 208 | - foreach ($callbacks as $callback) { |
|
| 217 | + foreach ($callbacks as $callback) |
|
| 218 | + { |
|
| 209 | 219 | $this->runningCallbacks[] = $callback; |
| 210 | 220 | } |
| 211 | 221 | } |
@@ -220,7 +230,8 @@ discard block |
||
| 220 | 230 | */ |
| 221 | 231 | public function booting(\Closure ...$callbacks): void |
| 222 | 232 | { |
| 223 | - foreach ($callbacks as $callback) { |
|
| 233 | + foreach ($callbacks as $callback) |
|
| 234 | + { |
|
| 224 | 235 | $this->bootingCallbacks[] = $callback; |
| 225 | 236 | } |
| 226 | 237 | } |
@@ -235,7 +246,8 @@ discard block |
||
| 235 | 246 | */ |
| 236 | 247 | public function booted(\Closure ...$callbacks): void |
| 237 | 248 | { |
| 238 | - foreach ($callbacks as $callback) { |
|
| 249 | + foreach ($callbacks as $callback) |
|
| 250 | + { |
|
| 239 | 251 | $this->bootedCallbacks[] = $callback; |
| 240 | 252 | } |
| 241 | 253 | } |
@@ -250,7 +262,8 @@ discard block |
||
| 250 | 262 | */ |
| 251 | 263 | public function bootstrapped(\Closure ...$callbacks): void |
| 252 | 264 | { |
| 253 | - foreach ($callbacks as $callback) { |
|
| 265 | + foreach ($callbacks as $callback) |
|
| 266 | + { |
|
| 254 | 267 | $this->bootstrappedCallbacks[] = $callback; |
| 255 | 268 | } |
| 256 | 269 | } |
@@ -264,7 +277,8 @@ discard block |
||
| 264 | 277 | */ |
| 265 | 278 | public function addDispatcher(string|DispatcherInterface $dispatcher): self |
| 266 | 279 | { |
| 267 | - if (\is_object($dispatcher)) { |
|
| 280 | + if (\is_object($dispatcher)) |
|
| 281 | + { |
|
| 268 | 282 | $dispatcher = $dispatcher::class; |
| 269 | 283 | } |
| 270 | 284 | |
@@ -286,19 +300,22 @@ discard block |
||
| 286 | 300 | $eventDispatcher?->dispatch(new Serving()); |
| 287 | 301 | |
| 288 | 302 | $serving = $servingScope = null; |
| 289 | - foreach ($this->dispatchers as $dispatcher) { |
|
| 303 | + foreach ($this->dispatchers as $dispatcher) |
|
| 304 | + { |
|
| 290 | 305 | $reflection = new \ReflectionClass($dispatcher); |
| 291 | 306 | |
| 292 | 307 | $scope = ($reflection->getAttributes(DispatcherScope::class)[0] ?? null)?->newInstance()->scope; |
| 293 | 308 | $this->container->getBinder($scope)->bind($dispatcher, $dispatcher); |
| 294 | 309 | |
| 295 | - if ($serving === null && $this->canServe($reflection)) { |
|
| 310 | + if ($serving === null && $this->canServe($reflection)) |
|
| 311 | + { |
|
| 296 | 312 | $serving = $dispatcher; |
| 297 | 313 | $servingScope = $scope; |
| 298 | 314 | } |
| 299 | 315 | } |
| 300 | 316 | |
| 301 | - if ($serving === null) { |
|
| 317 | + if ($serving === null) |
|
| 318 | + { |
|
| 302 | 319 | $eventDispatcher?->dispatch(new DispatcherNotFound()); |
| 303 | 320 | throw new BootException('Unable to locate active dispatcher.'); |
| 304 | 321 | } |
@@ -355,11 +372,13 @@ discard block |
||
| 355 | 372 | */ |
| 356 | 373 | protected function fireCallbacks(array &$callbacks): void |
| 357 | 374 | { |
| 358 | - if ($callbacks === []) { |
|
| 375 | + if ($callbacks === []) |
|
| 376 | + { |
|
| 359 | 377 | return; |
| 360 | 378 | } |
| 361 | 379 | |
| 362 | - do { |
|
| 380 | + do |
|
| 381 | + { |
|
| 363 | 382 | $this->container->invoke(\current($callbacks)); |
| 364 | 383 | } while (\next($callbacks)); |
| 365 | 384 | |
@@ -401,7 +420,8 @@ discard block |
||
| 401 | 420 | */ |
| 402 | 421 | private function canServe(\ReflectionClass $reflection): bool |
| 403 | 422 | { |
| 404 | - if (!$reflection->hasMethod('canServe')) { |
|
| 423 | + if (!$reflection->hasMethod('canServe')) |
|
| 424 | + { |
|
| 405 | 425 | throw new BootException('Dispatcher must implement static `canServe` method.'); |
| 406 | 426 | } |
| 407 | 427 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | public function __construct( |
| 24 | 24 | protected readonly BinderInterface $binder, |
| 25 | - ) {} |
|
| 25 | + ){} |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * @psalm-param T $attribute |
@@ -33,35 +33,35 @@ discard block |
||
| 33 | 33 | $alias = $attribute->alias ?? null; |
| 34 | 34 | |
| 35 | 35 | $aliases = []; |
| 36 | - if ($alias !== null) { |
|
| 36 | + if ($alias !== null){ |
|
| 37 | 37 | $aliases[] = $alias; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $attrs = $method->getAttributes(name: BindAlias::class); |
| 41 | - foreach ($attrs as $attr) { |
|
| 41 | + foreach ($attrs as $attr){ |
|
| 42 | 42 | $aliases = [...$aliases, ...$attr->newInstance()->aliases]; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | // If no aliases are provided, we will use the return type as the alias. |
| 46 | - if (\count($aliases) > 0 && !$attribute->aliasesFromReturnType) { |
|
| 46 | + if (\count($aliases) > 0 && !$attribute->aliasesFromReturnType){ |
|
| 47 | 47 | return \array_unique(\array_filter($aliases)); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | $type = $method->getReturnType(); |
| 51 | 51 | |
| 52 | - if ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType) { |
|
| 53 | - foreach ($type->getTypes() as $type) { |
|
| 54 | - if ($type->isBuiltin()) { |
|
| 52 | + if ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType){ |
|
| 53 | + foreach ($type->getTypes() as $type){ |
|
| 54 | + if ($type->isBuiltin()){ |
|
| 55 | 55 | continue; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | $aliases[] = $type->getName(); |
| 59 | 59 | } |
| 60 | - } elseif ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) { |
|
| 60 | + } elseif ($type instanceof \ReflectionNamedType && !$type->isBuiltin()){ |
|
| 61 | 61 | $aliases[] = $type->getName(); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if ($aliases === []) { |
|
| 64 | + if ($aliases === []){ |
|
| 65 | 65 | throw new \LogicException( |
| 66 | 66 | "No alias provided for binding {$method->getDeclaringClass()->getName()}::{$method->getName()}", |
| 67 | 67 | ); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | { |
| 75 | 75 | $attrs = $method->getAttributes(name: BindScope::class); |
| 76 | 76 | |
| 77 | - if ($attrs === []) { |
|
| 77 | + if ($attrs === []){ |
|
| 78 | 78 | return []; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -87,17 +87,17 @@ discard block |
||
| 87 | 87 | protected function bind(array $aliases, Binding $binding, array $scopes): void |
| 88 | 88 | { |
| 89 | 89 | $binders = []; |
| 90 | - foreach ($scopes as $scope) { |
|
| 90 | + foreach ($scopes as $scope){ |
|
| 91 | 91 | $binders[] = $this->binder->getBinder($scope); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if ($binders === []) { |
|
| 94 | + if ($binders === []){ |
|
| 95 | 95 | $binders[] = $this->binder; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - foreach ($binders as $binder) { |
|
| 98 | + foreach ($binders as $binder){ |
|
| 99 | 99 | $alias = \array_shift($aliases); |
| 100 | - foreach ($aliases as $a) { |
|
| 100 | + foreach ($aliases as $a){ |
|
| 101 | 101 | $binder->bind($alias, $a); |
| 102 | 102 | $alias = \array_shift($aliases); |
| 103 | 103 | } |
@@ -22,7 +22,8 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | public function __construct( |
| 24 | 24 | protected readonly BinderInterface $binder, |
| 25 | - ) {} |
|
| 25 | + ) { |
|
| 26 | +} |
|
| 26 | 27 | |
| 27 | 28 | /** |
| 28 | 29 | * @psalm-param T $attribute |
@@ -33,35 +34,44 @@ discard block |
||
| 33 | 34 | $alias = $attribute->alias ?? null; |
| 34 | 35 | |
| 35 | 36 | $aliases = []; |
| 36 | - if ($alias !== null) { |
|
| 37 | + if ($alias !== null) |
|
| 38 | + { |
|
| 37 | 39 | $aliases[] = $alias; |
| 38 | 40 | } |
| 39 | 41 | |
| 40 | 42 | $attrs = $method->getAttributes(name: BindAlias::class); |
| 41 | - foreach ($attrs as $attr) { |
|
| 43 | + foreach ($attrs as $attr) |
|
| 44 | + { |
|
| 42 | 45 | $aliases = [...$aliases, ...$attr->newInstance()->aliases]; |
| 43 | 46 | } |
| 44 | 47 | |
| 45 | 48 | // If no aliases are provided, we will use the return type as the alias. |
| 46 | - if (\count($aliases) > 0 && !$attribute->aliasesFromReturnType) { |
|
| 49 | + if (\count($aliases) > 0 && !$attribute->aliasesFromReturnType) |
|
| 50 | + { |
|
| 47 | 51 | return \array_unique(\array_filter($aliases)); |
| 48 | 52 | } |
| 49 | 53 | |
| 50 | 54 | $type = $method->getReturnType(); |
| 51 | 55 | |
| 52 | - if ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType) { |
|
| 53 | - foreach ($type->getTypes() as $type) { |
|
| 54 | - if ($type->isBuiltin()) { |
|
| 56 | + if ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType) |
|
| 57 | + { |
|
| 58 | + foreach ($type->getTypes() as $type) |
|
| 59 | + { |
|
| 60 | + if ($type->isBuiltin()) |
|
| 61 | + { |
|
| 55 | 62 | continue; |
| 56 | 63 | } |
| 57 | 64 | |
| 58 | 65 | $aliases[] = $type->getName(); |
| 59 | 66 | } |
| 60 | - } elseif ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) { |
|
| 67 | + } |
|
| 68 | + elseif ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) |
|
| 69 | + { |
|
| 61 | 70 | $aliases[] = $type->getName(); |
| 62 | 71 | } |
| 63 | 72 | |
| 64 | - if ($aliases === []) { |
|
| 73 | + if ($aliases === []) |
|
| 74 | + { |
|
| 65 | 75 | throw new \LogicException( |
| 66 | 76 | "No alias provided for binding {$method->getDeclaringClass()->getName()}::{$method->getName()}", |
| 67 | 77 | ); |
@@ -74,7 +84,8 @@ discard block |
||
| 74 | 84 | { |
| 75 | 85 | $attrs = $method->getAttributes(name: BindScope::class); |
| 76 | 86 | |
| 77 | - if ($attrs === []) { |
|
| 87 | + if ($attrs === []) |
|
| 88 | + { |
|
| 78 | 89 | return []; |
| 79 | 90 | } |
| 80 | 91 | |
@@ -87,17 +98,21 @@ discard block |
||
| 87 | 98 | protected function bind(array $aliases, Binding $binding, array $scopes): void |
| 88 | 99 | { |
| 89 | 100 | $binders = []; |
| 90 | - foreach ($scopes as $scope) { |
|
| 101 | + foreach ($scopes as $scope) |
|
| 102 | + { |
|
| 91 | 103 | $binders[] = $this->binder->getBinder($scope); |
| 92 | 104 | } |
| 93 | 105 | |
| 94 | - if ($binders === []) { |
|
| 106 | + if ($binders === []) |
|
| 107 | + { |
|
| 95 | 108 | $binders[] = $this->binder; |
| 96 | 109 | } |
| 97 | 110 | |
| 98 | - foreach ($binders as $binder) { |
|
| 111 | + foreach ($binders as $binder) |
|
| 112 | + { |
|
| 99 | 113 | $alias = \array_shift($aliases); |
| 100 | - foreach ($aliases as $a) { |
|
| 114 | + foreach ($aliases as $a) |
|
| 115 | + { |
|
| 101 | 116 | $binder->bind($alias, $a); |
| 102 | 117 | $alias = \array_shift($aliases); |
| 103 | 118 | } |