@@ -8,7 +8,7 @@ |
||
8 | 8 | { |
9 | 9 | public function __construct( |
10 | 10 | private readonly string $value |
11 | - ) { |
|
11 | + ){ |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | public function __toString(): string |
@@ -15,7 +15,7 @@ |
||
15 | 15 | private readonly string $controller, |
16 | 16 | int $options = 0, |
17 | 17 | string $defaultAction = 'index' |
18 | - ) { |
|
18 | + ){ |
|
19 | 19 | parent::__construct( |
20 | 20 | ['action' => null], |
21 | 21 | ['action' => null], |
@@ -15,7 +15,7 @@ |
||
15 | 15 | private readonly array $controllers, |
16 | 16 | int $options = 0, |
17 | 17 | string $defaultAction = 'index' |
18 | - ) { |
|
18 | + ){ |
|
19 | 19 | parent::__construct( |
20 | 20 | ['controller' => null, 'action' => null], |
21 | 21 | ['controller' => \array_keys($controllers), 'action' => null], |
@@ -23,16 +23,16 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct( |
25 | 25 | private readonly string $controller, |
26 | - private readonly string|array $action, |
|
26 | + private readonly string | array $action, |
|
27 | 27 | int $options = 0 |
28 | - ) { |
|
29 | - if (\is_string($action)) { |
|
28 | + ){ |
|
29 | + if (\is_string($action)){ |
|
30 | 30 | parent::__construct( |
31 | 31 | ['action' => $action], |
32 | 32 | ['action' => new Autofill($action)], |
33 | 33 | $options |
34 | 34 | ); |
35 | - } else { |
|
35 | + }else{ |
|
36 | 36 | parent::__construct( |
37 | 37 | ['action' => null], |
38 | 38 | ['action' => $action], |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | protected function resolveAction(array $matches): string |
50 | 50 | { |
51 | 51 | $action = $this->action; |
52 | - if (\is_string($action)) { |
|
52 | + if (\is_string($action)){ |
|
53 | 53 | return $action; |
54 | 54 | } |
55 | 55 |
@@ -26,13 +26,16 @@ discard block |
||
26 | 26 | private readonly string|array $action, |
27 | 27 | int $options = 0 |
28 | 28 | ) { |
29 | - if (\is_string($action)) { |
|
29 | + if (\is_string($action)) |
|
30 | + { |
|
30 | 31 | parent::__construct( |
31 | 32 | ['action' => $action], |
32 | 33 | ['action' => new Autofill($action)], |
33 | 34 | $options |
34 | 35 | ); |
35 | - } else { |
|
36 | + } |
|
37 | + else |
|
38 | + { |
|
36 | 39 | parent::__construct( |
37 | 40 | ['action' => null], |
38 | 41 | ['action' => $action], |
@@ -49,7 +52,8 @@ discard block |
||
49 | 52 | protected function resolveAction(array $matches): string |
50 | 53 | { |
51 | 54 | $action = $this->action; |
52 | - if (\is_string($action)) { |
|
55 | + if (\is_string($action)) |
|
56 | + { |
|
53 | 57 | return $action; |
54 | 58 | } |
55 | 59 |
@@ -9,6 +9,6 @@ |
||
9 | 9 | public function __construct( |
10 | 10 | public readonly ?object $actor, |
11 | 11 | public readonly ?string $transport = null |
12 | - ) { |
|
12 | + ){ |
|
13 | 13 | } |
14 | 14 | } |
@@ -11,6 +11,6 @@ |
||
11 | 11 | public function __construct( |
12 | 12 | public readonly TokenInterface $token, |
13 | 13 | public readonly ?string $transport = null |
14 | - ) { |
|
14 | + ){ |
|
15 | 15 | } |
16 | 16 | } |
@@ -43,11 +43,13 @@ |
||
43 | 43 | |
44 | 44 | public function getActor(): ?object |
45 | 45 | { |
46 | - if ($this->closed) { |
|
46 | + if ($this->closed) |
|
47 | + { |
|
47 | 48 | return null; |
48 | 49 | } |
49 | 50 | |
50 | - if ($this->actor === null && $this->token !== null) { |
|
51 | + if ($this->actor === null && $this->token !== null) |
|
52 | + { |
|
51 | 53 | $this->actor = $this->actorProvider->getActor($this->token); |
52 | 54 | } |
53 | 55 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | public function __construct( |
19 | 19 | private readonly ActorProviderInterface $actorProvider, |
20 | 20 | private readonly ?EventDispatcherInterface $eventDispatcher = null |
21 | - ) { |
|
21 | + ){ |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function start(TokenInterface $token, ?string $transport = null): void |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | |
44 | 44 | public function getActor(): ?object |
45 | 45 | { |
46 | - if ($this->closed) { |
|
46 | + if ($this->closed){ |
|
47 | 47 | return null; |
48 | 48 | } |
49 | 49 | |
50 | - if ($this->actor === null && $this->token !== null) { |
|
50 | + if ($this->actor === null && $this->token !== null){ |
|
51 | 51 | $this->actor = $this->actorProvider->getActor($this->token); |
52 | 52 | } |
53 | 53 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | public function __construct( |
15 | 15 | private readonly ?string $domain = null, |
16 | 16 | private readonly bool $secure = false |
17 | - ) { |
|
17 | + ){ |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | bool $httpOnly = true, |
74 | 74 | ?string $sameSite = null |
75 | 75 | ): self { |
76 | - if (\is_null($domain)) { |
|
76 | + if (\is_null($domain)){ |
|
77 | 77 | //Let's resolve domain via config |
78 | 78 | $domain = $this->domain; |
79 | 79 | } |
80 | 80 | |
81 | - if (\is_null($secure)) { |
|
81 | + if (\is_null($secure)){ |
|
82 | 82 | $secure = $this->secure; |
83 | 83 | } |
84 | 84 | |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function delete(string $name): void |
104 | 104 | { |
105 | - foreach ($this->scheduled as $index => $cookie) { |
|
106 | - if ($cookie->getName() === $name) { |
|
105 | + foreach ($this->scheduled as $index => $cookie){ |
|
106 | + if ($cookie->getName() === $name){ |
|
107 | 107 | unset($this->scheduled[$index]); |
108 | 108 | } |
109 | 109 | } |
@@ -73,12 +73,14 @@ discard block |
||
73 | 73 | bool $httpOnly = true, |
74 | 74 | ?string $sameSite = null |
75 | 75 | ): self { |
76 | - if (\is_null($domain)) { |
|
76 | + if (\is_null($domain)) |
|
77 | + { |
|
77 | 78 | //Let's resolve domain via config |
78 | 79 | $domain = $this->domain; |
79 | 80 | } |
80 | 81 | |
81 | - if (\is_null($secure)) { |
|
82 | + if (\is_null($secure)) |
|
83 | + { |
|
82 | 84 | $secure = $this->secure; |
83 | 85 | } |
84 | 86 | |
@@ -102,8 +104,10 @@ discard block |
||
102 | 104 | */ |
103 | 105 | public function delete(string $name): void |
104 | 106 | { |
105 | - foreach ($this->scheduled as $index => $cookie) { |
|
106 | - if ($cookie->getName() === $name) { |
|
107 | + foreach ($this->scheduled as $index => $cookie) |
|
108 | + { |
|
109 | + if ($cookie->getName() === $name) |
|
110 | + { |
|
107 | 111 | unset($this->scheduled[$index]); |
108 | 112 | } |
109 | 113 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function __construct( |
26 | 26 | private readonly CookiesConfig $config, |
27 | 27 | private readonly EncryptionInterface $encryption |
28 | - ) { |
|
28 | + ){ |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | public function process(Request $request, RequestHandlerInterface $handler): Response |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | { |
51 | 51 | $cookies = $request->getCookieParams(); |
52 | 52 | |
53 | - foreach ($cookies as $name => $cookie) { |
|
54 | - if (!$this->isProtected($name)) { |
|
53 | + foreach ($cookies as $name => $cookie){ |
|
54 | + if (!$this->isProtected($name)){ |
|
55 | 55 | continue; |
56 | 56 | } |
57 | 57 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | protected function isProtected(string $cookie): bool |
68 | 68 | { |
69 | - if (\in_array($cookie, $this->config->getExcludedCookies(), true)) { |
|
69 | + if (\in_array($cookie, $this->config->getExcludedCookies(), true)){ |
|
70 | 70 | //Excluded |
71 | 71 | return false; |
72 | 72 | } |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function packCookies(Response $response, CookieQueue $queue): Response |
83 | 83 | { |
84 | - if (empty($queue->getScheduled())) { |
|
84 | + if (empty($queue->getScheduled())){ |
|
85 | 85 | return $response; |
86 | 86 | } |
87 | 87 | |
88 | 88 | $cookies = $response->getHeader('Set-Cookie'); |
89 | 89 | |
90 | - foreach ($queue->getScheduled() as $cookie) { |
|
91 | - if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())) { |
|
90 | + foreach ($queue->getScheduled() as $cookie){ |
|
91 | + if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())){ |
|
92 | 92 | $cookies[] = $cookie->createHeader(); |
93 | 93 | continue; |
94 | 94 | } |
@@ -99,28 +99,28 @@ discard block |
||
99 | 99 | return $response->withHeader('Set-Cookie', $cookies); |
100 | 100 | } |
101 | 101 | |
102 | - private function decodeCookie(array|string $cookie): mixed |
|
102 | + private function decodeCookie(array | string $cookie): mixed |
|
103 | 103 | { |
104 | - try { |
|
105 | - if (\is_array($cookie)) { |
|
106 | - return \array_map(fn (array|string $cookie) => $this->decodeCookie($cookie), $cookie); |
|
104 | + try{ |
|
105 | + if (\is_array($cookie)){ |
|
106 | + return \array_map(fn (array | string $cookie) => $this->decodeCookie($cookie), $cookie); |
|
107 | 107 | } |
108 | - } catch (DecryptException) { |
|
108 | + }catch (DecryptException){ |
|
109 | 109 | return null; |
110 | 110 | } |
111 | 111 | |
112 | - switch ($this->config->getProtectionMethod()) { |
|
112 | + switch ($this->config->getProtectionMethod()){ |
|
113 | 113 | case CookiesConfig::COOKIE_ENCRYPT: |
114 | - try { |
|
114 | + try{ |
|
115 | 115 | return $this->encryption->getEncrypter()->decrypt($cookie); |
116 | - } catch (DecryptException) { |
|
116 | + }catch (DecryptException){ |
|
117 | 117 | } |
118 | 118 | return null; |
119 | 119 | case CookiesConfig::COOKIE_HMAC: |
120 | 120 | $hmac = \substr($cookie, -1 * CookiesConfig::MAC_LENGTH); |
121 | 121 | $value = \substr($cookie, 0, \strlen($cookie) - \strlen($hmac)); |
122 | 122 | |
123 | - if (\hash_equals($this->hmacSign($value), $hmac)) { |
|
123 | + if (\hash_equals($this->hmacSign($value), $hmac)){ |
|
124 | 124 | return $value; |
125 | 125 | } |
126 | 126 | } |
@@ -143,13 +143,13 @@ discard block |
||
143 | 143 | private function encodeCookie(Cookie $cookie): Cookie |
144 | 144 | { |
145 | 145 | $value = $cookie->getValue() ?? ''; |
146 | - if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT) { |
|
146 | + if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT){ |
|
147 | 147 | $encryptor = $this->encryption->getEncrypter(); |
148 | 148 | |
149 | 149 | return $cookie->withValue($encryptor->encrypt($value)); |
150 | 150 | } |
151 | 151 | |
152 | 152 | //VALUE.HMAC |
153 | - return $cookie->withValue($value . $this->hmacSign($value)); |
|
153 | + return $cookie->withValue($value.$this->hmacSign($value)); |
|
154 | 154 | } |
155 | 155 | } |
@@ -50,8 +50,10 @@ discard block |
||
50 | 50 | { |
51 | 51 | $cookies = $request->getCookieParams(); |
52 | 52 | |
53 | - foreach ($cookies as $name => $cookie) { |
|
54 | - if (!$this->isProtected($name)) { |
|
53 | + foreach ($cookies as $name => $cookie) |
|
54 | + { |
|
55 | + if (!$this->isProtected($name)) |
|
56 | + { |
|
55 | 57 | continue; |
56 | 58 | } |
57 | 59 | |
@@ -66,7 +68,8 @@ discard block |
||
66 | 68 | */ |
67 | 69 | protected function isProtected(string $cookie): bool |
68 | 70 | { |
69 | - if (\in_array($cookie, $this->config->getExcludedCookies(), true)) { |
|
71 | + if (\in_array($cookie, $this->config->getExcludedCookies(), true)) |
|
72 | + { |
|
70 | 73 | //Excluded |
71 | 74 | return false; |
72 | 75 | } |
@@ -81,14 +84,17 @@ discard block |
||
81 | 84 | */ |
82 | 85 | protected function packCookies(Response $response, CookieQueue $queue): Response |
83 | 86 | { |
84 | - if (empty($queue->getScheduled())) { |
|
87 | + if (empty($queue->getScheduled())) |
|
88 | + { |
|
85 | 89 | return $response; |
86 | 90 | } |
87 | 91 | |
88 | 92 | $cookies = $response->getHeader('Set-Cookie'); |
89 | 93 | |
90 | - foreach ($queue->getScheduled() as $cookie) { |
|
91 | - if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())) { |
|
94 | + foreach ($queue->getScheduled() as $cookie) |
|
95 | + { |
|
96 | + if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())) |
|
97 | + { |
|
92 | 98 | $cookies[] = $cookie->createHeader(); |
93 | 99 | continue; |
94 | 100 | } |
@@ -101,26 +107,35 @@ discard block |
||
101 | 107 | |
102 | 108 | private function decodeCookie(array|string $cookie): mixed |
103 | 109 | { |
104 | - try { |
|
105 | - if (\is_array($cookie)) { |
|
110 | + try |
|
111 | + { |
|
112 | + if (\is_array($cookie)) |
|
113 | + { |
|
106 | 114 | return \array_map(fn (array|string $cookie) => $this->decodeCookie($cookie), $cookie); |
107 | 115 | } |
108 | - } catch (DecryptException) { |
|
116 | + } |
|
117 | + catch (DecryptException) |
|
118 | + { |
|
109 | 119 | return null; |
110 | 120 | } |
111 | 121 | |
112 | - switch ($this->config->getProtectionMethod()) { |
|
122 | + switch ($this->config->getProtectionMethod()) |
|
123 | + { |
|
113 | 124 | case CookiesConfig::COOKIE_ENCRYPT: |
114 | - try { |
|
125 | + try |
|
126 | + { |
|
115 | 127 | return $this->encryption->getEncrypter()->decrypt($cookie); |
116 | - } catch (DecryptException) { |
|
128 | + } |
|
129 | + catch (DecryptException) |
|
130 | + { |
|
117 | 131 | } |
118 | 132 | return null; |
119 | 133 | case CookiesConfig::COOKIE_HMAC: |
120 | 134 | $hmac = \substr($cookie, -1 * CookiesConfig::MAC_LENGTH); |
121 | 135 | $value = \substr($cookie, 0, \strlen($cookie) - \strlen($hmac)); |
122 | 136 | |
123 | - if (\hash_equals($this->hmacSign($value), $hmac)) { |
|
137 | + if (\hash_equals($this->hmacSign($value), $hmac)) |
|
138 | + { |
|
124 | 139 | return $value; |
125 | 140 | } |
126 | 141 | } |
@@ -143,7 +158,8 @@ discard block |
||
143 | 158 | private function encodeCookie(Cookie $cookie): Cookie |
144 | 159 | { |
145 | 160 | $value = $cookie->getValue() ?? ''; |
146 | - if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT) { |
|
161 | + if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT) |
|
162 | + { |
|
147 | 163 | $encryptor = $this->encryption->getEncrypter(); |
148 | 164 | |
149 | 165 | return $cookie->withValue($encryptor->encrypt($value)); |