@@ -75,7 +75,7 @@ |
||
| 75 | 75 | |
| 76 | 76 | $http->setHandler( |
| 77 | 77 | static function (ServerRequestInterface $request, ResponseInterface $response): void { |
| 78 | - if ($request->getAttribute('authContext')->getToken() === null) { |
|
| 78 | + if ($request->getAttribute('authContext')->getToken() === null){ |
|
| 79 | 79 | echo 'no token'; |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -75,7 +75,8 @@ |
||
| 75 | 75 | |
| 76 | 76 | $http->setHandler( |
| 77 | 77 | static function (ServerRequestInterface $request, ResponseInterface $response): void { |
| 78 | - if ($request->getAttribute('authContext')->getToken() === null) { |
|
| 78 | + if ($request->getAttribute('authContext')->getToken() === null) |
|
| 79 | + { |
|
| 79 | 80 | echo 'no token'; |
| 80 | 81 | } |
| 81 | 82 | } |
@@ -16,11 +16,11 @@ |
||
| 16 | 16 | protected readonly UriInterface $uri, |
| 17 | 17 | protected readonly ResponseFactoryInterface $responseFactory, |
| 18 | 18 | protected readonly int $status = 302 |
| 19 | - ) { |
|
| 19 | + ){ |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | protected function denyAccess(Request $request, RequestHandlerInterface $handler): Response |
| 23 | 23 | { |
| 24 | - return $this->responseFactory->createResponse($this->status)->withHeader('Location', (string) $this->uri); |
|
| 24 | + return $this->responseFactory->createResponse($this->status)->withHeader('Location', (string)$this->uri); |
|
| 25 | 25 | } |
| 26 | 26 | } |
@@ -41,11 +41,11 @@ |
||
| 41 | 41 | public function __construct( |
| 42 | 42 | public readonly string $route, |
| 43 | 43 | public readonly ?string $name = null, |
| 44 | - public readonly array|string $methods = \Spiral\Router\Route::VERBS, |
|
| 44 | + public readonly array | string $methods = \Spiral\Router\Route::VERBS, |
|
| 45 | 45 | public readonly array $defaults = [], |
| 46 | 46 | public readonly ?string $group = null, |
| 47 | 47 | public readonly array $middleware = [], |
| 48 | 48 | public readonly int $priority = 0 |
| 49 | - ) { |
|
| 49 | + ){ |
|
| 50 | 50 | } |
| 51 | 51 | } |
@@ -24,10 +24,12 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function listen(ReflectionClass $class): void |
| 26 | 26 | { |
| 27 | - foreach ($class->getMethods() as $method) { |
|
| 27 | + foreach ($class->getMethods() as $method) |
|
| 28 | + { |
|
| 28 | 29 | $route = $this->reader->firstFunctionMetadata($method, Route::class); |
| 29 | 30 | |
| 30 | - if ($route === null) { |
|
| 31 | + if ($route === null) |
|
| 32 | + { |
|
| 31 | 33 | continue; |
| 32 | 34 | } |
| 33 | 35 | |
@@ -40,7 +42,8 @@ discard block |
||
| 40 | 42 | $defaultGroup = $this->groups->getDefaultGroup(); |
| 41 | 43 | |
| 42 | 44 | $routes = []; |
| 43 | - foreach ($this->attributes as $classes) { |
|
| 45 | + foreach ($this->attributes as $classes) |
|
| 46 | + { |
|
| 44 | 47 | [$method, $route] = $classes; |
| 45 | 48 | $class = $method->getDeclaringClass(); |
| 46 | 49 | |
@@ -64,7 +67,8 @@ discard block |
||
| 64 | 67 | |
| 65 | 68 | private function configureRoutes(array $routes): void |
| 66 | 69 | { |
| 67 | - foreach ($routes as $name => $schema) { |
|
| 70 | + foreach ($routes as $name => $schema) |
|
| 71 | + { |
|
| 68 | 72 | $route = new \Spiral\Router\Route( |
| 69 | 73 | $schema['pattern'], |
| 70 | 74 | new Action($schema['controller'], $schema['action']), |
@@ -21,15 +21,15 @@ discard block |
||
| 21 | 21 | public function __construct( |
| 22 | 22 | private readonly ReaderInterface $reader, |
| 23 | 23 | private readonly GroupRegistry $groups, |
| 24 | - ) { |
|
| 24 | + ){ |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function listen(ReflectionClass $class): void |
| 28 | 28 | { |
| 29 | - foreach ($class->getMethods() as $method) { |
|
| 29 | + foreach ($class->getMethods() as $method){ |
|
| 30 | 30 | $route = $this->reader->firstFunctionMetadata($method, Route::class); |
| 31 | 31 | |
| 32 | - if ($route === null) { |
|
| 32 | + if ($route === null){ |
|
| 33 | 33 | continue; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | $defaultGroup = $this->groups->getDefaultGroup(); |
| 43 | 43 | |
| 44 | 44 | $routes = []; |
| 45 | - foreach ($this->attributes as $classes) { |
|
| 45 | + foreach ($this->attributes as $classes){ |
|
| 46 | 46 | [$method, $route] = $classes; |
| 47 | 47 | $class = $method->getDeclaringClass(); |
| 48 | 48 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | private function configureRoutes(array $routes): void |
| 68 | 68 | { |
| 69 | - foreach ($routes as $name => $schema) { |
|
| 69 | + foreach ($routes as $name => $schema){ |
|
| 70 | 70 | $route = new \Spiral\Router\Route( |
| 71 | 71 | $schema['pattern'], |
| 72 | 72 | new Action($schema['controller'], $schema['action']), |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | public function __construct( |
| 18 | 18 | private readonly ResponseFactoryInterface $responseFactory |
| 19 | - ) { |
|
| 19 | + ){ |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | public function renderException(Request $request, int $code, \Throwable $exception): Response |
@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | $acceptItems = AcceptHeader::fromString($request->getHeaderLine('Accept'))->getAll(); |
| 26 | 26 | |
| 27 | 27 | $response = $this->responseFactory->createResponse($code); |
| 28 | - if ($acceptItems && $acceptItems[0]->getValue() === 'application/json') { |
|
| 28 | + if ($acceptItems && $acceptItems[0]->getValue() === 'application/json'){ |
|
| 29 | 29 | $response = $response->withHeader('Content-Type', 'application/json; charset=UTF-8'); |
| 30 | 30 | $response->getBody()->write(\json_encode(['status' => $code])); |
| 31 | - } else { |
|
| 31 | + }else{ |
|
| 32 | 32 | $response->getBody()->write("Error code: {$code}"); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -25,10 +25,13 @@ |
||
| 25 | 25 | $acceptItems = AcceptHeader::fromString($request->getHeaderLine('Accept'))->getAll(); |
| 26 | 26 | |
| 27 | 27 | $response = $this->responseFactory->createResponse($code); |
| 28 | - if ($acceptItems && $acceptItems[0]->getValue() === 'application/json') { |
|
| 28 | + if ($acceptItems && $acceptItems[0]->getValue() === 'application/json') |
|
| 29 | + { |
|
| 29 | 30 | $response = $response->withHeader('Content-Type', 'application/json; charset=UTF-8'); |
| 30 | 31 | $response->getBody()->write(\json_encode(['status' => $code])); |
| 31 | - } else { |
|
| 32 | + } |
|
| 33 | + else |
|
| 34 | + { |
|
| 32 | 35 | $response->getBody()->write("Error code: {$code}"); |
| 33 | 36 | } |
| 34 | 37 | |
@@ -39,17 +39,23 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function process(Request $request, Handler $handler): Response |
| 41 | 41 | { |
| 42 | - try { |
|
| 42 | + try |
|
| 43 | + { |
|
| 43 | 44 | return $handler->handle($request); |
| 44 | - } catch (ClientException|RouterException $e) { |
|
| 45 | + } |
|
| 46 | + catch (ClientException|RouterException $e) |
|
| 47 | + { |
|
| 45 | 48 | $code = $e instanceof ClientException ? $e->getCode() : 404; |
| 46 | - } catch (\Throwable $e) { |
|
| 49 | + } |
|
| 50 | + catch (\Throwable $e) |
|
| 51 | + { |
|
| 47 | 52 | $code = 500; |
| 48 | 53 | } |
| 49 | 54 | |
| 50 | 55 | $this->errorHandler->report($e); |
| 51 | 56 | |
| 52 | - if (!$this->suppressErrors->suppressed()) { |
|
| 57 | + if (!$this->suppressErrors->suppressed()) |
|
| 58 | + { |
|
| 53 | 59 | return $this->renderError($request, $e, $code); |
| 54 | 60 | } |
| 55 | 61 | |
@@ -67,7 +73,8 @@ discard block |
||
| 67 | 73 | |
| 68 | 74 | [$format, $renderer] = $this->getRenderer($this->errorHandler, $request); |
| 69 | 75 | |
| 70 | - if ($format !== null) { |
|
| 76 | + if ($format !== null) |
|
| 77 | + { |
|
| 71 | 78 | $response = $response->withHeader('Content-Type', $format . '; charset=UTF-8'); |
| 72 | 79 | } |
| 73 | 80 | |
@@ -87,12 +94,15 @@ discard block |
||
| 87 | 94 | */ |
| 88 | 95 | private function getRenderer(ExceptionHandlerInterface $handler, Request $request): array |
| 89 | 96 | { |
| 90 | - if ($request->hasHeader('Accept')) { |
|
| 97 | + if ($request->hasHeader('Accept')) |
|
| 98 | + { |
|
| 91 | 99 | $acceptItems = AcceptHeader::fromString($request->getHeaderLine('Accept'))->getAll(); |
| 92 | - foreach ($acceptItems as $item) { |
|
| 100 | + foreach ($acceptItems as $item) |
|
| 101 | + { |
|
| 93 | 102 | $format = $item->getValue(); |
| 94 | 103 | $renderer = $handler->getRenderer($format); |
| 95 | - if ($renderer !== null) { |
|
| 104 | + if ($renderer !== null) |
|
| 105 | + { |
|
| 96 | 106 | return [$format, $renderer]; |
| 97 | 107 | } |
| 98 | 108 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | private readonly ResponseFactoryInterface $responseFactory, |
| 33 | 33 | private readonly ExceptionHandlerInterface $errorHandler, |
| 34 | 34 | private readonly Verbosity $verbosity = Verbosity::VERBOSE, |
| 35 | - ) { |
|
| 35 | + ){ |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -41,17 +41,17 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function process(Request $request, Handler $handler): Response |
| 43 | 43 | { |
| 44 | - try { |
|
| 44 | + try{ |
|
| 45 | 45 | return $handler->handle($request); |
| 46 | - } catch (ClientException|RouterException $e) { |
|
| 46 | + }catch (ClientException | RouterException $e){ |
|
| 47 | 47 | $code = $e instanceof ClientException ? $e->getCode() : 404; |
| 48 | - } catch (\Throwable $e) { |
|
| 48 | + }catch (\Throwable $e){ |
|
| 49 | 49 | $code = 500; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $this->errorHandler->report($e); |
| 53 | 53 | |
| 54 | - if (!$this->suppressErrors->suppressed()) { |
|
| 54 | + if (!$this->suppressErrors->suppressed()){ |
|
| 55 | 55 | return $this->renderError($request, $e, $code); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | [$format, $renderer] = $this->getRenderer($this->errorHandler, $request); |
| 71 | 71 | |
| 72 | - if ($format !== null) { |
|
| 73 | - $response = $response->withHeader('Content-Type', $format . '; charset=UTF-8'); |
|
| 72 | + if ($format !== null){ |
|
| 73 | + $response = $response->withHeader('Content-Type', $format.'; charset=UTF-8'); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $response->getBody()->write( |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | private function getRenderer(ExceptionHandlerInterface $handler, Request $request): array |
| 91 | 91 | { |
| 92 | - if ($request->hasHeader('Accept')) { |
|
| 92 | + if ($request->hasHeader('Accept')){ |
|
| 93 | 93 | $acceptItems = AcceptHeader::fromString($request->getHeaderLine('Accept'))->getAll(); |
| 94 | - foreach ($acceptItems as $item) { |
|
| 94 | + foreach ($acceptItems as $item){ |
|
| 95 | 95 | $format = $item->getValue(); |
| 96 | 96 | $renderer = $handler->getRenderer($format); |
| 97 | - if ($renderer !== null) { |
|
| 97 | + if ($renderer !== null){ |
|
| 98 | 98 | return [$format, $renderer]; |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -62,10 +62,13 @@ discard block |
||
| 62 | 62 | $groups->registerRoutes($router); |
| 63 | 63 | }; |
| 64 | 64 | |
| 65 | - if ($kernel instanceof Kernel) { |
|
| 65 | + if ($kernel instanceof Kernel) |
|
| 66 | + { |
|
| 66 | 67 | $kernel->appBooted($configuratorCallback); |
| 67 | 68 | $kernel->appBooted($groupsCallback); |
| 68 | - } else { |
|
| 69 | + } |
|
| 70 | + else |
|
| 71 | + { |
|
| 69 | 72 | $kernel->booted($configuratorCallback); |
| 70 | 73 | $kernel->booted($groupsCallback); |
| 71 | 74 | } |
@@ -95,7 +98,8 @@ discard block |
||
| 95 | 98 | private function route(ServerRequestInterface $request): RouteInterface |
| 96 | 99 | { |
| 97 | 100 | $route = $request->getAttribute(Router::ROUTE_ATTRIBUTE, null); |
| 98 | - if ($route === null) { |
|
| 101 | + if ($route === null) |
|
| 102 | + { |
|
| 99 | 103 | throw new ScopeException('Unable to resolve Route, invalid request scope'); |
| 100 | 104 | } |
| 101 | 105 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | public function __construct( |
| 42 | 42 | private readonly ConfiguratorInterface $config, |
| 43 | 43 | private readonly BinderInterface $binder, |
| 44 | - ) { |
|
| 44 | + ){ |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | public function defineDependencies(): array |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | $groups->registerRoutes($router); |
| 81 | 81 | }; |
| 82 | 82 | |
| 83 | - if ($kernel instanceof Kernel) { |
|
| 83 | + if ($kernel instanceof Kernel){ |
|
| 84 | 84 | $kernel->appBooted($configuratorCallback); |
| 85 | 85 | $kernel->appBooted($groupsCallback); |
| 86 | - } else { |
|
| 86 | + }else{ |
|
| 87 | 87 | $kernel->booted($configuratorCallback); |
| 88 | 88 | $kernel->booted($groupsCallback); |
| 89 | 89 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | private function route(ServerRequestInterface $request): RouteInterface |
| 114 | 114 | { |
| 115 | 115 | $route = $request->getAttribute(Router::ROUTE_ATTRIBUTE, null); |
| 116 | - if ($route === null) { |
|
| 116 | + if ($route === null){ |
|
| 117 | 117 | throw new ScopeException('Unable to resolve Route, invalid request scope'); |
| 118 | 118 | } |
| 119 | 119 | |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | final class CacheHandlerTest extends TestCase |
| 14 | 14 | { |
| 15 | 15 | private CacheHandler $handler; |
| 16 | - private m\MockInterface|CacheInterface $cache; |
|
| 16 | + private m\MockInterface | CacheInterface $cache; |
|
| 17 | 17 | |
| 18 | 18 | protected function setUp(): void |
| 19 | 19 | { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | private readonly ?string $storage = null, |
| 18 | 18 | private readonly int $ttl = 86400, |
| 19 | 19 | private readonly string $prefix = 'session:' |
| 20 | - ) { |
|
| 20 | + ){ |
|
| 21 | 21 | $this->cache = $storageProvider->storage($this->storage); |
| 22 | 22 | } |
| 23 | 23 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | return true; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - public function gc(int $max_lifetime): int|false |
|
| 39 | + public function gc(int $max_lifetime): int | false |
|
| 40 | 40 | { |
| 41 | 41 | return 0; |
| 42 | 42 | } |
@@ -49,11 +49,11 @@ discard block |
||
| 49 | 49 | /** |
| 50 | 50 | * @throws InvalidArgumentException |
| 51 | 51 | */ |
| 52 | - public function read(string $id): string|false |
|
| 52 | + public function read(string $id): string | false |
|
| 53 | 53 | { |
| 54 | 54 | $result = $this->cache->get($this->getKey($id)); |
| 55 | 55 | |
| 56 | - return (string) $result; |
|
| 56 | + return (string)$result; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -66,6 +66,6 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | private function getKey(string $id): string |
| 68 | 68 | { |
| 69 | - return $this->prefix . $id; |
|
| 69 | + return $this->prefix.$id; |
|
| 70 | 70 | } |
| 71 | 71 | } |