1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Spiral\Command\Tokenizer; |
6
|
|
|
|
7
|
|
|
use Spiral\Boot\DirectoriesInterface; |
8
|
|
|
use Spiral\Console\Attribute\AsCommand; |
9
|
|
|
use Spiral\Console\Command; |
10
|
|
|
use Spiral\Tokenizer\Config\TokenizerConfig; |
11
|
|
|
|
12
|
|
|
#[AsCommand( |
13
|
|
|
name: 'tokenizer:info', |
14
|
|
|
description: 'Get information about tokenizer directories to scan' |
15
|
|
|
)] |
16
|
|
|
final class InfoCommand extends Command |
17
|
|
|
{ |
18
|
|
|
public function perform(TokenizerConfig $config, DirectoriesInterface $dirs): int |
19
|
|
|
{ |
20
|
|
|
$this->info('Included directories:'); |
21
|
|
|
$grid = $this->table(['Directory', 'Scope']); |
22
|
|
|
foreach ($config->getDirectories() as $directory) { |
23
|
|
|
$grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']); |
24
|
|
|
} |
25
|
|
|
foreach ($config->getScopes() as $scope => $data) { |
26
|
|
|
foreach ($data['directories'] ?? [] as $directory) { |
27
|
|
|
$grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$grid->render(); |
32
|
|
|
|
33
|
|
|
$this->newLine(); |
34
|
|
|
|
35
|
|
|
$this->info('Excluded directories:'); |
36
|
|
|
$grid = $this->table(['Directory', 'Scope']); |
37
|
|
|
foreach ($config->getExcludes() as $directory) { |
38
|
|
|
$grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']); |
39
|
|
|
} |
40
|
|
|
foreach ($config->getScopes() as $scope => $data) { |
41
|
|
|
foreach ($data['exclude'] ?? [] as $directory) { |
42
|
|
|
$grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$grid->render(); |
47
|
|
|
|
48
|
|
|
$this->newLine(); |
49
|
|
|
$this->info( |
50
|
|
|
\sprintf('Tokenizer cache: %s', $config->isCacheEnabled() ? '<success>enabled</>' : '<error>disabled</>'), |
51
|
|
|
); |
52
|
|
|
if (!$config->isCacheEnabled()) { |
53
|
|
|
$this->comment('To enable cache, add "TOKENIZER_CACHE_TARGETS=true" to your .env file.'); |
54
|
|
|
$this->comment('Read more at https://spiral.dev/docs/advanced-tokenizer/#class-listeners'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return self::SUCCESS; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|