From b424b8101fb4c6be232ad2b0b8af8d77abc53eba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Wed, 20 Mar 2024 18:27:42 +0100 Subject: [PATCH 1/6] chore: Move Descriptors in their own NS --- src/Console/Application.php | 12 ++++++------ src/ContextRegistry.php | 1 + src/{ => Descriptor}/ContextDescriptor.php | 2 +- src/{ => Descriptor}/ContextGeneratorDescriptor.php | 3 ++- src/{ => Descriptor}/ListenerDescriptor.php | 2 +- src/{ => Descriptor}/SymfonyTaskDescriptor.php | 2 +- src/{ => Descriptor}/TaskDescriptor.php | 2 +- src/FunctionFinder.php | 5 +++++ src/TaskDescriptorCollection.php | 3 +++ .../Generated/ContextGeneratorArg2Test.php.err.txt | 2 +- .../Generated/ContextGeneratorArgTest.php.err.txt | 2 +- .../ContextGeneratorNotCallableTest.php.err.txt | 2 +- 12 files changed, 24 insertions(+), 14 deletions(-) rename src/{ => Descriptor}/ContextDescriptor.php (89%) rename src/{ => Descriptor}/ContextGeneratorDescriptor.php (88%) rename src/{ => Descriptor}/ListenerDescriptor.php (88%) rename src/{ => Descriptor}/SymfonyTaskDescriptor.php (92%) rename src/{ => Descriptor}/TaskDescriptor.php (88%) diff --git a/src/Console/Application.php b/src/Console/Application.php index 4aad94d5..6b649147 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -5,20 +5,20 @@ use Castor\Console\Command\SymfonyTaskCommand; use Castor\Console\Command\TaskCommand; use Castor\Context; -use Castor\ContextDescriptor; -use Castor\ContextGeneratorDescriptor; use Castor\ContextRegistry; -use Castor\Event\AfterApplicationInitializationEvent; +use Castor\Descriptor\ContextDescriptor; +use Castor\Descriptor\ContextGeneratorDescriptor; +use Castor\Descriptor\ListenerDescriptor; +use Castor\Descriptor\SymfonyTaskDescriptor; +use Castor\Descriptor\TaskDescriptor; use Castor\EventDispatcher; +use Castor\Event\AfterApplicationInitializationEvent; use Castor\ExpressionLanguage; use Castor\Fingerprint\FingerprintHelper; use Castor\FunctionFinder; use Castor\GlobalHelper; -use Castor\ListenerDescriptor; use Castor\PlatformUtil; use Castor\SectionOutput; -use Castor\SymfonyTaskDescriptor; -use Castor\TaskDescriptor; use Castor\TaskDescriptorCollection; use Castor\VerbosityLevel; use Castor\WaitForHelper; diff --git a/src/ContextRegistry.php b/src/ContextRegistry.php index a9aa48c4..a0aaa82b 100644 --- a/src/ContextRegistry.php +++ b/src/ContextRegistry.php @@ -2,6 +2,7 @@ namespace Castor; +use Castor\Descriptor\ContextDescriptor; use Castor\Exception\FunctionConfigurationException; /** @internal */ diff --git a/src/ContextDescriptor.php b/src/Descriptor/ContextDescriptor.php similarity index 89% rename from src/ContextDescriptor.php rename to src/Descriptor/ContextDescriptor.php index 46937972..a8e4fc5b 100644 --- a/src/ContextDescriptor.php +++ b/src/Descriptor/ContextDescriptor.php @@ -1,6 +1,6 @@ Date: Wed, 20 Mar 2024 18:33:36 +0100 Subject: [PATCH 2/6] chore: move SectionOutput to the Console/Output NS --- src/Console/Application.php | 2 +- src/{ => Console/Output}/SectionOutput.php | 2 +- src/GlobalHelper.php | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) rename src/{ => Console/Output}/SectionOutput.php (99%) diff --git a/src/Console/Application.php b/src/Console/Application.php index 6b649147..3079aa78 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -4,6 +4,7 @@ use Castor\Console\Command\SymfonyTaskCommand; use Castor\Console\Command\TaskCommand; +use Castor\Console\Output\SectionOutput; use Castor\Context; use Castor\ContextRegistry; use Castor\Descriptor\ContextDescriptor; @@ -18,7 +19,6 @@ use Castor\FunctionFinder; use Castor\GlobalHelper; use Castor\PlatformUtil; -use Castor\SectionOutput; use Castor\TaskDescriptorCollection; use Castor\VerbosityLevel; use Castor\WaitForHelper; diff --git a/src/SectionOutput.php b/src/Console/Output/SectionOutput.php similarity index 99% rename from src/SectionOutput.php rename to src/Console/Output/SectionOutput.php index 3a37a6a0..407fe639 100644 --- a/src/SectionOutput.php +++ b/src/Console/Output/SectionOutput.php @@ -1,6 +1,6 @@ Date: Wed, 20 Mar 2024 18:35:19 +0100 Subject: [PATCH 3/6] chore: move VerbosittyLevel to the Console/Output NS --- src/Console/Application.php | 2 +- src/{ => Console/Output}/VerbosityLevel.php | 2 +- src/Context.php | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) rename src/{ => Console/Output}/VerbosityLevel.php (97%) diff --git a/src/Console/Application.php b/src/Console/Application.php index 3079aa78..db33faa3 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -5,6 +5,7 @@ use Castor\Console\Command\SymfonyTaskCommand; use Castor\Console\Command\TaskCommand; use Castor\Console\Output\SectionOutput; +use Castor\Console\Output\VerbosityLevel; use Castor\Context; use Castor\ContextRegistry; use Castor\Descriptor\ContextDescriptor; @@ -20,7 +21,6 @@ use Castor\GlobalHelper; use Castor\PlatformUtil; use Castor\TaskDescriptorCollection; -use Castor\VerbosityLevel; use Castor\WaitForHelper; use Monolog\Logger; use Psr\Cache\CacheItemPoolInterface; diff --git a/src/VerbosityLevel.php b/src/Console/Output/VerbosityLevel.php similarity index 97% rename from src/VerbosityLevel.php rename to src/Console/Output/VerbosityLevel.php index 4dfd2c81..87f3daa5 100644 --- a/src/VerbosityLevel.php +++ b/src/Console/Output/VerbosityLevel.php @@ -1,6 +1,6 @@ Date: Wed, 20 Mar 2024 18:39:37 +0100 Subject: [PATCH 4/6] chore: Move TaskDescriptorCollection to the Descriptor NS --- CHANGELOG.md | 2 ++ src/Console/Application.php | 4 ++-- src/Descriptor/TaskDescriptorCollection.php | 16 ++++++++++++++++ .../AfterApplicationInitializationEvent.php | 2 +- src/TaskDescriptorCollection.php | 19 +++++++------------ 5 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 src/Descriptor/TaskDescriptorCollection.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 2518249a..b8055ea2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ * Add a way to merge an application `box.json` config file used by `castor:repack`command * Deprecate `Context::withPath()` in favor of `Context::withWorkingDirectory()` * Deprecate `path` argument in `capture()`, `exit_code()`, `run()`, `with()` in favor of `workingDirectory` +* Deprecate `Castor\TaskDescriptorCollection` in favor of + `Castor\Descriptor\TaskDescriptorCollection` ## 0.14.0 (2024-03-08) diff --git a/src/Console/Application.php b/src/Console/Application.php index db33faa3..09dbebc8 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -13,14 +13,14 @@ use Castor\Descriptor\ListenerDescriptor; use Castor\Descriptor\SymfonyTaskDescriptor; use Castor\Descriptor\TaskDescriptor; -use Castor\EventDispatcher; +use Castor\Descriptor\TaskDescriptorCollection; use Castor\Event\AfterApplicationInitializationEvent; +use Castor\EventDispatcher; use Castor\ExpressionLanguage; use Castor\Fingerprint\FingerprintHelper; use Castor\FunctionFinder; use Castor\GlobalHelper; use Castor\PlatformUtil; -use Castor\TaskDescriptorCollection; use Castor\WaitForHelper; use Monolog\Logger; use Psr\Cache\CacheItemPoolInterface; diff --git a/src/Descriptor/TaskDescriptorCollection.php b/src/Descriptor/TaskDescriptorCollection.php new file mode 100644 index 00000000..3e245f3b --- /dev/null +++ b/src/Descriptor/TaskDescriptorCollection.php @@ -0,0 +1,16 @@ + Date: Wed, 20 Mar 2024 18:41:36 +0100 Subject: [PATCH 5/6] chore: Rename PlatformUtils to PlatformHelper to mimic other helper --- bin/generate-tests.php | 4 ++-- src/Console/Application.php | 4 ++-- src/Console/ApplicationFactory.php | 4 ++-- src/Console/Command/CompileCommand.php | 4 ++-- src/Listener/UpdateCastorListener.php | 4 ++-- src/{PlatformUtil.php => PlatformHelper.php} | 2 +- tests/Examples/Fingerprint/FingerprintedTestCase.php | 8 ++++---- tests/bin/compile-get-cache-key | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) rename src/{PlatformUtil.php => PlatformHelper.php} (98%) diff --git a/bin/generate-tests.php b/bin/generate-tests.php index db6c9065..581b58cb 100755 --- a/bin/generate-tests.php +++ b/bin/generate-tests.php @@ -4,7 +4,7 @@ require __DIR__ . '/../vendor/autoload.php'; use Castor\Console\ApplicationFactory; -use Castor\PlatformUtil; +use Castor\PlatformHelper; use Castor\Tests\Helper\OutputCleaner; use Castor\Tests\Helper\WebServerHelper; use Symfony\Component\Console\Input\ArrayInput; @@ -19,7 +19,7 @@ WebServerHelper::start(); $fs = new Filesystem(); -$fs->remove(PlatformUtil::getCacheDirectory()); +$fs->remove(PlatformHelper::getCacheDirectory()); $fs->remove(__DIR__ . '/../tests/Examples/Generated'); $fs->mkdir(__DIR__ . '/../tests/Examples/Generated'); diff --git a/src/Console/Application.php b/src/Console/Application.php index 09dbebc8..10a6a810 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -20,7 +20,7 @@ use Castor\Fingerprint\FingerprintHelper; use Castor\FunctionFinder; use Castor\GlobalHelper; -use Castor\PlatformUtil; +use Castor\PlatformHelper; use Castor\WaitForHelper; use Monolog\Logger; use Psr\Cache\CacheItemPoolInterface; @@ -203,7 +203,7 @@ private function initializeApplication(InputInterface $input): TaskDescriptorCol $contextNames = $this->contextRegistry->getNames(); if ($contextNames) { - $defaultContext = PlatformUtil::getEnv('CASTOR_CONTEXT') ?: $this->contextRegistry->getDefaultName(); + $defaultContext = PlatformHelper::getEnv('CASTOR_CONTEXT') ?: $this->contextRegistry->getDefaultName(); $this->getDefinition()->addOption(new InputOption( 'context', diff --git a/src/Console/ApplicationFactory.php b/src/Console/ApplicationFactory.php index 98303351..6a4e5e29 100644 --- a/src/Console/ApplicationFactory.php +++ b/src/Console/ApplicationFactory.php @@ -14,7 +14,7 @@ use Castor\Listener\UpdateCastorListener; use Castor\Monolog\Processor\ProcessProcessor; use Castor\PathHelper; -use Castor\PlatformUtil; +use Castor\PlatformHelper; use Castor\Stub\StubsGenerator; use Castor\WaitForHelper; use Monolog\Logger; @@ -45,7 +45,7 @@ public static function create(): SymfonyApplication 'User-Agent' => 'Castor/' . Application::VERSION, ], ]); - $cacheDir = PlatformUtil::getCacheDirectory(); + $cacheDir = PlatformHelper::getCacheDirectory(); $cache = new FilesystemAdapter(directory: $cacheDir); $logger = new Logger('castor', [], [new ProcessProcessor()]); $fs = new Filesystem(); diff --git a/src/Console/Command/CompileCommand.php b/src/Console/Command/CompileCommand.php index 56ec06ff..c0f60689 100644 --- a/src/Console/Command/CompileCommand.php +++ b/src/Console/Command/CompileCommand.php @@ -3,7 +3,7 @@ namespace Castor\Console\Command; use Castor\PathHelper; -use Castor\PlatformUtil; +use Castor\PlatformHelper; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $phpBuildCacheKey = $this->generatePHPBuildCacheKey($input); - $spcBinaryPath = PlatformUtil::getCacheDirectory() . '/castor-php-static-compiler/' . $phpBuildCacheKey . '/spc'; + $spcBinaryPath = PlatformHelper::getCacheDirectory() . '/castor-php-static-compiler/' . $phpBuildCacheKey . '/spc'; $spcBinaryDir = \dirname($spcBinaryPath); $this->setupSPC( diff --git a/src/Listener/UpdateCastorListener.php b/src/Listener/UpdateCastorListener.php index ea41a7ad..875b3d76 100644 --- a/src/Listener/UpdateCastorListener.php +++ b/src/Listener/UpdateCastorListener.php @@ -3,7 +3,7 @@ namespace Castor\Listener; use Castor\Console\Application; -use Castor\PlatformUtil; +use Castor\PlatformHelper; use JoliCode\PhpOsHelper\OsHelper; use Psr\Cache\CacheItemPoolInterface; use Psr\Log\LoggerInterface; @@ -33,7 +33,7 @@ public function checkUpdate(ConsoleCommandEvent $event): void if (class_exists(\RepackedApplication::class)) { return; } - if (PlatformUtil::getEnv('DISABLE_VERSION_CHECK')) { + if (PlatformHelper::getEnv('DISABLE_VERSION_CHECK')) { return; } diff --git a/src/PlatformUtil.php b/src/PlatformHelper.php similarity index 98% rename from src/PlatformUtil.php rename to src/PlatformHelper.php index 66593147..a8074964 100644 --- a/src/PlatformUtil.php +++ b/src/PlatformHelper.php @@ -9,7 +9,7 @@ * * @internal */ -final class PlatformUtil +final class PlatformHelper { /** * getenv() equivalent but reads from the runtime global variables first. diff --git a/tests/Examples/Fingerprint/FingerprintedTestCase.php b/tests/Examples/Fingerprint/FingerprintedTestCase.php index 2d6d68c9..c8660d9c 100644 --- a/tests/Examples/Fingerprint/FingerprintedTestCase.php +++ b/tests/Examples/Fingerprint/FingerprintedTestCase.php @@ -2,7 +2,7 @@ namespace Castor\Tests\Examples\Fingerprint; -use Castor\PlatformUtil; +use Castor\PlatformHelper; use Castor\Tests\TaskTestCase; use Symfony\Component\Finder\Finder; @@ -20,10 +20,10 @@ protected function setUp(): void private static function clearFingerprintsCache(): void { - if (is_dir(PlatformUtil::getCacheDirectory())) { + if (is_dir(PlatformHelper::getCacheDirectory())) { foreach ( (new Finder()) - ->in(PlatformUtil::getCacheDirectory()) + ->in(PlatformHelper::getCacheDirectory()) ->contains('.fingerprint') ->files() as $file ) { @@ -32,7 +32,7 @@ private static function clearFingerprintsCache(): void foreach ( (new Finder()) - ->in(PlatformUtil::getCacheDirectory()) + ->in(PlatformHelper::getCacheDirectory()) ->notContains('.fingerprint') ->directories() as $directory ) { diff --git a/tests/bin/compile-get-cache-key b/tests/bin/compile-get-cache-key index 551f85f7..84909ea4 100755 --- a/tests/bin/compile-get-cache-key +++ b/tests/bin/compile-get-cache-key @@ -4,7 +4,7 @@ require __DIR__ . '/../../vendor/autoload.php'; use Castor\Console\Command\CompileCommand; -use Castor\PlatformUtil; +use Castor\PlatformHelper; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; @@ -14,7 +14,7 @@ $command = (new class() extends CompileCommand { }} ) ->setCode(Closure::bind( - fn($input) => (print PlatformUtil::getCacheDirectory() . '/castor-php-static-compiler/' . $this->generatePHPBuildCacheKey($input)) && 0, + fn($input) => (print PlatformHelper::getCacheDirectory() . '/castor-php-static-compiler/' . $this->generatePHPBuildCacheKey($input)) && 0, null, CompileCommand::class )) From b3ff0a324be893ff40ac0e2da5805afac498a1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Wed, 20 Mar 2024 18:44:53 +0100 Subject: [PATCH 6/6] chore: add missing internal tag on FingerprintHelper --- src/Fingerprint/FingerprintHelper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Fingerprint/FingerprintHelper.php b/src/Fingerprint/FingerprintHelper.php index 219dfae5..1cd1b68d 100644 --- a/src/Fingerprint/FingerprintHelper.php +++ b/src/Fingerprint/FingerprintHelper.php @@ -5,6 +5,7 @@ use Psr\Cache\CacheItemPoolInterface; use Symfony\Contracts\Cache\CacheInterface; +/** @internal */ class FingerprintHelper { private const SUFFIX = '.fingerprint';