@@ -47,9 +47,12 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | public function getRenderer(?string $format = null): ?ExceptionRendererInterface |
| 49 | 49 | { |
| 50 | - if ($format !== null) { |
|
| 51 | - foreach ($this->renderers as $renderer) { |
|
| 52 | - if ($renderer->canRender($format)) { |
|
| 50 | + if ($format !== null) |
|
| 51 | + { |
|
| 52 | + foreach ($this->renderers as $renderer) |
|
| 53 | + { |
|
| 54 | + if ($renderer->canRender($format)) |
|
| 55 | + { |
|
| 53 | 56 | return $renderer; |
| 54 | 57 | } |
| 55 | 58 | } |
@@ -72,18 +75,26 @@ discard block |
||
| 72 | 75 | |
| 73 | 76 | public function report(\Throwable $exception): void |
| 74 | 77 | { |
| 75 | - if ($this->shouldNotReport($exception)) { |
|
| 78 | + if ($this->shouldNotReport($exception)) |
|
| 79 | + { |
|
| 76 | 80 | return; |
| 77 | 81 | } |
| 78 | 82 | |
| 79 | - foreach ($this->reporters as $reporter) { |
|
| 80 | - try { |
|
| 81 | - if ($reporter instanceof ExceptionReporterInterface) { |
|
| 83 | + foreach ($this->reporters as $reporter) |
|
| 84 | + { |
|
| 85 | + try |
|
| 86 | + { |
|
| 87 | + if ($reporter instanceof ExceptionReporterInterface) |
|
| 88 | + { |
|
| 82 | 89 | $reporter->report($exception); |
| 83 | - } else { |
|
| 90 | + } |
|
| 91 | + else |
|
| 92 | + { |
|
| 84 | 93 | $reporter($exception); |
| 85 | 94 | } |
| 86 | - } catch (\Throwable) { |
|
| 95 | + } |
|
| 96 | + catch (\Throwable) |
|
| 97 | + { |
|
| 87 | 98 | // Do nothing |
| 88 | 99 | } |
| 89 | 100 | } |
@@ -91,10 +102,13 @@ discard block |
||
| 91 | 102 | |
| 92 | 103 | public function handleGlobalException(\Throwable $e): void |
| 93 | 104 | { |
| 94 | - if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) { |
|
| 105 | + if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) |
|
| 106 | + { |
|
| 95 | 107 | $this->output ??= \defined('STDERR') ? \STDERR : \fopen('php://stderr', 'wb+'); |
| 96 | 108 | $format = 'cli'; |
| 97 | - } else { |
|
| 109 | + } |
|
| 110 | + else |
|
| 111 | + { |
|
| 98 | 112 | $this->output ??= \defined('STDOUT') ? \STDOUT : \fopen('php://stdout', 'wb+'); |
| 99 | 113 | $format = 'html'; |
| 100 | 114 | } |
@@ -103,9 +117,12 @@ discard block |
||
| 103 | 117 | $this->report($e); |
| 104 | 118 | |
| 105 | 119 | // There is possible an exception on the application termination |
| 106 | - try { |
|
| 120 | + try |
|
| 121 | + { |
|
| 107 | 122 | \fwrite($this->output, $this->render($e, verbosity: $this->verbosity, format: $format)); |
| 108 | - } catch (\Throwable) { |
|
| 123 | + } |
|
| 124 | + catch (\Throwable) |
|
| 125 | + { |
|
| 109 | 126 | $this->output = null; |
| 110 | 127 | } |
| 111 | 128 | } |
@@ -147,13 +164,17 @@ discard block |
||
| 147 | 164 | */ |
| 148 | 165 | protected function handleShutdown(): void |
| 149 | 166 | { |
| 150 | - if (empty($error = \error_get_last())) { |
|
| 167 | + if (empty($error = \error_get_last())) |
|
| 168 | + { |
|
| 151 | 169 | return; |
| 152 | 170 | } |
| 153 | 171 | |
| 154 | - try { |
|
| 172 | + try |
|
| 173 | + { |
|
| 155 | 174 | $this->handleError($error['type'], $error['message'], $error['file'], $error['line']); |
| 156 | - } catch (\Throwable $e) { |
|
| 175 | + } |
|
| 176 | + catch (\Throwable $e) |
|
| 177 | + { |
|
| 157 | 178 | $this->handleGlobalException($e); |
| 158 | 179 | } |
| 159 | 180 | } |
@@ -169,7 +190,8 @@ discard block |
||
| 169 | 190 | string $errfile = '', |
| 170 | 191 | int $errline = 0, |
| 171 | 192 | ): bool { |
| 172 | - if (!(\error_reporting() & $errno)) { |
|
| 193 | + if (!(\error_reporting() & $errno)) |
|
| 194 | + { |
|
| 173 | 195 | return false; |
| 174 | 196 | } |
| 175 | 197 | |
@@ -183,8 +205,10 @@ discard block |
||
| 183 | 205 | |
| 184 | 206 | protected function shouldNotReport(\Throwable $exception): bool |
| 185 | 207 | { |
| 186 | - foreach ($this->nonReportableExceptions as $nonReportableException) { |
|
| 187 | - if ($exception instanceof $nonReportableException) { |
|
| 208 | + foreach ($this->nonReportableExceptions as $nonReportableException) |
|
| 209 | + { |
|
| 210 | + if ($exception instanceof $nonReportableException) |
|
| 211 | + { |
|
| 188 | 212 | return true; |
| 189 | 213 | } |
| 190 | 214 | } |
@@ -55,9 +55,9 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | public function getRenderer(?string $format = null): ?ExceptionRendererInterface |
| 57 | 57 | { |
| 58 | - if ($format !== null) { |
|
| 59 | - foreach ($this->renderers as $renderer) { |
|
| 60 | - if ($renderer->canRender($format)) { |
|
| 58 | + if ($format !== null){ |
|
| 59 | + foreach ($this->renderers as $renderer){ |
|
| 60 | + if ($renderer->canRender($format)){ |
|
| 61 | 61 | return $renderer; |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | ?Verbosity $verbosity = null, |
| 71 | 71 | ?string $format = null, |
| 72 | 72 | ): string { |
| 73 | - return (string) $this->getRenderer($format)?->render($exception, $verbosity ?? $this->verbosity, $format); |
|
| 73 | + return (string)$this->getRenderer($format)?->render($exception, $verbosity ?? $this->verbosity, $format); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | public function canRender(string $format): bool |
@@ -80,18 +80,18 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | public function report(\Throwable $exception): void |
| 82 | 82 | { |
| 83 | - if ($this->shouldNotReport($exception)) { |
|
| 83 | + if ($this->shouldNotReport($exception)){ |
|
| 84 | 84 | return; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - foreach ($this->reporters as $reporter) { |
|
| 88 | - try { |
|
| 89 | - if ($reporter instanceof ExceptionReporterInterface) { |
|
| 87 | + foreach ($this->reporters as $reporter){ |
|
| 88 | + try{ |
|
| 89 | + if ($reporter instanceof ExceptionReporterInterface){ |
|
| 90 | 90 | $reporter->report($exception); |
| 91 | - } else { |
|
| 91 | + }else{ |
|
| 92 | 92 | $reporter($exception); |
| 93 | 93 | } |
| 94 | - } catch (\Throwable) { |
|
| 94 | + }catch (\Throwable){ |
|
| 95 | 95 | // Do nothing |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -99,10 +99,10 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | public function handleGlobalException(\Throwable $e): void |
| 101 | 101 | { |
| 102 | - if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)) { |
|
| 102 | + if (\in_array(PHP_SAPI, ['cli', 'cli-server'], true)){ |
|
| 103 | 103 | $this->output ??= \defined('STDERR') ? \STDERR : \fopen('php://stderr', 'wb+'); |
| 104 | 104 | $format = 'cli'; |
| 105 | - } else { |
|
| 105 | + }else{ |
|
| 106 | 106 | $this->output ??= \defined('STDOUT') ? \STDOUT : \fopen('php://stdout', 'wb+'); |
| 107 | 107 | $format = 'html'; |
| 108 | 108 | } |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | $this->report($e); |
| 112 | 112 | |
| 113 | 113 | // There is possible an exception on the application termination |
| 114 | - try { |
|
| 114 | + try{ |
|
| 115 | 115 | \fwrite($this->output, $this->render($e, verbosity: $this->verbosity, format: $format)); |
| 116 | - } catch (\Throwable) { |
|
| 116 | + }catch (\Throwable){ |
|
| 117 | 117 | $this->output = null; |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | /** |
| 138 | 138 | * @param ExceptionReporterInterface|\Closure(\Throwable):void $reporter |
| 139 | 139 | */ |
| 140 | - public function addReporter(ExceptionReporterInterface|\Closure $reporter): void |
|
| 140 | + public function addReporter(ExceptionReporterInterface | \Closure $reporter): void |
|
| 141 | 141 | { |
| 142 | 142 | $this->reporters[] = $reporter; |
| 143 | 143 | } |
@@ -155,13 +155,13 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | protected function handleShutdown(): void |
| 157 | 157 | { |
| 158 | - if (empty($error = \error_get_last())) { |
|
| 158 | + if (empty($error = \error_get_last())){ |
|
| 159 | 159 | return; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - try { |
|
| 162 | + try{ |
|
| 163 | 163 | $this->handleError($error['type'], $error['message'], $error['file'], $error['line']); |
| 164 | - } catch (\Throwable $e) { |
|
| 164 | + }catch (\Throwable $e){ |
|
| 165 | 165 | $this->handleGlobalException($e); |
| 166 | 166 | } |
| 167 | 167 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | string $errfile = '', |
| 178 | 178 | int $errline = 0, |
| 179 | 179 | ): bool { |
| 180 | - if (!(\error_reporting() & $errno)) { |
|
| 180 | + if (!(\error_reporting() & $errno)){ |
|
| 181 | 181 | return false; |
| 182 | 182 | } |
| 183 | 183 | |
@@ -191,8 +191,8 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | protected function shouldNotReport(\Throwable $exception): bool |
| 193 | 193 | { |
| 194 | - foreach ($this->nonReportableExceptions as $nonReportableException) { |
|
| 195 | - if ($exception instanceof $nonReportableException) { |
|
| 194 | + foreach ($this->nonReportableExceptions as $nonReportableException){ |
|
| 195 | + if ($exception instanceof $nonReportableException){ |
|
| 196 | 196 | return true; |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | return $name; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public function qux(int|string $age = 42): string|int |
|
| 18 | + public function qux(int | string $age = 42): string | int |
|
| 19 | 19 | { |
| 20 | 20 | return $age; |
| 21 | 21 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public function concat(string $prefix, string &$byLink): array |
| 39 | 39 | { |
| 40 | - $byLink = $prefix . $byLink; |
|
| 40 | + $byLink = $prefix.$byLink; |
|
| 41 | 41 | return \func_get_args(); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | public function concatMultiple(string $prefix, string &...$byLink): array |
| 50 | 50 | { |
| 51 | - foreach ($byLink as $k => $link) { |
|
| 52 | - $byLink[$k] = $prefix . $link; |
|
| 51 | + foreach ($byLink as $k => $link){ |
|
| 52 | + $byLink[$k] = $prefix.$link; |
|
| 53 | 53 | unset($link); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -48,7 +48,8 @@ |
||
| 48 | 48 | |
| 49 | 49 | public function concatMultiple(string $prefix, string &...$byLink): array |
| 50 | 50 | { |
| 51 | - foreach ($byLink as $k => $link) { |
|
| 51 | + foreach ($byLink as $k => $link) |
|
| 52 | + { |
|
| 52 | 53 | $byLink[$k] = $prefix . $link; |
| 53 | 54 | unset($link); |
| 54 | 55 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | public function baz(string $name, int $age): string; |
| 14 | 14 | |
| 15 | - public function qux(string|int $age = 42): string|int; |
|
| 15 | + public function qux(string | int $age = 42): string | int; |
|
| 16 | 16 | |
| 17 | 17 | public function space(mixed $test age = 42): mixed; |
| 18 | 18 | |
@@ -6,5 +6,5 @@ |
||
| 6 | 6 | |
| 7 | 7 | interface ContextInterface |
| 8 | 8 | { |
| 9 | - public function getValue(): \Stringable|string|null; |
|
| 9 | + public function getValue(): \Stringable | string | null; |
|
| 10 | 10 | } |
@@ -12,6 +12,6 @@ |
||
| 12 | 12 | trait ProxyTrait |
| 13 | 13 | { |
| 14 | 14 | private static string $__container_proxy_alias; |
| 15 | - private \Stringable|string|null $__container_proxy_context = null; |
|
| 15 | + private \Stringable | string | null $__container_proxy_context = null; |
|
| 16 | 16 | private ?ContainerInterface $__container_proxy_container = null; |
| 17 | 17 | } |
@@ -37,9 +37,11 @@ discard block |
||
| 37 | 37 | $attribute->proxyOverloads ? '[magic-calls]' : '', |
| 38 | 38 | ); |
| 39 | 39 | |
| 40 | - if (!\array_key_exists($cacheKey, self::$classes)) { |
|
| 40 | + if (!\array_key_exists($cacheKey, self::$classes)) |
|
| 41 | + { |
|
| 41 | 42 | $n = 0; |
| 42 | - do { |
|
| 43 | + do |
|
| 44 | + { |
|
| 43 | 45 | $className = \sprintf( |
| 44 | 46 | '%s\%s SCOPED PROXY%s', |
| 45 | 47 | $type->getNamespaceName(), |
@@ -49,7 +51,8 @@ discard block |
||
| 49 | 51 | } while (\class_exists($className)); |
| 50 | 52 | |
| 51 | 53 | /** @var class-string<TClass> $className */ |
| 52 | - try { |
|
| 54 | + try |
|
| 55 | + { |
|
| 53 | 56 | $classString = ProxyClassRenderer::renderClass( |
| 54 | 57 | $type, |
| 55 | 58 | $className, |
@@ -58,7 +61,9 @@ discard block |
||
| 58 | 61 | ); |
| 59 | 62 | |
| 60 | 63 | eval($classString); |
| 61 | - } catch (\Throwable $e) { |
|
| 64 | + } |
|
| 65 | + catch (\Throwable $e) |
|
| 66 | + { |
|
| 62 | 67 | throw new \Error("Unable to create proxy for `{$interface}`: {$e->getMessage()}", 0, $e); |
| 63 | 68 | } |
| 64 | 69 | |
@@ -67,12 +72,15 @@ discard block |
||
| 67 | 72 | |
| 68 | 73 | // Store in cache without context |
| 69 | 74 | self::$classes[$cacheKey] = $className; |
| 70 | - } else { |
|
| 75 | + } |
|
| 76 | + else |
|
| 77 | + { |
|
| 71 | 78 | /** @var TClass $instance */ |
| 72 | 79 | $instance = new (self::$classes[$cacheKey])(); |
| 73 | 80 | } |
| 74 | 81 | |
| 75 | - if ($context !== null || $attachContainer) { |
|
| 82 | + if ($context !== null || $attachContainer) |
|
| 83 | + { |
|
| 76 | 84 | (static function () use ($instance, $context, $attachContainer): void { |
| 77 | 85 | // Set the Current Context |
| 78 | 86 | /** @see \Spiral\Core\Internal\Proxy\ProxyTrait::$__container_proxy_context */ |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | public static function create( |
| 24 | 24 | \ReflectionClass $type, |
| 25 | - \Stringable|string|null $context, |
|
| 25 | + \Stringable | string | null $context, |
|
| 26 | 26 | \Spiral\Core\Attribute\Proxy $attribute, |
| 27 | 27 | ): object { |
| 28 | 28 | $interface = $type->getName(); |
@@ -37,19 +37,19 @@ discard block |
||
| 37 | 37 | $attribute->proxyOverloads ? '[magic-calls]' : '', |
| 38 | 38 | ); |
| 39 | 39 | |
| 40 | - if (!\array_key_exists($cacheKey, self::$classes)) { |
|
| 40 | + if (!\array_key_exists($cacheKey, self::$classes)){ |
|
| 41 | 41 | $n = 0; |
| 42 | - do { |
|
| 42 | + do{ |
|
| 43 | 43 | $className = \sprintf( |
| 44 | 44 | '%s\%s SCOPED PROXY%s', |
| 45 | 45 | $type->getNamespaceName(), |
| 46 | 46 | $type->getShortName(), |
| 47 | 47 | $n++ > 0 ? " {$n}" : '', |
| 48 | 48 | ); |
| 49 | - } while (\class_exists($className)); |
|
| 49 | + }while (\class_exists($className)); |
|
| 50 | 50 | |
| 51 | 51 | /** @var class-string<TClass> $className */ |
| 52 | - try { |
|
| 52 | + try{ |
|
| 53 | 53 | $classString = ProxyClassRenderer::renderClass( |
| 54 | 54 | $type, |
| 55 | 55 | $className, |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | ); |
| 59 | 59 | |
| 60 | 60 | eval($classString); |
| 61 | - } catch (\Throwable $e) { |
|
| 61 | + }catch (\Throwable $e){ |
|
| 62 | 62 | throw new \Error("Unable to create proxy for `{$interface}`: {$e->getMessage()}", 0, $e); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -67,12 +67,12 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | // Store in cache without context |
| 69 | 69 | self::$classes[$cacheKey] = $className; |
| 70 | - } else { |
|
| 70 | + }else{ |
|
| 71 | 71 | /** @var TClass $instance */ |
| 72 | 72 | $instance = new (self::$classes[$cacheKey])(); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ($context !== null || $attachContainer) { |
|
| 75 | + if ($context !== null || $attachContainer){ |
|
| 76 | 76 | (static function () use ($instance, $context, $attachContainer): void { |
| 77 | 77 | // Set the Current Context |
| 78 | 78 | /** @see \Spiral\Core\Internal\Proxy\ProxyTrait::$__container_proxy_context */ |
@@ -46,7 +46,9 @@ |
||
| 46 | 46 | $binder = $this->constructor->get('binder', BinderInterface::class); |
| 47 | 47 | $factory = $this->constructor->get('factory', FactoryInterface::class); |
| 48 | 48 | |
| 49 | - $this->bindSingleton('test', new #[Singleton] class {}); |
|
| 49 | + $this->bindSingleton('test', new #[Singleton] class |
|
| 50 | + { |
|
| 51 | +}); |
|
| 50 | 52 | $factory->make('test'); |
| 51 | 53 | |
| 52 | 54 | $this->assertTrue($binder->hasInstance('test')); |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | #[Route('/page/<page>', name: 'page_get', methods: 'GET')] |
| 12 | 12 | public function get($page): string |
| 13 | 13 | { |
| 14 | - return 'page-' . $page; |
|
| 14 | + return 'page-'.$page; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | #[Route('/page/about', name: 'page_about', methods: 'GET', priority: -1)] |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | use DestructorTrait; |
| 20 | 20 | |
| 21 | 21 | private State $state; |
| 22 | - private FactoryInterface|Factory $factory; |
|
| 22 | + private FactoryInterface | Factory $factory; |
|
| 23 | 23 | private Scope $scope; |
| 24 | 24 | |
| 25 | 25 | public function __construct(Registry $constructor) |
@@ -49,9 +49,9 @@ discard block |
||
| 49 | 49 | * @throws ContainerException |
| 50 | 50 | * @throws \Throwable |
| 51 | 51 | */ |
| 52 | - public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed |
|
| 52 | + public function get(string | Autowire $id, \Stringable | string | null $context = null): mixed |
|
| 53 | 53 | { |
| 54 | - if ($id instanceof Autowire) { |
|
| 54 | + if ($id instanceof Autowire){ |
|
| 55 | 55 | return $id->resolve($this->factory); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | public function has(string $id): bool |
| 63 | 63 | { |
| 64 | - if (\array_key_exists($id, $this->state->bindings) || \array_key_exists($id, $this->state->singletons)) { |
|
| 64 | + if (\array_key_exists($id, $this->state->bindings) || \array_key_exists($id, $this->state->singletons)){ |
|
| 65 | 65 | return true; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -51,7 +51,8 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed |
| 53 | 53 | { |
| 54 | - if ($id instanceof Autowire) { |
|
| 54 | + if ($id instanceof Autowire) |
|
| 55 | + { |
|
| 55 | 56 | return $id->resolve($this->factory); |
| 56 | 57 | } |
| 57 | 58 | |
@@ -61,7 +62,8 @@ discard block |
||
| 61 | 62 | |
| 62 | 63 | public function has(string $id): bool |
| 63 | 64 | { |
| 64 | - if (\array_key_exists($id, $this->state->bindings) || \array_key_exists($id, $this->state->singletons)) { |
|
| 65 | + if (\array_key_exists($id, $this->state->bindings) || \array_key_exists($id, $this->state->singletons)) |
|
| 66 | + { |
|
| 65 | 67 | return true; |
| 66 | 68 | } |
| 67 | 69 | |