@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | bool $secure = false, |
44 | 44 | bool $httpOnly = true, |
45 | 45 | ?string $sameSite = null |
46 | - ) { |
|
46 | + ){ |
|
47 | 47 | $this->cookie = $cookie; |
48 | 48 | $this->basePath = $basePath; |
49 | 49 | $this->domain = $domain; |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | ): Response { |
73 | 73 | /** @var CookieQueue $cookieQueue */ |
74 | 74 | $cookieQueue = $request->getAttribute(CookieQueue::ATTRIBUTE); |
75 | - if ($cookieQueue === null) { |
|
75 | + if ($cookieQueue === null){ |
|
76 | 76 | return $response->withAddedHeader( |
77 | 77 | 'Set-Cookie', |
78 | 78 | Cookie::create( |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | ); |
89 | 89 | } |
90 | 90 | |
91 | - if ($tokenID === null) { |
|
91 | + if ($tokenID === null){ |
|
92 | 92 | $cookieQueue->delete($this->cookie); |
93 | - } else { |
|
93 | + }else{ |
|
94 | 94 | $cookieQueue->set( |
95 | 95 | $this->cookie, |
96 | 96 | $tokenID, |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | private function getLifetime(DateTimeInterface $expiresAt = null): ?int |
122 | 122 | { |
123 | - if ($expiresAt === null) { |
|
123 | + if ($expiresAt === null){ |
|
124 | 124 | return null; |
125 | 125 | } |
126 | 126 |
@@ -72,7 +72,8 @@ discard block |
||
72 | 72 | ): Response { |
73 | 73 | /** @var CookieQueue $cookieQueue */ |
74 | 74 | $cookieQueue = $request->getAttribute(CookieQueue::ATTRIBUTE); |
75 | - if ($cookieQueue === null) { |
|
75 | + if ($cookieQueue === null) |
|
76 | + { |
|
76 | 77 | return $response->withAddedHeader( |
77 | 78 | 'Set-Cookie', |
78 | 79 | Cookie::create( |
@@ -88,9 +89,12 @@ discard block |
||
88 | 89 | ); |
89 | 90 | } |
90 | 91 | |
91 | - if ($tokenID === null) { |
|
92 | + if ($tokenID === null) |
|
93 | + { |
|
92 | 94 | $cookieQueue->delete($this->cookie); |
93 | - } else { |
|
95 | + } |
|
96 | + else |
|
97 | + { |
|
94 | 98 | $cookieQueue->set( |
95 | 99 | $this->cookie, |
96 | 100 | $tokenID, |
@@ -120,7 +124,8 @@ discard block |
||
120 | 124 | */ |
121 | 125 | private function getLifetime(DateTimeInterface $expiresAt = null): ?int |
122 | 126 | { |
123 | - if ($expiresAt === null) { |
|
127 | + if ($expiresAt === null) |
|
128 | + { |
|
124 | 129 | return null; |
125 | 130 | } |
126 | 131 |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function fetchToken(Request $request): ?string |
38 | 38 | { |
39 | - if ($request->hasHeader($this->header)) { |
|
39 | + if ($request->hasHeader($this->header)){ |
|
40 | 40 | return $this->extractToken($request); |
41 | 41 | } |
42 | 42 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | string $tokenID, |
53 | 53 | DateTimeInterface $expiresAt = null |
54 | 54 | ): Response { |
55 | - if ($request->hasHeader($this->header) && $this->extractToken($request) === $tokenID) { |
|
55 | + if ($request->hasHeader($this->header) && $this->extractToken($request) === $tokenID){ |
|
56 | 56 | return $response; |
57 | 57 | } |
58 | 58 | |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | { |
72 | 72 | $headerLine = $request->getHeaderLine($this->header); |
73 | 73 | |
74 | - if ($this->valueFormat !== '%s') { |
|
74 | + if ($this->valueFormat !== '%s'){ |
|
75 | 75 | [$token] = sscanf($headerLine, $this->valueFormat); |
76 | 76 | |
77 | - return $token !== null ? (string) $token : null; |
|
77 | + return $token !== null ? (string)$token : null; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | return $headerLine; |
@@ -36,7 +36,8 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function fetchToken(Request $request): ?string |
38 | 38 | { |
39 | - if ($request->hasHeader($this->header)) { |
|
39 | + if ($request->hasHeader($this->header)) |
|
40 | + { |
|
40 | 41 | return $this->extractToken($request); |
41 | 42 | } |
42 | 43 | |
@@ -52,7 +53,8 @@ discard block |
||
52 | 53 | string $tokenID, |
53 | 54 | DateTimeInterface $expiresAt = null |
54 | 55 | ): Response { |
55 | - if ($request->hasHeader($this->header) && $this->extractToken($request) === $tokenID) { |
|
56 | + if ($request->hasHeader($this->header) && $this->extractToken($request) === $tokenID) |
|
57 | + { |
|
56 | 58 | return $response; |
57 | 59 | } |
58 | 60 | |
@@ -71,7 +73,8 @@ discard block |
||
71 | 73 | { |
72 | 74 | $headerLine = $request->getHeaderLine($this->header); |
73 | 75 | |
74 | - if ($this->valueFormat !== '%s') { |
|
76 | + if ($this->valueFormat !== '%s') |
|
77 | + { |
|
75 | 78 | [$token] = sscanf($headerLine, $this->valueFormat); |
76 | 79 | |
77 | 80 | return $token !== null ? (string) $token : null; |
@@ -70,14 +70,17 @@ discard block |
||
70 | 70 | |
71 | 71 | private function initContext(Request $request, AuthContextInterface $authContext): AuthContextInterface |
72 | 72 | { |
73 | - foreach ($this->transportRegistry->getTransports() as $name => $transport) { |
|
73 | + foreach ($this->transportRegistry->getTransports() as $name => $transport) |
|
74 | + { |
|
74 | 75 | $tokenID = $transport->fetchToken($request); |
75 | - if ($tokenID === null) { |
|
76 | + if ($tokenID === null) |
|
77 | + { |
|
76 | 78 | continue; |
77 | 79 | } |
78 | 80 | |
79 | 81 | $token = $this->tokenStorage->load($tokenID); |
80 | - if ($token === null) { |
|
82 | + if ($token === null) |
|
83 | + { |
|
81 | 84 | continue; |
82 | 85 | } |
83 | 86 | |
@@ -91,13 +94,15 @@ discard block |
||
91 | 94 | |
92 | 95 | private function closeContext(Request $request, Response $response, AuthContextInterface $authContext): Response |
93 | 96 | { |
94 | - if ($authContext->getToken() === null) { |
|
97 | + if ($authContext->getToken() === null) |
|
98 | + { |
|
95 | 99 | return $response; |
96 | 100 | } |
97 | 101 | |
98 | 102 | $transport = $this->transportRegistry->getTransport($authContext->getTransport()); |
99 | 103 | |
100 | - if ($authContext->isClosed()) { |
|
104 | + if ($authContext->isClosed()) |
|
105 | + { |
|
101 | 106 | $this->tokenStorage->delete($authContext->getToken()); |
102 | 107 | |
103 | 108 | return $transport->removeToken( |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | public function process(Request $request, RequestHandlerInterface $handler): Response |
46 | 46 | { |
47 | 47 | $cookie = null; |
48 | - if (isset($request->getCookieParams()[$this->config->getCookie()])) { |
|
48 | + if (isset($request->getCookieParams()[$this->config->getCookie()])){ |
|
49 | 49 | $token = $request->getCookieParams()[$this->config->getCookie()]; |
50 | - } else { |
|
50 | + }else{ |
|
51 | 51 | //Making new token |
52 | 52 | $token = $this->random($this->config->getTokenLength()); |
53 | 53 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | //CSRF issues must be handled by Firewall middleware |
59 | 59 | $response = $handler->handle($request->withAttribute(static::ATTRIBUTE, $token)); |
60 | 60 | |
61 | - if (!empty($cookie)) { |
|
61 | + if (!empty($cookie)){ |
|
62 | 62 | return $response->withAddedHeader('Set-Cookie', $cookie); |
63 | 63 | } |
64 | 64 | |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | */ |
90 | 90 | private function random(int $length = 32): string |
91 | 91 | { |
92 | - try { |
|
93 | - if (empty($string = random_bytes($length))) { |
|
92 | + try{ |
|
93 | + if (empty($string = random_bytes($length))){ |
|
94 | 94 | throw new RuntimeException('Unable to generate random string'); |
95 | 95 | } |
96 | - } catch (Throwable $e) { |
|
96 | + }catch (Throwable $e){ |
|
97 | 97 | throw new RuntimeException('Unable to generate random string', $e->getCode(), $e); |
98 | 98 | } |
99 | 99 |
@@ -45,9 +45,12 @@ discard block |
||
45 | 45 | public function process(Request $request, RequestHandlerInterface $handler): Response |
46 | 46 | { |
47 | 47 | $cookie = null; |
48 | - if (isset($request->getCookieParams()[$this->config->getCookie()])) { |
|
48 | + if (isset($request->getCookieParams()[$this->config->getCookie()])) |
|
49 | + { |
|
49 | 50 | $token = $request->getCookieParams()[$this->config->getCookie()]; |
50 | - } else { |
|
51 | + } |
|
52 | + else |
|
53 | + { |
|
51 | 54 | //Making new token |
52 | 55 | $token = $this->random($this->config->getTokenLength()); |
53 | 56 | |
@@ -58,7 +61,8 @@ discard block |
||
58 | 61 | //CSRF issues must be handled by Firewall middleware |
59 | 62 | $response = $handler->handle($request->withAttribute(static::ATTRIBUTE, $token)); |
60 | 63 | |
61 | - if (!empty($cookie)) { |
|
64 | + if (!empty($cookie)) |
|
65 | + { |
|
62 | 66 | return $response->withAddedHeader('Set-Cookie', $cookie); |
63 | 67 | } |
64 | 68 | |
@@ -89,11 +93,15 @@ discard block |
||
89 | 93 | */ |
90 | 94 | private function random(int $length = 32): string |
91 | 95 | { |
92 | - try { |
|
93 | - if (empty($string = random_bytes($length))) { |
|
96 | + try |
|
97 | + { |
|
98 | + if (empty($string = random_bytes($length))) |
|
99 | + { |
|
94 | 100 | throw new RuntimeException('Unable to generate random string'); |
95 | 101 | } |
96 | - } catch (Throwable $e) { |
|
102 | + } |
|
103 | + catch (Throwable $e) |
|
104 | + { |
|
97 | 105 | throw new RuntimeException('Unable to generate random string', $e->getCode(), $e); |
98 | 106 | } |
99 | 107 |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | { |
57 | 57 | $token = $request->getAttribute(CsrfMiddleware::ATTRIBUTE); |
58 | 58 | |
59 | - if (empty($token)) { |
|
59 | + if (empty($token)){ |
|
60 | 60 | throw new LogicException('Unable to apply CSRF firewall, attribute is missing'); |
61 | 61 | } |
62 | 62 | |
63 | - if ($this->isRequired($request) && !hash_equals($token, $this->fetchToken($request))) { |
|
63 | + if ($this->isRequired($request) && !hash_equals($token, $this->fetchToken($request))){ |
|
64 | 64 | return $this->responseFactory->createResponse(412, 'Bad CSRF Token'); |
65 | 65 | } |
66 | 66 | |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | */ |
81 | 81 | protected function fetchToken(Request $request): string |
82 | 82 | { |
83 | - if ($request->hasHeader(self::HEADER)) { |
|
83 | + if ($request->hasHeader(self::HEADER)){ |
|
84 | 84 | return $request->getHeaderLine(self::HEADER); |
85 | 85 | } |
86 | 86 | |
87 | 87 | $data = $request->getParsedBody(); |
88 | - if (is_array($data) && isset($data[self::PARAMETER]) && is_string($data[self::PARAMETER])) { |
|
88 | + if (is_array($data) && isset($data[self::PARAMETER]) && is_string($data[self::PARAMETER])){ |
|
89 | 89 | return $data[self::PARAMETER]; |
90 | 90 | } |
91 | 91 |
@@ -56,11 +56,13 @@ discard block |
||
56 | 56 | { |
57 | 57 | $token = $request->getAttribute(CsrfMiddleware::ATTRIBUTE); |
58 | 58 | |
59 | - if (empty($token)) { |
|
59 | + if (empty($token)) |
|
60 | + { |
|
60 | 61 | throw new LogicException('Unable to apply CSRF firewall, attribute is missing'); |
61 | 62 | } |
62 | 63 | |
63 | - if ($this->isRequired($request) && !hash_equals($token, $this->fetchToken($request))) { |
|
64 | + if ($this->isRequired($request) && !hash_equals($token, $this->fetchToken($request))) |
|
65 | + { |
|
64 | 66 | return $this->responseFactory->createResponse(412, 'Bad CSRF Token'); |
65 | 67 | } |
66 | 68 | |
@@ -80,12 +82,14 @@ discard block |
||
80 | 82 | */ |
81 | 83 | protected function fetchToken(Request $request): string |
82 | 84 | { |
83 | - if ($request->hasHeader(self::HEADER)) { |
|
85 | + if ($request->hasHeader(self::HEADER)) |
|
86 | + { |
|
84 | 87 | return $request->getHeaderLine(self::HEADER); |
85 | 88 | } |
86 | 89 | |
87 | 90 | $data = $request->getParsedBody(); |
88 | - if (is_array($data) && isset($data[self::PARAMETER]) && is_string($data[self::PARAMETER])) { |
|
91 | + if (is_array($data) && isset($data[self::PARAMETER]) && is_string($data[self::PARAMETER])) |
|
92 | + { |
|
89 | 93 | return $data[self::PARAMETER]; |
90 | 94 | } |
91 | 95 |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | namespace Spiral\Scaffolder; |
13 | 13 | |
14 | -if (!function_exists('trimPostfix')) { |
|
14 | +if (!function_exists('trimPostfix')){ |
|
15 | 15 | /** |
16 | 16 | * @param string $name |
17 | 17 | * @param string $postfix |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | -if (!function_exists('isAssociativeArray')) { |
|
29 | +if (!function_exists('isAssociativeArray')){ |
|
30 | 30 | /** |
31 | 31 | * @param array $array |
32 | 32 | * @return bool |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | function isAssociativeArray(array $array): bool |
36 | 36 | { |
37 | 37 | $keys = []; |
38 | - foreach ($array as $key => $_) { |
|
39 | - if (!is_int($key)) { |
|
38 | + foreach ($array as $key => $_){ |
|
39 | + if (!is_int($key)){ |
|
40 | 40 | return true; |
41 | 41 | } |
42 | 42 | |
43 | - if ($key !== count($keys)) { |
|
43 | + if ($key !== count($keys)){ |
|
44 | 44 | return true; |
45 | 45 | } |
46 | 46 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
54 | -if (!function_exists('defineArrayType')) { |
|
54 | +if (!function_exists('defineArrayType')){ |
|
55 | 55 | /** |
56 | 56 | * @param array $array |
57 | 57 | * @param string|null $failureType |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | function defineArrayType(array $array, string $failureType = null): ?string |
62 | 62 | { |
63 | - $types = array_map(static fn ($value): string => gettype($value), $array); |
|
63 | + $types = array_map(static fn ($value) : string => gettype($value), $array); |
|
64 | 64 | |
65 | 65 | $types = array_unique($types); |
66 | 66 |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | public function start(Container $container): void |
71 | 71 | { |
72 | - if ($container->has(JobRegistry::class)) { |
|
72 | + if ($container->has(JobRegistry::class)){ |
|
73 | 73 | // Will be removed since v3.0 |
74 | 74 | $registry = $container->get(JobRegistry::class); |
75 | 75 | $registry->setHandler(MailQueue::JOB_NAME, MailJob::class); |
@@ -77,16 +77,16 @@ discard block |
||
77 | 77 | $container->bindSingleton( |
78 | 78 | MailerInterface::class, |
79 | 79 | static function (MailerConfig $config) use ($container) { |
80 | - if ($config->getQueueConnection() === 'sync') { |
|
80 | + if ($config->getQueueConnection() === 'sync'){ |
|
81 | 81 | $queue = $container->get(ShortCircuit::class); |
82 | - } else { |
|
82 | + }else{ |
|
83 | 83 | $queue = $container->get(QueueInterface::class); |
84 | 84 | } |
85 | 85 | |
86 | 86 | return new MailQueue($config, $queue); |
87 | 87 | } |
88 | 88 | ); |
89 | - } else { |
|
89 | + }else{ |
|
90 | 90 | $container->bindSingleton( |
91 | 91 | MailerInterface::class, |
92 | 92 | static fn (MailerConfig $config, QueueConnectionProviderInterface $provider) => new MailQueue( |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | ); |
97 | 97 | } |
98 | 98 | |
99 | - if ($container->has(HandlerRegistryInterface::class)) { |
|
99 | + if ($container->has(HandlerRegistryInterface::class)){ |
|
100 | 100 | $registry = $container->get(HandlerRegistryInterface::class); |
101 | 101 | $registry->setHandler(MailQueue::JOB_NAME, MailJob::class); |
102 | 102 | } |
@@ -69,24 +69,31 @@ discard block |
||
69 | 69 | |
70 | 70 | public function start(Container $container): void |
71 | 71 | { |
72 | - if ($container->has(JobRegistry::class)) { |
|
72 | + if ($container->has(JobRegistry::class)) |
|
73 | + { |
|
73 | 74 | // Will be removed since v3.0 |
74 | 75 | $registry = $container->get(JobRegistry::class); |
75 | 76 | $registry->setHandler(MailQueue::JOB_NAME, MailJob::class); |
76 | 77 | $registry->setSerializer(MailQueue::JOB_NAME, MessageSerializer::class); |
77 | 78 | $container->bindSingleton( |
78 | 79 | MailerInterface::class, |
79 | - static function (MailerConfig $config) use ($container) { |
|
80 | - if ($config->getQueueConnection() === 'sync') { |
|
80 | + static function (MailerConfig $config) use ($container) |
|
81 | + { |
|
82 | + if ($config->getQueueConnection() === 'sync') |
|
83 | + { |
|
81 | 84 | $queue = $container->get(ShortCircuit::class); |
82 | - } else { |
|
85 | + } |
|
86 | + else |
|
87 | + { |
|
83 | 88 | $queue = $container->get(QueueInterface::class); |
84 | 89 | } |
85 | 90 | |
86 | 91 | return new MailQueue($config, $queue); |
87 | 92 | } |
88 | 93 | ); |
89 | - } else { |
|
94 | + } |
|
95 | + else |
|
96 | + { |
|
90 | 97 | $container->bindSingleton( |
91 | 98 | MailerInterface::class, |
92 | 99 | static fn (MailerConfig $config, QueueConnectionProviderInterface $provider) => new MailQueue( |
@@ -96,7 +103,8 @@ discard block |
||
96 | 103 | ); |
97 | 104 | } |
98 | 105 | |
99 | - if ($container->has(HandlerRegistryInterface::class)) { |
|
106 | + if ($container->has(HandlerRegistryInterface::class)) |
|
107 | + { |
|
100 | 108 | $registry = $container->get(HandlerRegistryInterface::class); |
101 | 109 | $registry->setHandler(MailQueue::JOB_NAME, MailJob::class); |
102 | 110 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | { |
55 | 55 | $manager = new CacheManager($config, $container); |
56 | 56 | |
57 | - foreach ($config->getAliases() as $alias => $storageName) { |
|
57 | + foreach ($config->getAliases() as $alias => $storageName){ |
|
58 | 58 | $container->bind($alias, static fn (CacheManager $manager) => $manager->storage($storageName)); |
59 | 59 | } |
60 | 60 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | ], |
75 | 75 | 'file' => [ |
76 | 76 | 'type' => 'file', |
77 | - 'path' => $dirs->get('runtime') . 'cache', |
|
77 | + 'path' => $dirs->get('runtime').'cache', |
|
78 | 78 | ], |
79 | 79 | ], |
80 | 80 | 'typeAliases' => [ |
@@ -54,7 +54,8 @@ |
||
54 | 54 | { |
55 | 55 | $manager = new CacheManager($config, $container); |
56 | 56 | |
57 | - foreach ($config->getAliases() as $alias => $storageName) { |
|
57 | + foreach ($config->getAliases() as $alias => $storageName) |
|
58 | + { |
|
58 | 59 | $container->bind($alias, static fn (CacheManager $manager) => $manager->storage($storageName)); |
59 | 60 | } |
60 | 61 |
@@ -33,9 +33,9 @@ |
||
33 | 33 | */ |
34 | 34 | public function loadFile(string $section, string $filename): array |
35 | 35 | { |
36 | - try { |
|
36 | + try{ |
|
37 | 37 | return ContainerScope::runScope($this->container, fn () => require $filename); |
38 | - } catch (Throwable $e) { |
|
38 | + }catch (Throwable $e){ |
|
39 | 39 | throw new LoaderException($e->getMessage(), $e->getCode(), $e); |
40 | 40 | } |
41 | 41 | } |
@@ -33,9 +33,12 @@ |
||
33 | 33 | */ |
34 | 34 | public function loadFile(string $section, string $filename): array |
35 | 35 | { |
36 | - try { |
|
36 | + try |
|
37 | + { |
|
37 | 38 | return ContainerScope::runScope($this->container, fn () => require $filename); |
38 | - } catch (Throwable $e) { |
|
39 | + } |
|
40 | + catch (Throwable $e) |
|
41 | + { |
|
39 | 42 | throw new LoaderException($e->getMessage(), $e->getCode(), $e); |
40 | 43 | } |
41 | 44 | } |