Skip to content

Commit

Permalink
Adds Tokenizer info console command
Browse files Browse the repository at this point in the history
see #916
  • Loading branch information
butschster committed Aug 10, 2023
1 parent 0682428 commit 008995f
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/Framework/Command/Tokenizer/InfoCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace Spiral\Command\Tokenizer;

use Spiral\Boot\DirectoriesInterface;
use Spiral\Console\Attribute\AsCommand;
use Spiral\Console\Command;
use Spiral\Tokenizer\Config\TokenizerConfig;

#[AsCommand(
name: 'tokenizer:info',
description: 'Get information about tokenizer directories to scan'
)]
final class InfoCommand extends Command
{
public function perform(TokenizerConfig $config, DirectoriesInterface $dirs): int
{
$this->info('Included directories:');
$grid = $this->table(['Directory', 'Scope']);
foreach ($config->getDirectories() as $directory) {
$grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']);
}
foreach ($config->getScopes() as $scope => $data) {
foreach ($data['directories'] ?? [] as $directory) {
$grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]);
}
}

$grid->render();

$this->newLine();

$this->info('Excluded directories:');
$grid = $this->table(['Directory', 'Scope']);
foreach ($config->getExcludes() as $directory) {
$grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']);
}
foreach ($config->getScopes() as $scope => $data) {
foreach ($data['exclude'] ?? [] as $directory) {
$grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]);
}
}

$grid->render();

$this->newLine();
$this->info(
\sprintf('Tokenizer cache: %s', $config->isCacheEnabled() ? '<success>enabled</>' : '<error>disabled</>'),
);
if (!$config->isCacheEnabled()) {
$this->comment('To enable cache, add "TOKENIZER_CACHE_TARGETS=true" to your .env file.');
$this->comment('Read more at https://spiral.dev/docs/advanced-tokenizer/#class-listeners');
}

return self::SUCCESS;
}
}

0 comments on commit 008995f

Please sign in to comment.