-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #963 from spiral/feature/916
Changes behavior for loading system bootloaders.
- Loading branch information
Showing
19 changed files
with
276 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/Tokenizer/tests/Bootloader/TokenizerBootloaderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Tests\Tokenizer\Bootloader; | ||
|
||
use Mockery as m; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use Spiral\Boot\DirectoriesInterface; | ||
use Spiral\Boot\EnvironmentInterface; | ||
use Spiral\Config\ConfigManager; | ||
use Spiral\Config\Loader\DirectoryLoader; | ||
use Spiral\Core\BinderInterface; | ||
use Spiral\Tokenizer\Bootloader\TokenizerBootloader; | ||
use Spiral\Tokenizer\Config\TokenizerConfig; | ||
|
||
final class TokenizerBootloaderTest extends TestCase | ||
{ | ||
#[DataProvider('readCacheDataProvider')] | ||
public function testCastingReadCacheEnvVariable(mixed $readCache, bool $expected): void | ||
{ | ||
$binder = m::spy(BinderInterface::class); | ||
$dirs = m::mock(DirectoriesInterface::class); | ||
$env = m::mock(EnvironmentInterface::class); | ||
|
||
$env->shouldReceive('get')->once()->with('TOKENIZER_CACHE_TARGETS', false)->andReturn($readCache); | ||
|
||
$dirs->shouldReceive('get')->once()->with('app')->andReturn('app/'); | ||
$dirs->shouldReceive('get')->once()->with('resources')->andReturn('resources/'); | ||
$dirs->shouldReceive('get')->once()->with('config')->andReturn('config/'); | ||
$dirs->shouldReceive('get')->once()->with('runtime')->andReturn('runtime/'); | ||
|
||
$bootloader = new TokenizerBootloader($config = new ConfigManager(new DirectoryLoader('config'))); | ||
$bootloader->init($binder, $dirs, $env); | ||
|
||
$initConfig = $config->getConfig(TokenizerConfig::CONFIG); | ||
|
||
$this->assertSame('runtime/cache/listeners', $initConfig['cache']['directory']); | ||
$this->assertSame($expected, $initConfig['cache']['enabled']); | ||
} | ||
|
||
public static function readCacheDataProvider(): \Traversable | ||
{ | ||
yield [true, true]; | ||
yield [false, false]; | ||
yield [1, true]; | ||
yield [0, false]; | ||
yield ['1', true]; | ||
yield ['0', false]; | ||
yield ['true', true]; | ||
yield ['false', false]; | ||
} | ||
} |
Oops, something went wrong.