@@ -73,8 +73,8 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $cookies = $request->getCookieParams(); |
| 75 | 75 | |
| 76 | - foreach ($cookies as $name => $cookie) { |
|
| 77 | - if (!$this->isProtected($name)) { |
|
| 76 | + foreach ($cookies as $name => $cookie){ |
|
| 77 | + if (!$this->isProtected($name)){ |
|
| 78 | 78 | continue; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | protected function isProtected(string $cookie): bool |
| 94 | 94 | { |
| 95 | - if (in_array($cookie, $this->config->getExcludedCookies(), true)) { |
|
| 95 | + if (in_array($cookie, $this->config->getExcludedCookies(), true)){ |
|
| 96 | 96 | //Excluded |
| 97 | 97 | return false; |
| 98 | 98 | } |
@@ -111,14 +111,14 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | protected function packCookies(Response $response, CookieQueue $queue): Response |
| 113 | 113 | { |
| 114 | - if (empty($queue->getScheduled())) { |
|
| 114 | + if (empty($queue->getScheduled())){ |
|
| 115 | 115 | return $response; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | $cookies = $response->getHeader('Set-Cookie'); |
| 119 | 119 | |
| 120 | - foreach ($queue->getScheduled() as $cookie) { |
|
| 121 | - if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())) { |
|
| 120 | + foreach ($queue->getScheduled() as $cookie){ |
|
| 121 | + if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())){ |
|
| 122 | 122 | $cookies[] = $cookie->createHeader(); |
| 123 | 123 | continue; |
| 124 | 124 | } |
@@ -135,26 +135,26 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | private function decodeCookie($cookie) |
| 137 | 137 | { |
| 138 | - try { |
|
| 139 | - if (is_array($cookie)) { |
|
| 138 | + try{ |
|
| 139 | + if (is_array($cookie)){ |
|
| 140 | 140 | return array_map([$this, 'decodeCookie'], $cookie); |
| 141 | 141 | } |
| 142 | - } catch (DecryptException $exception) { |
|
| 142 | + }catch (DecryptException $exception){ |
|
| 143 | 143 | return null; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - switch ($this->config->getProtectionMethod()) { |
|
| 146 | + switch ($this->config->getProtectionMethod()){ |
|
| 147 | 147 | case CookiesConfig::COOKIE_ENCRYPT: |
| 148 | - try { |
|
| 148 | + try{ |
|
| 149 | 149 | return $this->encryption->getEncrypter()->decrypt($cookie); |
| 150 | - } catch (DecryptException $e) { |
|
| 150 | + }catch (DecryptException $e){ |
|
| 151 | 151 | } |
| 152 | 152 | return null; |
| 153 | 153 | case CookiesConfig::COOKIE_HMAC: |
| 154 | 154 | $hmac = substr($cookie, -1 * CookiesConfig::MAC_LENGTH); |
| 155 | 155 | $value = substr($cookie, 0, strlen($cookie) - strlen($hmac)); |
| 156 | 156 | |
| 157 | - if (hash_equals($this->hmacSign($value), $hmac)) { |
|
| 157 | + if (hash_equals($this->hmacSign($value), $hmac)){ |
|
| 158 | 158 | return $value; |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -183,13 +183,13 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | private function encodeCookie(Cookie $cookie): Cookie |
| 185 | 185 | { |
| 186 | - if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT) { |
|
| 186 | + if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT){ |
|
| 187 | 187 | $encryptor = $this->encryption->getEncrypter(); |
| 188 | 188 | |
| 189 | 189 | return $cookie->withValue($encryptor->encrypt($cookie->getValue())); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | //VALUE.HMAC |
| 193 | - return $cookie->withValue($cookie->getValue() . $this->hmacSign($cookie->getValue())); |
|
| 193 | + return $cookie->withValue($cookie->getValue().$this->hmacSign($cookie->getValue())); |
|
| 194 | 194 | } |
| 195 | 195 | } |
@@ -73,8 +73,10 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $cookies = $request->getCookieParams(); |
| 75 | 75 | |
| 76 | - foreach ($cookies as $name => $cookie) { |
|
| 77 | - if (!$this->isProtected($name)) { |
|
| 76 | + foreach ($cookies as $name => $cookie) |
|
| 77 | + { |
|
| 78 | + if (!$this->isProtected($name)) |
|
| 79 | + { |
|
| 78 | 80 | continue; |
| 79 | 81 | } |
| 80 | 82 | |
@@ -92,7 +94,8 @@ discard block |
||
| 92 | 94 | */ |
| 93 | 95 | protected function isProtected(string $cookie): bool |
| 94 | 96 | { |
| 95 | - if (in_array($cookie, $this->config->getExcludedCookies(), true)) { |
|
| 97 | + if (in_array($cookie, $this->config->getExcludedCookies(), true)) |
|
| 98 | + { |
|
| 96 | 99 | //Excluded |
| 97 | 100 | return false; |
| 98 | 101 | } |
@@ -111,14 +114,17 @@ discard block |
||
| 111 | 114 | */ |
| 112 | 115 | protected function packCookies(Response $response, CookieQueue $queue): Response |
| 113 | 116 | { |
| 114 | - if (empty($queue->getScheduled())) { |
|
| 117 | + if (empty($queue->getScheduled())) |
|
| 118 | + { |
|
| 115 | 119 | return $response; |
| 116 | 120 | } |
| 117 | 121 | |
| 118 | 122 | $cookies = $response->getHeader('Set-Cookie'); |
| 119 | 123 | |
| 120 | - foreach ($queue->getScheduled() as $cookie) { |
|
| 121 | - if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())) { |
|
| 124 | + foreach ($queue->getScheduled() as $cookie) |
|
| 125 | + { |
|
| 126 | + if (empty($cookie->getValue()) || !$this->isProtected($cookie->getName())) |
|
| 127 | + { |
|
| 122 | 128 | $cookies[] = $cookie->createHeader(); |
| 123 | 129 | continue; |
| 124 | 130 | } |
@@ -135,26 +141,35 @@ discard block |
||
| 135 | 141 | */ |
| 136 | 142 | private function decodeCookie($cookie) |
| 137 | 143 | { |
| 138 | - try { |
|
| 139 | - if (is_array($cookie)) { |
|
| 144 | + try |
|
| 145 | + { |
|
| 146 | + if (is_array($cookie)) |
|
| 147 | + { |
|
| 140 | 148 | return array_map([$this, 'decodeCookie'], $cookie); |
| 141 | 149 | } |
| 142 | - } catch (DecryptException $exception) { |
|
| 150 | + } |
|
| 151 | + catch (DecryptException $exception) |
|
| 152 | + { |
|
| 143 | 153 | return null; |
| 144 | 154 | } |
| 145 | 155 | |
| 146 | - switch ($this->config->getProtectionMethod()) { |
|
| 156 | + switch ($this->config->getProtectionMethod()) |
|
| 157 | + { |
|
| 147 | 158 | case CookiesConfig::COOKIE_ENCRYPT: |
| 148 | - try { |
|
| 159 | + try |
|
| 160 | + { |
|
| 149 | 161 | return $this->encryption->getEncrypter()->decrypt($cookie); |
| 150 | - } catch (DecryptException $e) { |
|
| 162 | + } |
|
| 163 | + catch (DecryptException $e) |
|
| 164 | + { |
|
| 151 | 165 | } |
| 152 | 166 | return null; |
| 153 | 167 | case CookiesConfig::COOKIE_HMAC: |
| 154 | 168 | $hmac = substr($cookie, -1 * CookiesConfig::MAC_LENGTH); |
| 155 | 169 | $value = substr($cookie, 0, strlen($cookie) - strlen($hmac)); |
| 156 | 170 | |
| 157 | - if (hash_equals($this->hmacSign($value), $hmac)) { |
|
| 171 | + if (hash_equals($this->hmacSign($value), $hmac)) |
|
| 172 | + { |
|
| 158 | 173 | return $value; |
| 159 | 174 | } |
| 160 | 175 | } |
@@ -183,7 +198,8 @@ discard block |
||
| 183 | 198 | */ |
| 184 | 199 | private function encodeCookie(Cookie $cookie): Cookie |
| 185 | 200 | { |
| 186 | - if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT) { |
|
| 201 | + if ($this->config->getProtectionMethod() === CookiesConfig::COOKIE_ENCRYPT) |
|
| 202 | + { |
|
| 187 | 203 | $encryptor = $this->encryption->getEncrypter(); |
| 188 | 204 | |
| 189 | 205 | return $cookie->withValue($encryptor->encrypt($cookie->getValue())); |
@@ -53,22 +53,22 @@ |
||
| 53 | 53 | public function resolveDomain(UriInterface $uri): ?string |
| 54 | 54 | { |
| 55 | 55 | $host = $uri->getHost(); |
| 56 | - if (empty($host)) { |
|
| 56 | + if (empty($host)){ |
|
| 57 | 57 | return null; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $pattern = $this->config['domain']; |
| 61 | - if (preg_match("/^(\d{1,3}){4}:\d+$/", $host, $matches)) { |
|
| 61 | + if (preg_match("/^(\d{1,3}){4}:\d+$/", $host, $matches)){ |
|
| 62 | 62 | // remove port |
| 63 | 63 | $host = $matches[1]; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if ($host === 'localhost' || filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 66 | + if ($host === 'localhost' || filter_var($host, FILTER_VALIDATE_IP)){ |
|
| 67 | 67 | //We can't use sub-domains when website required by IP |
| 68 | 68 | $pattern = ltrim($pattern, '.'); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if (strpos($pattern, '%s') === false) { |
|
| 71 | + if (strpos($pattern, '%s') === false){ |
|
| 72 | 72 | //Forced domain |
| 73 | 73 | return $pattern; |
| 74 | 74 | } |
@@ -53,22 +53,26 @@ |
||
| 53 | 53 | public function resolveDomain(UriInterface $uri): ?string |
| 54 | 54 | { |
| 55 | 55 | $host = $uri->getHost(); |
| 56 | - if (empty($host)) { |
|
| 56 | + if (empty($host)) |
|
| 57 | + { |
|
| 57 | 58 | return null; |
| 58 | 59 | } |
| 59 | 60 | |
| 60 | 61 | $pattern = $this->config['domain']; |
| 61 | - if (preg_match("/^(\d{1,3}){4}:\d+$/", $host, $matches)) { |
|
| 62 | + if (preg_match("/^(\d{1,3}){4}:\d+$/", $host, $matches)) |
|
| 63 | + { |
|
| 62 | 64 | // remove port |
| 63 | 65 | $host = $matches[1]; |
| 64 | 66 | } |
| 65 | 67 | |
| 66 | - if ($host === 'localhost' || filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 68 | + if ($host === 'localhost' || filter_var($host, FILTER_VALIDATE_IP)) |
|
| 69 | + { |
|
| 67 | 70 | //We can't use sub-domains when website required by IP |
| 68 | 71 | $pattern = ltrim($pattern, '.'); |
| 69 | 72 | } |
| 70 | 73 | |
| 71 | - if (strpos($pattern, '%s') === false) { |
|
| 74 | + if (strpos($pattern, '%s') === false) |
|
| 75 | + { |
|
| 72 | 76 | //Forced domain |
| 73 | 77 | return $pattern; |
| 74 | 78 | } |
@@ -33,12 +33,12 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | private function defineValue(?string $sameSite, bool $secure): ?string |
| 35 | 35 | { |
| 36 | - if ($sameSite === null) { |
|
| 36 | + if ($sameSite === null){ |
|
| 37 | 37 | return null; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $sameSite = ucfirst(strtolower($sameSite)); |
| 41 | - if (!in_array($sameSite, self::VALUES, true)) { |
|
| 41 | + if (!in_array($sameSite, self::VALUES, true)){ |
|
| 42 | 42 | return null; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -33,12 +33,14 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | private function defineValue(?string $sameSite, bool $secure): ?string |
| 35 | 35 | { |
| 36 | - if ($sameSite === null) { |
|
| 36 | + if ($sameSite === null) |
|
| 37 | + { |
|
| 37 | 38 | return null; |
| 38 | 39 | } |
| 39 | 40 | |
| 40 | 41 | $sameSite = ucfirst(strtolower($sameSite)); |
| 41 | - if (!in_array($sameSite, self::VALUES, true)) { |
|
| 42 | + if (!in_array($sameSite, self::VALUES, true)) |
|
| 43 | + { |
|
| 42 | 44 | return null; |
| 43 | 45 | } |
| 44 | 46 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | public const NONE = 'None'; |
| 12 | 12 | |
| 13 | 13 | private const VALUES = [self::STRICT, self::LAX, self::NONE]; |
| 14 | - private const DEFAULT = self::LAX; |
|
| 14 | + private const default = self::LAX; |
|
| 15 | 15 | |
| 16 | 16 | /** @var string|null */ |
| 17 | 17 | private $sameSite; |
@@ -42,6 +42,6 @@ discard block |
||
| 42 | 42 | return null; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - return ($sameSite === self::NONE && !$secure) ? self::DEFAULT : $sameSite; |
|
| 45 | + return ($sameSite === self::NONE && !$secure) ? self::default : $sameSite; |
|
| 46 | 46 | } |
| 47 | 47 | } |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | $output = trim(implode("\n", $output), "\n ,"); |
| 65 | 65 | |
| 66 | - if ($output !== '') { |
|
| 66 | + if ($output !== ''){ |
|
| 67 | 67 | $this->files->deleteDirectory($tmpDir); |
| 68 | 68 | throw new CompileException($output); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // copying files (using relative path and namespace) |
| 72 | 72 | $result = []; |
| 73 | - foreach ($this->files->getFiles($tmpDir) as $file) { |
|
| 73 | + foreach ($this->files->getFiles($tmpDir) as $file){ |
|
| 74 | 74 | $result[] = $this->copy($tmpDir, $file); |
| 75 | 75 | } |
| 76 | 76 | |
@@ -87,11 +87,11 @@ discard block |
||
| 87 | 87 | private function copy(string $tmpDir, string $file): string |
| 88 | 88 | { |
| 89 | 89 | $source = ltrim($this->files->relativePath($file, $tmpDir), '\\/'); |
| 90 | - if (strpos($source, $this->baseNamespace) === 0) { |
|
| 90 | + if (strpos($source, $this->baseNamespace) === 0){ |
|
| 91 | 91 | $source = ltrim(substr($source, strlen($this->baseNamespace)), '\\/'); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - $target = $this->files->normalizePath($this->basePath . '/' . $source); |
|
| 94 | + $target = $this->files->normalizePath($this->basePath.'/'.$source); |
|
| 95 | 95 | |
| 96 | 96 | $this->files->ensureDirectory(dirname($target)); |
| 97 | 97 | $this->files->copy($file, $target); |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | private function tmpDir(): string |
| 106 | 106 | { |
| 107 | - $directory = sys_get_temp_dir() . '/' . spl_object_hash($this); |
|
| 107 | + $directory = sys_get_temp_dir().'/'.spl_object_hash($this); |
|
| 108 | 108 | $this->files->ensureDirectory($directory); |
| 109 | 109 | |
| 110 | 110 | return $this->files->normalizePath($directory, true); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | { |
| 121 | 121 | return array_filter( |
| 122 | 122 | $this->files->getFiles(dirname($protoFile)), |
| 123 | - function ($file) { |
|
| 123 | + function ($file){ |
|
| 124 | 124 | return strpos($file, '.proto') !== false; |
| 125 | 125 | } |
| 126 | 126 | ); |
@@ -63,14 +63,16 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | $output = trim(implode("\n", $output), "\n ,"); |
| 65 | 65 | |
| 66 | - if ($output !== '') { |
|
| 66 | + if ($output !== '') |
|
| 67 | + { |
|
| 67 | 68 | $this->files->deleteDirectory($tmpDir); |
| 68 | 69 | throw new CompileException($output); |
| 69 | 70 | } |
| 70 | 71 | |
| 71 | 72 | // copying files (using relative path and namespace) |
| 72 | 73 | $result = []; |
| 73 | - foreach ($this->files->getFiles($tmpDir) as $file) { |
|
| 74 | + foreach ($this->files->getFiles($tmpDir) as $file) |
|
| 75 | + { |
|
| 74 | 76 | $result[] = $this->copy($tmpDir, $file); |
| 75 | 77 | } |
| 76 | 78 | |
@@ -87,7 +89,8 @@ discard block |
||
| 87 | 89 | private function copy(string $tmpDir, string $file): string |
| 88 | 90 | { |
| 89 | 91 | $source = ltrim($this->files->relativePath($file, $tmpDir), '\\/'); |
| 90 | - if (strpos($source, $this->baseNamespace) === 0) { |
|
| 92 | + if (strpos($source, $this->baseNamespace) === 0) |
|
| 93 | + { |
|
| 91 | 94 | $source = ltrim(substr($source, strlen($this->baseNamespace)), '\\/'); |
| 92 | 95 | } |
| 93 | 96 | |
@@ -120,7 +123,8 @@ discard block |
||
| 120 | 123 | { |
| 121 | 124 | return array_filter( |
| 122 | 125 | $this->files->getFiles(dirname($protoFile)), |
| 123 | - function ($file) { |
|
| 126 | + function ($file) |
|
| 127 | + { |
|
| 124 | 128 | return strpos($file, '.proto') !== false; |
| 125 | 129 | } |
| 126 | 130 | ); |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | $this->output->writeln('<info>Detecting schema changes:</info>'); |
| 43 | 43 | |
| 44 | 44 | $this->changes = []; |
| 45 | - foreach ($registry->getIterator() as $e) { |
|
| 46 | - if ($registry->hasTable($e)) { |
|
| 45 | + foreach ($registry->getIterator() as $e){ |
|
| 46 | + if ($registry->hasTable($e)){ |
|
| 47 | 47 | $table = $registry->getTableSchema($e); |
| 48 | 48 | |
| 49 | - if ($table->getComparator()->hasChanges()) { |
|
| 49 | + if ($table->getComparator()->hasChanges()){ |
|
| 50 | 50 | $this->changes[] = [ |
| 51 | 51 | 'database' => $registry->getDatabase($e), |
| 52 | 52 | 'table' => $registry->getTable($e), |
@@ -56,13 +56,13 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - if ($this->changes === []) { |
|
| 59 | + if ($this->changes === []){ |
|
| 60 | 60 | $this->output->writeln('<fg=yellow>no database changes has been detected</fg=yellow>'); |
| 61 | 61 | |
| 62 | 62 | return $registry; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - foreach ($this->changes as $change) { |
|
| 65 | + foreach ($this->changes as $change){ |
|
| 66 | 66 | $this->output->write(sprintf('• <fg=cyan>%s.%s</fg=cyan>', $change['database'], $change['table'])); |
| 67 | 67 | $this->describeChanges($change['schema']); |
| 68 | 68 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | protected function describeChanges(AbstractTable $table): void |
| 85 | 85 | { |
| 86 | - if (!$this->output->isVerbose()) { |
|
| 86 | + if (!$this->output->isVerbose()){ |
|
| 87 | 87 | $this->output->writeln( |
| 88 | 88 | sprintf( |
| 89 | 89 | ': <fg=green>%s</fg=green> change(s) detected', |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | $this->output->write("\n"); |
| 97 | 97 | |
| 98 | 98 | |
| 99 | - if (!$table->exists()) { |
|
| 99 | + if (!$table->exists()){ |
|
| 100 | 100 | $this->output->writeln(' - create table'); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) { |
|
| 103 | + if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED){ |
|
| 104 | 104 | $this->output->writeln(' - drop table'); |
| 105 | 105 | return; |
| 106 | 106 | } |
@@ -117,15 +117,15 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | protected function describeColumns(Comparator $cmp): void |
| 119 | 119 | { |
| 120 | - foreach ($cmp->addedColumns() as $column) { |
|
| 120 | + foreach ($cmp->addedColumns() as $column){ |
|
| 121 | 121 | $this->output->writeln(" - add column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - foreach ($cmp->droppedColumns() as $column) { |
|
| 124 | + foreach ($cmp->droppedColumns() as $column){ |
|
| 125 | 125 | $this->output->writeln(" - drop column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - foreach ($cmp->alteredColumns() as $column) { |
|
| 128 | + foreach ($cmp->alteredColumns() as $column){ |
|
| 129 | 129 | $column = $column[0]; |
| 130 | 130 | $this->output->writeln(" - alter column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 131 | 131 | } |
@@ -136,17 +136,17 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | protected function describeIndexes(Comparator $cmp): void |
| 138 | 138 | { |
| 139 | - foreach ($cmp->addedIndexes() as $index) { |
|
| 139 | + foreach ($cmp->addedIndexes() as $index){ |
|
| 140 | 140 | $index = implode(', ', $index->getColumns()); |
| 141 | 141 | $this->output->writeln(" - add index on <fg=yellow>[{$index}]</fg=yellow>"); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - foreach ($cmp->droppedIndexes() as $index) { |
|
| 144 | + foreach ($cmp->droppedIndexes() as $index){ |
|
| 145 | 145 | $index = implode(', ', $index->getColumns()); |
| 146 | 146 | $this->output->writeln(" - drop index on <fg=yellow>[{$index}]</fg=yellow>"); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - foreach ($cmp->alteredIndexes() as $index) { |
|
| 149 | + foreach ($cmp->alteredIndexes() as $index){ |
|
| 150 | 150 | $index = $index[0]; |
| 151 | 151 | $index = implode(', ', $index->getColumns()); |
| 152 | 152 | $this->output->writeln(" - alter index on <fg=yellow>[{$index}]</fg=yellow>"); |
@@ -158,17 +158,17 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | protected function describeFKs(Comparator $cmp): void |
| 160 | 160 | { |
| 161 | - foreach ($cmp->addedForeignKeys() as $fk) { |
|
| 161 | + foreach ($cmp->addedForeignKeys() as $fk){ |
|
| 162 | 162 | $fkColumns = implode(', ', $fk->getColumns()); |
| 163 | 163 | $this->output->writeln(" - add foreign key on <fg=yellow>{$fkColumns}</fg=yellow>"); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - foreach ($cmp->droppedForeignKeys() as $fk) { |
|
| 166 | + foreach ($cmp->droppedForeignKeys() as $fk){ |
|
| 167 | 167 | $fkColumns = implode(', ', $fk->getColumns()); |
| 168 | 168 | $this->output->writeln(" - drop foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - foreach ($cmp->alteredForeignKeys() as $fk) { |
|
| 171 | + foreach ($cmp->alteredForeignKeys() as $fk){ |
|
| 172 | 172 | $fk = $fk[0]; |
| 173 | 173 | $fkColumns = implode(', ', $fk->getColumns()); |
| 174 | 174 | $this->output->writeln(" - alter foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
@@ -42,11 +42,14 @@ discard block |
||
| 42 | 42 | $this->output->writeln('<info>Detecting schema changes:</info>'); |
| 43 | 43 | |
| 44 | 44 | $this->changes = []; |
| 45 | - foreach ($registry->getIterator() as $e) { |
|
| 46 | - if ($registry->hasTable($e)) { |
|
| 45 | + foreach ($registry->getIterator() as $e) |
|
| 46 | + { |
|
| 47 | + if ($registry->hasTable($e)) |
|
| 48 | + { |
|
| 47 | 49 | $table = $registry->getTableSchema($e); |
| 48 | 50 | |
| 49 | - if ($table->getComparator()->hasChanges()) { |
|
| 51 | + if ($table->getComparator()->hasChanges()) |
|
| 52 | + { |
|
| 50 | 53 | $this->changes[] = [ |
| 51 | 54 | 'database' => $registry->getDatabase($e), |
| 52 | 55 | 'table' => $registry->getTable($e), |
@@ -56,13 +59,15 @@ discard block |
||
| 56 | 59 | } |
| 57 | 60 | } |
| 58 | 61 | |
| 59 | - if ($this->changes === []) { |
|
| 62 | + if ($this->changes === []) |
|
| 63 | + { |
|
| 60 | 64 | $this->output->writeln('<fg=yellow>no database changes has been detected</fg=yellow>'); |
| 61 | 65 | |
| 62 | 66 | return $registry; |
| 63 | 67 | } |
| 64 | 68 | |
| 65 | - foreach ($this->changes as $change) { |
|
| 69 | + foreach ($this->changes as $change) |
|
| 70 | + { |
|
| 66 | 71 | $this->output->write(sprintf('• <fg=cyan>%s.%s</fg=cyan>', $change['database'], $change['table'])); |
| 67 | 72 | $this->describeChanges($change['schema']); |
| 68 | 73 | } |
@@ -83,7 +88,8 @@ discard block |
||
| 83 | 88 | */ |
| 84 | 89 | protected function describeChanges(AbstractTable $table): void |
| 85 | 90 | { |
| 86 | - if (!$this->output->isVerbose()) { |
|
| 91 | + if (!$this->output->isVerbose()) |
|
| 92 | + { |
|
| 87 | 93 | $this->output->writeln( |
| 88 | 94 | sprintf( |
| 89 | 95 | ': <fg=green>%s</fg=green> change(s) detected', |
@@ -96,11 +102,13 @@ discard block |
||
| 96 | 102 | $this->output->write("\n"); |
| 97 | 103 | |
| 98 | 104 | |
| 99 | - if (!$table->exists()) { |
|
| 105 | + if (!$table->exists()) |
|
| 106 | + { |
|
| 100 | 107 | $this->output->writeln(' - create table'); |
| 101 | 108 | } |
| 102 | 109 | |
| 103 | - if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) { |
|
| 110 | + if ($table->getStatus() === AbstractTable::STATUS_DECLARED_DROPPED) |
|
| 111 | + { |
|
| 104 | 112 | $this->output->writeln(' - drop table'); |
| 105 | 113 | return; |
| 106 | 114 | } |
@@ -117,15 +125,18 @@ discard block |
||
| 117 | 125 | */ |
| 118 | 126 | protected function describeColumns(Comparator $cmp): void |
| 119 | 127 | { |
| 120 | - foreach ($cmp->addedColumns() as $column) { |
|
| 128 | + foreach ($cmp->addedColumns() as $column) |
|
| 129 | + { |
|
| 121 | 130 | $this->output->writeln(" - add column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 122 | 131 | } |
| 123 | 132 | |
| 124 | - foreach ($cmp->droppedColumns() as $column) { |
|
| 133 | + foreach ($cmp->droppedColumns() as $column) |
|
| 134 | + { |
|
| 125 | 135 | $this->output->writeln(" - drop column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 126 | 136 | } |
| 127 | 137 | |
| 128 | - foreach ($cmp->alteredColumns() as $column) { |
|
| 138 | + foreach ($cmp->alteredColumns() as $column) |
|
| 139 | + { |
|
| 129 | 140 | $column = $column[0]; |
| 130 | 141 | $this->output->writeln(" - alter column <fg=yellow>{$column->getName()}</fg=yellow>"); |
| 131 | 142 | } |
@@ -136,17 +147,20 @@ discard block |
||
| 136 | 147 | */ |
| 137 | 148 | protected function describeIndexes(Comparator $cmp): void |
| 138 | 149 | { |
| 139 | - foreach ($cmp->addedIndexes() as $index) { |
|
| 150 | + foreach ($cmp->addedIndexes() as $index) |
|
| 151 | + { |
|
| 140 | 152 | $index = implode(', ', $index->getColumns()); |
| 141 | 153 | $this->output->writeln(" - add index on <fg=yellow>[{$index}]</fg=yellow>"); |
| 142 | 154 | } |
| 143 | 155 | |
| 144 | - foreach ($cmp->droppedIndexes() as $index) { |
|
| 156 | + foreach ($cmp->droppedIndexes() as $index) |
|
| 157 | + { |
|
| 145 | 158 | $index = implode(', ', $index->getColumns()); |
| 146 | 159 | $this->output->writeln(" - drop index on <fg=yellow>[{$index}]</fg=yellow>"); |
| 147 | 160 | } |
| 148 | 161 | |
| 149 | - foreach ($cmp->alteredIndexes() as $index) { |
|
| 162 | + foreach ($cmp->alteredIndexes() as $index) |
|
| 163 | + { |
|
| 150 | 164 | $index = $index[0]; |
| 151 | 165 | $index = implode(', ', $index->getColumns()); |
| 152 | 166 | $this->output->writeln(" - alter index on <fg=yellow>[{$index}]</fg=yellow>"); |
@@ -158,17 +172,20 @@ discard block |
||
| 158 | 172 | */ |
| 159 | 173 | protected function describeFKs(Comparator $cmp): void |
| 160 | 174 | { |
| 161 | - foreach ($cmp->addedForeignKeys() as $fk) { |
|
| 175 | + foreach ($cmp->addedForeignKeys() as $fk) |
|
| 176 | + { |
|
| 162 | 177 | $fkColumns = implode(', ', $fk->getColumns()); |
| 163 | 178 | $this->output->writeln(" - add foreign key on <fg=yellow>{$fkColumns}</fg=yellow>"); |
| 164 | 179 | } |
| 165 | 180 | |
| 166 | - foreach ($cmp->droppedForeignKeys() as $fk) { |
|
| 181 | + foreach ($cmp->droppedForeignKeys() as $fk) |
|
| 182 | + { |
|
| 167 | 183 | $fkColumns = implode(', ', $fk->getColumns()); |
| 168 | 184 | $this->output->writeln(" - drop foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
| 169 | 185 | } |
| 170 | 186 | |
| 171 | - foreach ($cmp->alteredForeignKeys() as $fk) { |
|
| 187 | + foreach ($cmp->alteredForeignKeys() as $fk) |
|
| 188 | + { |
|
| 172 | 189 | $fk = $fk[0]; |
| 173 | 190 | $fkColumns = implode(', ', $fk->getColumns()); |
| 174 | 191 | $this->output->writeln(" - alter foreign key <fg=yellow>{$fkColumns}</fg=yellow>"); |
@@ -39,7 +39,8 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function perform(TranslatorConfig $config, CatalogueManager $manager): void |
| 41 | 41 | { |
| 42 | - if (!$config->hasDumper($this->option('dumper'))) { |
|
| 42 | + if (!$config->hasDumper($this->option('dumper'))) |
|
| 43 | + { |
|
| 43 | 44 | $this->writeln("<fg=red>Undefined dumper '{$this->option('dumper')}'.</fg=red>"); |
| 44 | 45 | |
| 45 | 46 | return; |
@@ -51,7 +52,8 @@ discard block |
||
| 51 | 52 | $manager->get($this->argument('locale')) |
| 52 | 53 | ); |
| 53 | 54 | |
| 54 | - if ($this->isVerbose() && !empty($mc->getDomains())) { |
|
| 55 | + if ($this->isVerbose() && !empty($mc->getDomains())) |
|
| 56 | + { |
|
| 55 | 57 | $this->sprintf( |
| 56 | 58 | "<info>Exporting domain(s):</info> %s\n", |
| 57 | 59 | implode(',', $mc->getDomains()) |
@@ -89,10 +91,14 @@ discard block |
||
| 89 | 91 | $catalogue->getData() |
| 90 | 92 | ); |
| 91 | 93 | |
| 92 | - if ($this->option('fallback')) { |
|
| 93 | - foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages) { |
|
| 94 | - foreach ($messages as $id => $message) { |
|
| 95 | - if (!$messageCatalogue->defines($id, $domain)) { |
|
| 94 | + if ($this->option('fallback')) |
|
| 95 | + { |
|
| 96 | + foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages) |
|
| 97 | + { |
|
| 98 | + foreach ($messages as $id => $message) |
|
| 99 | + { |
|
| 100 | + if (!$messageCatalogue->defines($id, $domain)) |
|
| 101 | + { |
|
| 96 | 102 | $messageCatalogue->set($id, $message, $domain); |
| 97 | 103 | } |
| 98 | 104 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | ['locale', InputArgument::REQUIRED, 'Locale to be dumped'], |
| 29 | 29 | ['path', InputArgument::REQUIRED, 'Export path'], |
| 30 | 30 | ]; |
| 31 | - protected const OPTIONS = [ |
|
| 31 | + protected const OPTIONS = [ |
|
| 32 | 32 | ['dumper', 'd', InputOption::VALUE_OPTIONAL, 'Dumper name', 'php'], |
| 33 | 33 | ['fallback', 'f', InputOption::VALUE_NONE, 'Merge messages from fallback catalogue'], |
| 34 | 34 | ]; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function perform(TranslatorConfig $config, CatalogueManager $manager): void |
| 41 | 41 | { |
| 42 | - if (!$config->hasDumper($this->option('dumper'))) { |
|
| 42 | + if (!$config->hasDumper($this->option('dumper'))){ |
|
| 43 | 43 | $this->writeln("<fg=red>Undefined dumper '{$this->option('dumper')}'.</fg=red>"); |
| 44 | 44 | |
| 45 | 45 | return; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $manager->get($this->argument('locale')) |
| 52 | 52 | ); |
| 53 | 53 | |
| 54 | - if ($this->isVerbose() && !empty($mc->getDomains())) { |
|
| 54 | + if ($this->isVerbose() && !empty($mc->getDomains())){ |
|
| 55 | 55 | $this->sprintf( |
| 56 | 56 | "<info>Exporting domain(s):</info> %s\n", |
| 57 | 57 | implode(',', $mc->getDomains()) |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | ] |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | - $this->writeln('Export successfully completed using <info>' . get_class($dumper) . '</info>'); |
|
| 73 | - $this->writeln('Output: <comment>' . realpath($this->argument('path')) . '</comment>'); |
|
| 72 | + $this->writeln('Export successfully completed using <info>'.get_class($dumper).'</info>'); |
|
| 73 | + $this->writeln('Output: <comment>'.realpath($this->argument('path')).'</comment>'); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | $catalogue->getData() |
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | - if ($this->option('fallback')) { |
|
| 93 | - foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages) { |
|
| 94 | - foreach ($messages as $id => $message) { |
|
| 95 | - if (!$messageCatalogue->defines($id, $domain)) { |
|
| 92 | + if ($this->option('fallback')){ |
|
| 93 | + foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages){ |
|
| 94 | + foreach ($messages as $id => $message){ |
|
| 95 | + if (!$messageCatalogue->defines($id, $domain)){ |
|
| 96 | 96 | $messageCatalogue->set($id, $message, $domain); |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | $response = new Response('php://memory', $code, []); |
| 38 | 38 | $response = $response->withStatus($code, $reasonPhrase); |
| 39 | 39 | |
| 40 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
| 40 | + foreach ($this->config->getBaseHeaders() as $header => $value){ |
|
| 41 | 41 | $response = $response->withAddedHeader($header, $value); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -37,7 +37,8 @@ |
||
| 37 | 37 | $response = new Response('php://memory', $code, []); |
| 38 | 38 | $response = $response->withStatus($code, $reasonPhrase); |
| 39 | 39 | |
| 40 | - foreach ($this->config->getBaseHeaders() as $header => $value) { |
|
| 40 | + foreach ($this->config->getBaseHeaders() as $header => $value) |
|
| 41 | + { |
|
| 41 | 42 | $response = $response->withAddedHeader($header, $value); |
| 42 | 43 | } |
| 43 | 44 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $core = $this->httpCore([CsrfMiddleware::class]); |
| 54 | 54 | $core->setHandler( |
| 55 | - static function ($r) { |
|
| 55 | + static function ($r){ |
|
| 56 | 56 | return $r->getAttribute(CsrfMiddleware::ATTRIBUTE); |
| 57 | 57 | } |
| 58 | 58 | ); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | $core = $this->httpCore([CsrfMiddleware::class]); |
| 84 | 84 | $core->setHandler( |
| 85 | - static function () { |
|
| 85 | + static function (){ |
|
| 86 | 86 | return 'all good'; |
| 87 | 87 | } |
| 88 | 88 | ); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | { |
| 95 | 95 | $core = $this->httpCore([CsrfMiddleware::class, CsrfFirewall::class]); |
| 96 | 96 | $core->setHandler( |
| 97 | - static function () { |
|
| 97 | + static function (){ |
|
| 98 | 98 | return 'all good'; |
| 99 | 99 | } |
| 100 | 100 | ); |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $this->expectException(\LogicException::class); |
| 109 | 109 | $core = $this->httpCore([CsrfFirewall::class]); |
| 110 | 110 | $core->setHandler( |
| 111 | - static function () { |
|
| 111 | + static function (){ |
|
| 112 | 112 | return 'all good'; |
| 113 | 113 | } |
| 114 | 114 | ); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | { |
| 121 | 121 | $core = $this->httpCore([CsrfMiddleware::class, CsrfFirewall::class]); |
| 122 | 122 | $core->setHandler( |
| 123 | - static function () { |
|
| 123 | + static function (){ |
|
| 124 | 124 | return 'all good'; |
| 125 | 125 | } |
| 126 | 126 | ); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | { |
| 154 | 154 | $core = $this->httpCore([CsrfMiddleware::class, CsrfFirewall::class]); |
| 155 | 155 | $core->setHandler( |
| 156 | - static function () { |
|
| 156 | + static function (){ |
|
| 157 | 157 | return 'all good'; |
| 158 | 158 | } |
| 159 | 159 | ); |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | { |
| 187 | 187 | $core = $this->httpCore([CsrfMiddleware::class, StrictCsrfFirewall::class]); |
| 188 | 188 | $core->setHandler( |
| 189 | - static function () { |
|
| 189 | + static function (){ |
|
| 190 | 190 | return 'all good'; |
| 191 | 191 | } |
| 192 | 192 | ); |
@@ -277,10 +277,10 @@ discard block |
||
| 277 | 277 | { |
| 278 | 278 | $result = []; |
| 279 | 279 | |
| 280 | - foreach ($response->getHeaders() as $header) { |
|
| 281 | - foreach ($header as $headerLine) { |
|
| 280 | + foreach ($response->getHeaders() as $header){ |
|
| 281 | + foreach ($header as $headerLine){ |
|
| 282 | 282 | $chunk = explode(';', $headerLine); |
| 283 | - if (!count($chunk) || mb_strpos($chunk[0], '=') === false) { |
|
| 283 | + if (!count($chunk) || mb_strpos($chunk[0], '=') === false){ |
|
| 284 | 284 | continue; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -52,7 +52,8 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $core = $this->httpCore([CsrfMiddleware::class]); |
| 54 | 54 | $core->setHandler( |
| 55 | - static function ($r) { |
|
| 55 | + static function ($r) |
|
| 56 | + { |
|
| 56 | 57 | return $r->getAttribute(CsrfMiddleware::ATTRIBUTE); |
| 57 | 58 | } |
| 58 | 59 | ); |
@@ -82,7 +83,8 @@ discard block |
||
| 82 | 83 | |
| 83 | 84 | $core = $this->httpCore([CsrfMiddleware::class]); |
| 84 | 85 | $core->setHandler( |
| 85 | - static function () { |
|
| 86 | + static function () |
|
| 87 | + { |
|
| 86 | 88 | return 'all good'; |
| 87 | 89 | } |
| 88 | 90 | ); |
@@ -94,7 +96,8 @@ discard block |
||
| 94 | 96 | { |
| 95 | 97 | $core = $this->httpCore([CsrfMiddleware::class, CsrfFirewall::class]); |
| 96 | 98 | $core->setHandler( |
| 97 | - static function () { |
|
| 99 | + static function () |
|
| 100 | + { |
|
| 98 | 101 | return 'all good'; |
| 99 | 102 | } |
| 100 | 103 | ); |
@@ -108,7 +111,8 @@ discard block |
||
| 108 | 111 | $this->expectException(\LogicException::class); |
| 109 | 112 | $core = $this->httpCore([CsrfFirewall::class]); |
| 110 | 113 | $core->setHandler( |
| 111 | - static function () { |
|
| 114 | + static function () |
|
| 115 | + { |
|
| 112 | 116 | return 'all good'; |
| 113 | 117 | } |
| 114 | 118 | ); |
@@ -120,7 +124,8 @@ discard block |
||
| 120 | 124 | { |
| 121 | 125 | $core = $this->httpCore([CsrfMiddleware::class, CsrfFirewall::class]); |
| 122 | 126 | $core->setHandler( |
| 123 | - static function () { |
|
| 127 | + static function () |
|
| 128 | + { |
|
| 124 | 129 | return 'all good'; |
| 125 | 130 | } |
| 126 | 131 | ); |
@@ -153,7 +158,8 @@ discard block |
||
| 153 | 158 | { |
| 154 | 159 | $core = $this->httpCore([CsrfMiddleware::class, CsrfFirewall::class]); |
| 155 | 160 | $core->setHandler( |
| 156 | - static function () { |
|
| 161 | + static function () |
|
| 162 | + { |
|
| 157 | 163 | return 'all good'; |
| 158 | 164 | } |
| 159 | 165 | ); |
@@ -186,7 +192,8 @@ discard block |
||
| 186 | 192 | { |
| 187 | 193 | $core = $this->httpCore([CsrfMiddleware::class, StrictCsrfFirewall::class]); |
| 188 | 194 | $core->setHandler( |
| 189 | - static function () { |
|
| 195 | + static function () |
|
| 196 | + { |
|
| 190 | 197 | return 'all good'; |
| 191 | 198 | } |
| 192 | 199 | ); |
@@ -277,10 +284,13 @@ discard block |
||
| 277 | 284 | { |
| 278 | 285 | $result = []; |
| 279 | 286 | |
| 280 | - foreach ($response->getHeaders() as $header) { |
|
| 281 | - foreach ($header as $headerLine) { |
|
| 287 | + foreach ($response->getHeaders() as $header) |
|
| 288 | + { |
|
| 289 | + foreach ($header as $headerLine) |
|
| 290 | + { |
|
| 282 | 291 | $chunk = explode(';', $headerLine); |
| 283 | - if (!count($chunk) || mb_strpos($chunk[0], '=') === false) { |
|
| 292 | + if (!count($chunk) || mb_strpos($chunk[0], '=') === false) |
|
| 293 | + { |
|
| 284 | 294 | continue; |
| 285 | 295 | } |
| 286 | 296 | |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function process(Request $request, RequestHandlerInterface $handler): Response |
| 48 | 48 | { |
| 49 | - if (isset($request->getCookieParams()[$this->config->getCookie()])) { |
|
| 49 | + if (isset($request->getCookieParams()[$this->config->getCookie()])){ |
|
| 50 | 50 | $token = $request->getCookieParams()[$this->config->getCookie()]; |
| 51 | - } else { |
|
| 51 | + }else{ |
|
| 52 | 52 | //Making new token |
| 53 | 53 | $token = $this->random($this->config->getTokenLength()); |
| 54 | 54 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | //CSRF issues must be handled by Firewall middleware |
| 60 | 60 | $response = $handler->handle($request->withAttribute(static::ATTRIBUTE, $token)); |
| 61 | 61 | |
| 62 | - if (!empty($cookie)) { |
|
| 62 | + if (!empty($cookie)){ |
|
| 63 | 63 | return $response->withAddedHeader('Set-Cookie', $cookie); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | private function random(int $length = 32): string |
| 96 | 96 | { |
| 97 | - try { |
|
| 98 | - if (empty($string = random_bytes($length))) { |
|
| 97 | + try{ |
|
| 98 | + if (empty($string = random_bytes($length))){ |
|
| 99 | 99 | throw new \RuntimeException('Unable to generate random string'); |
| 100 | 100 | } |
| 101 | - } catch (\Throwable $e) { |
|
| 101 | + }catch (\Throwable $e){ |
|
| 102 | 102 | throw new \RuntimeException('Unable to generate random string', $e->getCode(), $e); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -46,9 +46,12 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function process(Request $request, RequestHandlerInterface $handler): Response |
| 48 | 48 | { |
| 49 | - if (isset($request->getCookieParams()[$this->config->getCookie()])) { |
|
| 49 | + if (isset($request->getCookieParams()[$this->config->getCookie()])) |
|
| 50 | + { |
|
| 50 | 51 | $token = $request->getCookieParams()[$this->config->getCookie()]; |
| 51 | - } else { |
|
| 52 | + } |
|
| 53 | + else |
|
| 54 | + { |
|
| 52 | 55 | //Making new token |
| 53 | 56 | $token = $this->random($this->config->getTokenLength()); |
| 54 | 57 | |
@@ -59,7 +62,8 @@ discard block |
||
| 59 | 62 | //CSRF issues must be handled by Firewall middleware |
| 60 | 63 | $response = $handler->handle($request->withAttribute(static::ATTRIBUTE, $token)); |
| 61 | 64 | |
| 62 | - if (!empty($cookie)) { |
|
| 65 | + if (!empty($cookie)) |
|
| 66 | + { |
|
| 63 | 67 | return $response->withAddedHeader('Set-Cookie', $cookie); |
| 64 | 68 | } |
| 65 | 69 | |
@@ -94,11 +98,15 @@ discard block |
||
| 94 | 98 | */ |
| 95 | 99 | private function random(int $length = 32): string |
| 96 | 100 | { |
| 97 | - try { |
|
| 98 | - if (empty($string = random_bytes($length))) { |
|
| 101 | + try |
|
| 102 | + { |
|
| 103 | + if (empty($string = random_bytes($length))) |
|
| 104 | + { |
|
| 99 | 105 | throw new \RuntimeException('Unable to generate random string'); |
| 100 | 106 | } |
| 101 | - } catch (\Throwable $e) { |
|
| 107 | + } |
|
| 108 | + catch (\Throwable $e) |
|
| 109 | + { |
|
| 102 | 110 | throw new \RuntimeException('Unable to generate random string', $e->getCode(), $e); |
| 103 | 111 | } |
| 104 | 112 | |