@@ -19,27 +19,27 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct( |
21 | 21 | private readonly SessionScope $session, |
22 | - ) {} |
|
22 | + ){} |
|
23 | 23 | |
24 | 24 | public function load(string $id): ?TokenInterface |
25 | 25 | { |
26 | - try { |
|
26 | + try{ |
|
27 | 27 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
28 | - if ($tokenData === null) { |
|
28 | + if ($tokenData === null){ |
|
29 | 29 | return null; |
30 | 30 | } |
31 | 31 | |
32 | 32 | $token = Token::unpack($tokenData); |
33 | - } catch (\Throwable $e) { |
|
34 | - throw new TokenStorageException('Unable to load session token', (int) $e->getCode(), $e); |
|
33 | + }catch (\Throwable $e){ |
|
34 | + throw new TokenStorageException('Unable to load session token', (int)$e->getCode(), $e); |
|
35 | 35 | } |
36 | 36 | |
37 | - if (!\hash_equals($token->getID(), $id)) { |
|
37 | + if (!\hash_equals($token->getID(), $id)){ |
|
38 | 38 | return null; |
39 | 39 | } |
40 | 40 | |
41 | 41 | $expiresAt = $token->getExpiresAt(); |
42 | - if ($expiresAt !== null && $expiresAt < new \DateTimeImmutable()) { |
|
42 | + if ($expiresAt !== null && $expiresAt < new \DateTimeImmutable()){ |
|
43 | 43 | $this->delete($token); |
44 | 44 | return null; |
45 | 45 | } |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | |
50 | 50 | public function create(array $payload, ?\DateTimeInterface $expiresAt = null): TokenInterface |
51 | 51 | { |
52 | - try { |
|
52 | + try{ |
|
53 | 53 | $token = new Token($this->randomHash(128), $payload, $expiresAt); |
54 | 54 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
55 | 55 | |
56 | 56 | return $token; |
57 | - } catch (\Throwable $e) { |
|
58 | - throw new TokenStorageException('Unable to create session token', (int) $e->getCode(), $e); |
|
57 | + }catch (\Throwable $e){ |
|
58 | + throw new TokenStorageException('Unable to create session token', (int)$e->getCode(), $e); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 |
@@ -19,27 +19,34 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct( |
21 | 21 | private readonly SessionScope $session, |
22 | - ) {} |
|
22 | + ) { |
|
23 | +} |
|
23 | 24 | |
24 | 25 | public function load(string $id): ?TokenInterface |
25 | 26 | { |
26 | - try { |
|
27 | + try |
|
28 | + { |
|
27 | 29 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
28 | - if ($tokenData === null) { |
|
30 | + if ($tokenData === null) |
|
31 | + { |
|
29 | 32 | return null; |
30 | 33 | } |
31 | 34 | |
32 | 35 | $token = Token::unpack($tokenData); |
33 | - } catch (\Throwable $e) { |
|
36 | + } |
|
37 | + catch (\Throwable $e) |
|
38 | + { |
|
34 | 39 | throw new TokenStorageException('Unable to load session token', (int) $e->getCode(), $e); |
35 | 40 | } |
36 | 41 | |
37 | - if (!\hash_equals($token->getID(), $id)) { |
|
42 | + if (!\hash_equals($token->getID(), $id)) |
|
43 | + { |
|
38 | 44 | return null; |
39 | 45 | } |
40 | 46 | |
41 | 47 | $expiresAt = $token->getExpiresAt(); |
42 | - if ($expiresAt !== null && $expiresAt < new \DateTimeImmutable()) { |
|
48 | + if ($expiresAt !== null && $expiresAt < new \DateTimeImmutable()) |
|
49 | + { |
|
43 | 50 | $this->delete($token); |
44 | 51 | return null; |
45 | 52 | } |
@@ -49,12 +56,15 @@ discard block |
||
49 | 56 | |
50 | 57 | public function create(array $payload, ?\DateTimeInterface $expiresAt = null): TokenInterface |
51 | 58 | { |
52 | - try { |
|
59 | + try |
|
60 | + { |
|
53 | 61 | $token = new Token($this->randomHash(128), $payload, $expiresAt); |
54 | 62 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
55 | 63 | |
56 | 64 | return $token; |
57 | - } catch (\Throwable $e) { |
|
65 | + } |
|
66 | + catch (\Throwable $e) |
|
67 | + { |
|
58 | 68 | throw new TokenStorageException('Unable to create session token', (int) $e->getCode(), $e); |
59 | 69 | } |
60 | 70 | } |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | public function __construct( |
12 | 12 | private readonly string $id, |
13 | 13 | private readonly array $payload, |
14 | - private readonly ?\DateTimeInterface $expiresAt = null, |
|
15 | - ) {} |
|
14 | + private readonly ? \DateTimeInterface $expiresAt = null, |
|
15 | + ){} |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Unpack token from serialized data. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | public static function unpack(array $data): Token |
23 | 23 | { |
24 | 24 | $expiresAt = null; |
25 | - if ($data['expiresAt'] !== null) { |
|
25 | + if ($data['expiresAt'] !== null){ |
|
26 | 26 | $expiresAt = (new \DateTimeImmutable())->setTimestamp($data['expiresAt']); |
27 | 27 | } |
28 | 28 |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | private readonly string $id, |
13 | 13 | private readonly array $payload, |
14 | 14 | private readonly ?\DateTimeInterface $expiresAt = null, |
15 | - ) {} |
|
15 | + ) { |
|
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Unpack token from serialized data. |
@@ -22,7 +23,8 @@ discard block |
||
22 | 23 | public static function unpack(array $data): Token |
23 | 24 | { |
24 | 25 | $expiresAt = null; |
25 | - if ($data['expiresAt'] !== null) { |
|
26 | + if ($data['expiresAt'] !== null) |
|
27 | + { |
|
26 | 28 | $expiresAt = (new \DateTimeImmutable())->setTimestamp($data['expiresAt']); |
27 | 29 | } |
28 | 30 |
@@ -41,9 +41,9 @@ |
||
41 | 41 | * @return TokenStorageInterface|class-string<TokenStorageInterface>|Autowire |
42 | 42 | * @throws InvalidArgumentException |
43 | 43 | */ |
44 | - public function getStorage(string $name): TokenStorageInterface|string|Autowire |
|
44 | + public function getStorage(string $name): TokenStorageInterface | string | Autowire |
|
45 | 45 | { |
46 | - if (!isset($this->config['storages'][$name])) { |
|
46 | + if (!isset($this->config['storages'][$name])){ |
|
47 | 47 | throw new InvalidArgumentException( |
48 | 48 | \sprintf('Token storage `%s` is not defined.', $name), |
49 | 49 | ); |
@@ -43,7 +43,8 @@ |
||
43 | 43 | */ |
44 | 44 | public function getStorage(string $name): TokenStorageInterface|string|Autowire |
45 | 45 | { |
46 | - if (!isset($this->config['storages'][$name])) { |
|
46 | + if (!isset($this->config['storages'][$name])) |
|
47 | + { |
|
47 | 48 | throw new InvalidArgumentException( |
48 | 49 | \sprintf('Token storage `%s` is not defined.', $name), |
49 | 50 | ); |
@@ -4,4 +4,4 @@ |
||
4 | 4 | |
5 | 5 | namespace Spiral\Auth\Exception; |
6 | 6 | |
7 | -class InvalidArgumentException extends AuthException {} |
|
7 | +class InvalidArgumentException extends AuthException{} |
@@ -4,4 +4,6 @@ |
||
4 | 4 | |
5 | 5 | namespace Spiral\Auth\Exception; |
6 | 6 | |
7 | -class InvalidArgumentException extends AuthException {} |
|
7 | +class InvalidArgumentException extends AuthException |
|
8 | +{ |
|
9 | +} |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | { |
18 | 18 | public function __construct( |
19 | 19 | #[Proxy] private readonly ContainerInterface $container, |
20 | - ) {} |
|
20 | + ){} |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @throws ScopeException |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | |
70 | 70 | private function getAuthContext(): AuthContextInterface |
71 | 71 | { |
72 | - try { |
|
72 | + try{ |
|
73 | 73 | return $this->container->get(AuthContextInterface::class); |
74 | - } catch (NotFoundExceptionInterface $e) { |
|
74 | + }catch (NotFoundExceptionInterface $e){ |
|
75 | 75 | throw new ScopeException('Unable to resolve auth context, invalid scope', $e->getCode(), $e); |
76 | 76 | } |
77 | 77 | } |
@@ -17,7 +17,8 @@ discard block |
||
17 | 17 | { |
18 | 18 | public function __construct( |
19 | 19 | #[Proxy] private readonly ContainerInterface $container, |
20 | - ) {} |
|
20 | + ) { |
|
21 | +} |
|
21 | 22 | |
22 | 23 | /** |
23 | 24 | * @throws ScopeException |
@@ -69,9 +70,12 @@ discard block |
||
69 | 70 | |
70 | 71 | private function getAuthContext(): AuthContextInterface |
71 | 72 | { |
72 | - try { |
|
73 | + try |
|
74 | + { |
|
73 | 75 | return $this->container->get(AuthContextInterface::class); |
74 | - } catch (NotFoundExceptionInterface $e) { |
|
76 | + } |
|
77 | + catch (NotFoundExceptionInterface $e) |
|
78 | + { |
|
75 | 79 | throw new ScopeException('Unable to resolve auth context, invalid scope', $e->getCode(), $e); |
76 | 80 | } |
77 | 81 | } |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | ): int { |
22 | 22 | $this->info('Included directories:'); |
23 | 23 | $grid = $this->table(['Directory', 'Scope']); |
24 | - foreach ($config->getDirectories() as $directory) { |
|
24 | + foreach ($config->getDirectories() as $directory){ |
|
25 | 25 | $grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']); |
26 | 26 | } |
27 | - foreach ($config->getScopes() as $scope => $data) { |
|
28 | - foreach ($data['directories'] ?? [] as $directory) { |
|
27 | + foreach ($config->getScopes() as $scope => $data){ |
|
28 | + foreach ($data['directories'] ?? [] as $directory){ |
|
29 | 29 | $grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]); |
30 | 30 | } |
31 | 31 | } |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | |
37 | 37 | $this->info('Excluded directories:'); |
38 | 38 | $grid = $this->table(['Directory', 'Scope']); |
39 | - foreach ($config->getExcludes() as $directory) { |
|
39 | + foreach ($config->getExcludes() as $directory){ |
|
40 | 40 | $grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']); |
41 | 41 | } |
42 | - foreach ($config->getScopes() as $scope => $data) { |
|
43 | - foreach ($data['exclude'] ?? [] as $directory) { |
|
42 | + foreach ($config->getScopes() as $scope => $data){ |
|
43 | + foreach ($data['exclude'] ?? [] as $directory){ |
|
44 | 44 | $grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]); |
45 | 45 | } |
46 | 46 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | $this->info('Listeners:'); |
76 | 76 | $grid = $this->table(['Registered Listener', 'File']); |
77 | - foreach ($listeners as $listener) { |
|
77 | + foreach ($listeners as $listener){ |
|
78 | 78 | $grid->addRow([ |
79 | 79 | $listener, |
80 | 80 | \str_replace([$dirs->get('root'), '\\'], ['', '/'], (new \ReflectionClass($listener))->getFileName()), |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $this->info( |
90 | 90 | \sprintf('Tokenizer cache: %s', $config->isCacheEnabled() ? '<info>enabled</>' : '<error>disabled</>'), |
91 | 91 | ); |
92 | - if (!$config->isCacheEnabled()) { |
|
92 | + if (!$config->isCacheEnabled()){ |
|
93 | 93 | $this->comment('To enable cache, add "TOKENIZER_CACHE_TARGETS=true" to your .env file.'); |
94 | 94 | $this->comment('Read more at https://spiral.dev/docs/advanced-tokenizer/#class-listeners'); |
95 | 95 | } |
@@ -21,11 +21,14 @@ discard block |
||
21 | 21 | ): int { |
22 | 22 | $this->info('Included directories:'); |
23 | 23 | $grid = $this->table(['Directory', 'Scope']); |
24 | - foreach ($config->getDirectories() as $directory) { |
|
24 | + foreach ($config->getDirectories() as $directory) |
|
25 | + { |
|
25 | 26 | $grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']); |
26 | 27 | } |
27 | - foreach ($config->getScopes() as $scope => $data) { |
|
28 | - foreach ($data['directories'] ?? [] as $directory) { |
|
28 | + foreach ($config->getScopes() as $scope => $data) |
|
29 | + { |
|
30 | + foreach ($data['directories'] ?? [] as $directory) |
|
31 | + { |
|
29 | 32 | $grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]); |
30 | 33 | } |
31 | 34 | } |
@@ -36,11 +39,14 @@ discard block |
||
36 | 39 | |
37 | 40 | $this->info('Excluded directories:'); |
38 | 41 | $grid = $this->table(['Directory', 'Scope']); |
39 | - foreach ($config->getExcludes() as $directory) { |
|
42 | + foreach ($config->getExcludes() as $directory) |
|
43 | + { |
|
40 | 44 | $grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']); |
41 | 45 | } |
42 | - foreach ($config->getScopes() as $scope => $data) { |
|
43 | - foreach ($data['exclude'] ?? [] as $directory) { |
|
46 | + foreach ($config->getScopes() as $scope => $data) |
|
47 | + { |
|
48 | + foreach ($data['exclude'] ?? [] as $directory) |
|
49 | + { |
|
44 | 50 | $grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]); |
45 | 51 | } |
46 | 52 | } |
@@ -74,7 +80,8 @@ discard block |
||
74 | 80 | |
75 | 81 | $this->info('Listeners:'); |
76 | 82 | $grid = $this->table(['Registered Listener', 'File']); |
77 | - foreach ($listeners as $listener) { |
|
83 | + foreach ($listeners as $listener) |
|
84 | + { |
|
78 | 85 | $grid->addRow([ |
79 | 86 | $listener, |
80 | 87 | \str_replace([$dirs->get('root'), '\\'], ['', '/'], (new \ReflectionClass($listener))->getFileName()), |
@@ -89,7 +96,8 @@ discard block |
||
89 | 96 | $this->info( |
90 | 97 | \sprintf('Tokenizer cache: %s', $config->isCacheEnabled() ? '<info>enabled</>' : '<error>disabled</>'), |
91 | 98 | ); |
92 | - if (!$config->isCacheEnabled()) { |
|
99 | + if (!$config->isCacheEnabled()) |
|
100 | + { |
|
93 | 101 | $this->comment('To enable cache, add "TOKENIZER_CACHE_TARGETS=true" to your .env file.'); |
94 | 102 | $this->comment('Read more at https://spiral.dev/docs/advanced-tokenizer/#class-listeners'); |
95 | 103 | } |
@@ -31,14 +31,14 @@ discard block |
||
31 | 31 | ['locale', InputArgument::REQUIRED, 'Locale to be dumped'], |
32 | 32 | ['path', InputArgument::REQUIRED, 'Export path'], |
33 | 33 | ]; |
34 | - protected const OPTIONS = [ |
|
34 | + protected const OPTIONS = [ |
|
35 | 35 | ['dumper', 'd', InputOption::VALUE_OPTIONAL, 'Dumper name', 'php'], |
36 | 36 | ['fallback', 'f', InputOption::VALUE_NONE, 'Merge messages from fallback catalogue'], |
37 | 37 | ]; |
38 | 38 | |
39 | 39 | public function perform(TranslatorConfig $config, CatalogueManager $manager): int |
40 | 40 | { |
41 | - if (!$config->hasDumper($this->option('dumper'))) { |
|
41 | + if (!$config->hasDumper($this->option('dumper'))){ |
|
42 | 42 | $this->writeln("<fg=red>Undefined dumper '{$this->option('dumper')}'.</fg=red>"); |
43 | 43 | |
44 | 44 | return self::FAILURE; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $manager->get($this->argument('locale')), |
51 | 51 | ); |
52 | 52 | |
53 | - if ($this->isVerbose() && !empty($mc->getDomains())) { |
|
53 | + if ($this->isVerbose() && !empty($mc->getDomains())){ |
|
54 | 54 | $this->sprintf( |
55 | 55 | "<info>Exporting domain(s):</info> %s\n", |
56 | 56 | \implode(',', $mc->getDomains()), |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | ], |
69 | 69 | ); |
70 | 70 | |
71 | - $this->writeln('Export successfully completed using <info>' . $dumper::class . '</info>'); |
|
72 | - $this->writeln('Output: <comment>' . \realpath($this->argument('path')) . '</comment>'); |
|
71 | + $this->writeln('Export successfully completed using <info>'.$dumper::class.'</info>'); |
|
72 | + $this->writeln('Output: <comment>'.\realpath($this->argument('path')).'</comment>'); |
|
73 | 73 | |
74 | 74 | return self::SUCCESS; |
75 | 75 | } |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | $catalogue->getData(), |
85 | 85 | ); |
86 | 86 | |
87 | - if ($this->option('fallback')) { |
|
88 | - foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages) { |
|
89 | - foreach ($messages as $id => $message) { |
|
90 | - if (!$messageCatalogue->defines($id, $domain)) { |
|
87 | + if ($this->option('fallback')){ |
|
88 | + foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages){ |
|
89 | + foreach ($messages as $id => $message){ |
|
90 | + if (!$messageCatalogue->defines($id, $domain)){ |
|
91 | 91 | $messageCatalogue->set($id, $message, $domain); |
92 | 92 | } |
93 | 93 | } |
@@ -38,7 +38,8 @@ discard block |
||
38 | 38 | |
39 | 39 | public function perform(TranslatorConfig $config, CatalogueManager $manager): int |
40 | 40 | { |
41 | - if (!$config->hasDumper($this->option('dumper'))) { |
|
41 | + if (!$config->hasDumper($this->option('dumper'))) |
|
42 | + { |
|
42 | 43 | $this->writeln("<fg=red>Undefined dumper '{$this->option('dumper')}'.</fg=red>"); |
43 | 44 | |
44 | 45 | return self::FAILURE; |
@@ -50,7 +51,8 @@ discard block |
||
50 | 51 | $manager->get($this->argument('locale')), |
51 | 52 | ); |
52 | 53 | |
53 | - if ($this->isVerbose() && !empty($mc->getDomains())) { |
|
54 | + if ($this->isVerbose() && !empty($mc->getDomains())) |
|
55 | + { |
|
54 | 56 | $this->sprintf( |
55 | 57 | "<info>Exporting domain(s):</info> %s\n", |
56 | 58 | \implode(',', $mc->getDomains()), |
@@ -84,10 +86,14 @@ discard block |
||
84 | 86 | $catalogue->getData(), |
85 | 87 | ); |
86 | 88 | |
87 | - if ($this->option('fallback')) { |
|
88 | - foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages) { |
|
89 | - foreach ($messages as $id => $message) { |
|
90 | - if (!$messageCatalogue->defines($id, $domain)) { |
|
89 | + if ($this->option('fallback')) |
|
90 | + { |
|
91 | + foreach ($manager->get($config->getFallbackLocale())->getData() as $domain => $messages) |
|
92 | + { |
|
93 | + foreach ($messages as $id => $message) |
|
94 | + { |
|
95 | + if (!$messageCatalogue->defines($id, $domain)) |
|
96 | + { |
|
91 | 97 | $messageCatalogue->set($id, $message, $domain); |
92 | 98 | } |
93 | 99 | } |
@@ -25,13 +25,13 @@ discard block |
||
25 | 25 | $generator = new ContextGenerator($views->getContext()); |
26 | 26 | |
27 | 27 | $contexts = $generator->generate(); |
28 | - if (empty($contexts)) { |
|
28 | + if (empty($contexts)){ |
|
29 | 29 | $contexts[] = $views->getContext(); |
30 | 30 | } |
31 | 31 | |
32 | - foreach ($contexts as $context) { |
|
33 | - foreach ($views->getEngines() as $engine) { |
|
34 | - if ($engine instanceof NativeEngine) { |
|
32 | + foreach ($contexts as $context){ |
|
33 | + foreach ($views->getEngines() as $engine){ |
|
34 | + if ($engine instanceof NativeEngine){ |
|
35 | 35 | // no need to compile |
36 | 36 | continue; |
37 | 37 | } |
@@ -53,19 +53,19 @@ discard block |
||
53 | 53 | $this->describeContext($context) ?? 'default', |
54 | 54 | ); |
55 | 55 | |
56 | - foreach ($engine->getLoader()->list() as $path) { |
|
56 | + foreach ($engine->getLoader()->list() as $path){ |
|
57 | 57 | $start = \microtime(true); |
58 | - try { |
|
58 | + try{ |
|
59 | 59 | $engine->reset($path, $context); |
60 | 60 | $engine->compile($path, $context); |
61 | 61 | |
62 | - if ($this->isVerbose()) { |
|
62 | + if ($this->isVerbose()){ |
|
63 | 63 | $this->sprintf('<info>•</info> %s', $path); |
64 | 64 | } |
65 | - } catch (\Throwable $e) { |
|
65 | + }catch (\Throwable $e){ |
|
66 | 66 | $this->renderError($path, $e); |
67 | 67 | continue; |
68 | - } finally { |
|
68 | + }finally{ |
|
69 | 69 | $this->renderElapsed($start); |
70 | 70 | } |
71 | 71 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | protected function renderError(string $path, \Throwable $e): void |
77 | 77 | { |
78 | - if (!$this->isVerbose()) { |
|
78 | + if (!$this->isVerbose()){ |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | { |
92 | 92 | $values = []; |
93 | 93 | |
94 | - foreach ($context->getDependencies() as $dependency) { |
|
94 | + foreach ($context->getDependencies() as $dependency){ |
|
95 | 95 | $values[] = \sprintf( |
96 | 96 | '%s%s%s:%s%s%s', |
97 | 97 | Color::LIGHT_WHITE, |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | |
114 | 114 | private function renderSuccess(?string $lastPath = null): void |
115 | 115 | { |
116 | - if (!$this->isVerbose()) { |
|
116 | + if (!$this->isVerbose()){ |
|
117 | 117 | return; |
118 | 118 | } |
119 | 119 | |
120 | - if ($lastPath === null) { |
|
120 | + if ($lastPath === null){ |
|
121 | 121 | $this->writeln('• no views found'); |
122 | 122 | } |
123 | 123 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | |
127 | 127 | private function renderElapsed(float $start): void |
128 | 128 | { |
129 | - if (!$this->isVerbose()) { |
|
129 | + if (!$this->isVerbose()){ |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 |
@@ -25,13 +25,17 @@ discard block |
||
25 | 25 | $generator = new ContextGenerator($views->getContext()); |
26 | 26 | |
27 | 27 | $contexts = $generator->generate(); |
28 | - if (empty($contexts)) { |
|
28 | + if (empty($contexts)) |
|
29 | + { |
|
29 | 30 | $contexts[] = $views->getContext(); |
30 | 31 | } |
31 | 32 | |
32 | - foreach ($contexts as $context) { |
|
33 | - foreach ($views->getEngines() as $engine) { |
|
34 | - if ($engine instanceof NativeEngine) { |
|
33 | + foreach ($contexts as $context) |
|
34 | + { |
|
35 | + foreach ($views->getEngines() as $engine) |
|
36 | + { |
|
37 | + if ($engine instanceof NativeEngine) |
|
38 | + { |
|
35 | 39 | // no need to compile |
36 | 40 | continue; |
37 | 41 | } |
@@ -53,19 +57,26 @@ discard block |
||
53 | 57 | $this->describeContext($context) ?? 'default', |
54 | 58 | ); |
55 | 59 | |
56 | - foreach ($engine->getLoader()->list() as $path) { |
|
60 | + foreach ($engine->getLoader()->list() as $path) |
|
61 | + { |
|
57 | 62 | $start = \microtime(true); |
58 | - try { |
|
63 | + try |
|
64 | + { |
|
59 | 65 | $engine->reset($path, $context); |
60 | 66 | $engine->compile($path, $context); |
61 | 67 | |
62 | - if ($this->isVerbose()) { |
|
68 | + if ($this->isVerbose()) |
|
69 | + { |
|
63 | 70 | $this->sprintf('<info>•</info> %s', $path); |
64 | 71 | } |
65 | - } catch (\Throwable $e) { |
|
72 | + } |
|
73 | + catch (\Throwable $e) |
|
74 | + { |
|
66 | 75 | $this->renderError($path, $e); |
67 | 76 | continue; |
68 | - } finally { |
|
77 | + } |
|
78 | + finally |
|
79 | + { |
|
69 | 80 | $this->renderElapsed($start); |
70 | 81 | } |
71 | 82 | } |
@@ -75,7 +86,8 @@ discard block |
||
75 | 86 | |
76 | 87 | protected function renderError(string $path, \Throwable $e): void |
77 | 88 | { |
78 | - if (!$this->isVerbose()) { |
|
89 | + if (!$this->isVerbose()) |
|
90 | + { |
|
79 | 91 | return; |
80 | 92 | } |
81 | 93 | |
@@ -91,7 +103,8 @@ discard block |
||
91 | 103 | { |
92 | 104 | $values = []; |
93 | 105 | |
94 | - foreach ($context->getDependencies() as $dependency) { |
|
106 | + foreach ($context->getDependencies() as $dependency) |
|
107 | + { |
|
95 | 108 | $values[] = \sprintf( |
96 | 109 | '%s%s%s:%s%s%s', |
97 | 110 | Color::LIGHT_WHITE, |
@@ -113,11 +126,13 @@ discard block |
||
113 | 126 | |
114 | 127 | private function renderSuccess(?string $lastPath = null): void |
115 | 128 | { |
116 | - if (!$this->isVerbose()) { |
|
129 | + if (!$this->isVerbose()) |
|
130 | + { |
|
117 | 131 | return; |
118 | 132 | } |
119 | 133 | |
120 | - if ($lastPath === null) { |
|
134 | + if ($lastPath === null) |
|
135 | + { |
|
121 | 136 | $this->writeln('• no views found'); |
122 | 137 | } |
123 | 138 | |
@@ -126,7 +141,8 @@ discard block |
||
126 | 141 | |
127 | 142 | private function renderElapsed(float $start): void |
128 | 143 | { |
129 | - if (!$this->isVerbose()) { |
|
144 | + if (!$this->isVerbose()) |
|
145 | + { |
|
130 | 146 | return; |
131 | 147 | } |
132 | 148 |
@@ -18,20 +18,20 @@ discard block |
||
18 | 18 | |
19 | 19 | public function perform(ViewsConfig $config, FilesInterface $files): int |
20 | 20 | { |
21 | - if (!$files->exists($config->getCacheDirectory())) { |
|
21 | + if (!$files->exists($config->getCacheDirectory())){ |
|
22 | 22 | $this->writeln('Cache directory is missing, no cache to be cleaned.'); |
23 | 23 | |
24 | 24 | return self::FAILURE; |
25 | 25 | } |
26 | 26 | |
27 | - if ($this->isVerbose()) { |
|
27 | + if ($this->isVerbose()){ |
|
28 | 28 | $this->writeln('<info>Cleaning view cache:</info>'); |
29 | 29 | } |
30 | 30 | |
31 | - foreach ($files->getFiles($config->getCacheDirectory()) as $filename) { |
|
32 | - try { |
|
31 | + foreach ($files->getFiles($config->getCacheDirectory()) as $filename){ |
|
32 | + try{ |
|
33 | 33 | $files->delete($filename); |
34 | - } catch (\Throwable $e) { |
|
34 | + }catch (\Throwable $e){ |
|
35 | 35 | // @codeCoverageIgnoreStart |
36 | 36 | $this->sprintf( |
37 | 37 | "<fg=red>[errored]</fg=red> `%s`: <fg=red>%s</fg=red>\n", |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | // @codeCoverageIgnoreEnd |
44 | 44 | } |
45 | 45 | |
46 | - if ($this->isVerbose()) { |
|
46 | + if ($this->isVerbose()){ |
|
47 | 47 | $this->sprintf( |
48 | 48 | "<fg=green>[deleted]</fg=green> `%s`\n", |
49 | 49 | $files->relativePath($filename, $config->getCacheDirectory()), |
@@ -18,20 +18,26 @@ discard block |
||
18 | 18 | |
19 | 19 | public function perform(ViewsConfig $config, FilesInterface $files): int |
20 | 20 | { |
21 | - if (!$files->exists($config->getCacheDirectory())) { |
|
21 | + if (!$files->exists($config->getCacheDirectory())) |
|
22 | + { |
|
22 | 23 | $this->writeln('Cache directory is missing, no cache to be cleaned.'); |
23 | 24 | |
24 | 25 | return self::FAILURE; |
25 | 26 | } |
26 | 27 | |
27 | - if ($this->isVerbose()) { |
|
28 | + if ($this->isVerbose()) |
|
29 | + { |
|
28 | 30 | $this->writeln('<info>Cleaning view cache:</info>'); |
29 | 31 | } |
30 | 32 | |
31 | - foreach ($files->getFiles($config->getCacheDirectory()) as $filename) { |
|
32 | - try { |
|
33 | + foreach ($files->getFiles($config->getCacheDirectory()) as $filename) |
|
34 | + { |
|
35 | + try |
|
36 | + { |
|
33 | 37 | $files->delete($filename); |
34 | - } catch (\Throwable $e) { |
|
38 | + } |
|
39 | + catch (\Throwable $e) |
|
40 | + { |
|
35 | 41 | // @codeCoverageIgnoreStart |
36 | 42 | $this->sprintf( |
37 | 43 | "<fg=red>[errored]</fg=red> `%s`: <fg=red>%s</fg=red>\n", |
@@ -43,7 +49,8 @@ discard block |
||
43 | 49 | // @codeCoverageIgnoreEnd |
44 | 50 | } |
45 | 51 | |
46 | - if ($this->isVerbose()) { |
|
52 | + if ($this->isVerbose()) |
|
53 | + { |
|
47 | 54 | $this->sprintf( |
48 | 55 | "<fg=green>[deleted]</fg=green> `%s`\n", |
49 | 56 | $files->relativePath($filename, $config->getCacheDirectory()), |