From 2cf928e97e442597209c81e8b582305880ae6c96 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 16 Dec 2023 12:29:30 +0100 Subject: [PATCH 1/6] remove http kernel --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index fb9bd1e27ad..fc61413b5b3 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,6 @@ "symfony/expression-language": "^6.4", "symfony/filesystem": "^6.4", "symfony/finder": "^6.4", - "symfony/http-kernel": "^6.1", "symfony/yaml": "^6.4", "symplify/php-config-printer": "^11.3.6", "webmozart/assert": "^1.11" From da610f5b4abce2d07b93705baabfde297bd24f68 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 16 Dec 2023 12:33:05 +0100 Subject: [PATCH 2/6] avoid polyfills --- composer.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/composer.json b/composer.json index fc61413b5b3..e1198005aa3 100644 --- a/composer.json +++ b/composer.json @@ -57,6 +57,13 @@ }, "enable-patching": true }, + "replace": { + "symfony/polyfill-ctype": "*", + "symfony/polyfill-intl-grapheme": "*", + "symfony/polyfill-php74": "*", + "symfony/polyfill-php80": "*", + "symfony/polyfill-php81": "*" + }, "scripts": { "check-cs": "vendor/bin/ecs check --ansi", "fix-cs": "vendor/bin/ecs check --fix --ansi", From ace05ba5f8b5362e4fd460873290b9e57a1fbf65 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 16 Dec 2023 12:34:03 +0100 Subject: [PATCH 3/6] naming --- src/Console/Command/SwitchFormatCommand.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Console/Command/SwitchFormatCommand.php b/src/Console/Command/SwitchFormatCommand.php index fe1c0e2e8b6..23e6c553aa3 100644 --- a/src/Console/Command/SwitchFormatCommand.php +++ b/src/Console/Command/SwitchFormatCommand.php @@ -54,7 +54,6 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { $configuration = $this->configurationFactory->createFromInput($input); - $totalFileCount = $this->getTotalFileCount($configuration); $fileInfos = $this->configFileFinder->findFileInfos($configuration->getSources()); @@ -70,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $convertedContent = new ConvertedContent($convertedFileContent, $fileInfo); $this->configFileDumper->dumpFile($convertedContent, $configuration); - $this->removeFileInfo($configuration, $fileInfo); + $this->removeOriginalYamlFileInfo($configuration, $fileInfo); $this->symfonyStyle->newLine(); } @@ -89,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return self::SUCCESS; } - private function removeFileInfo(Configuration $configuration, SplFileInfo $fileInfo): void + private function removeOriginalYamlFileInfo(Configuration $configuration, SplFileInfo $fileInfo): void { // only dry run, nothing to remove if ($configuration->isDryRun()) { From 4a0931409016d4038fde083dfcc4a37de2659d8b Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 16 Dec 2023 12:43:17 +0100 Subject: [PATCH 4/6] add ConfigTransformerContainerFactory to drop http-kernel dependency --- bin/config-transformer.php | 4 +- .../LoadExtensionConfigsCompilerPass.php | 26 ++++++++ .../Loader/ParameterMergingPhpFileLoader.php | 53 ++++++++++++++++ .../ConfigTransformerContainerFactory.php | 51 ++++++++++++++++ src/Kernel/ConfigTransformerKernel.php | 31 ---------- src/Utils/ParametersMerger.php | 60 +++++++++++++++++++ tests/AbstractTestCase.php | 8 +-- 7 files changed, 195 insertions(+), 38 deletions(-) create mode 100644 src/DependencyInjection/Compiler/LoadExtensionConfigsCompilerPass.php create mode 100644 src/DependencyInjection/Loader/ParameterMergingPhpFileLoader.php create mode 100644 src/Kernel/ConfigTransformerContainerFactory.php delete mode 100644 src/Kernel/ConfigTransformerKernel.php create mode 100644 src/Utils/ParametersMerger.php diff --git a/bin/config-transformer.php b/bin/config-transformer.php index 62d283c7bc1..cb2bb7a948c 100755 --- a/bin/config-transformer.php +++ b/bin/config-transformer.php @@ -4,7 +4,7 @@ use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\ConsoleOutput; -use Symplify\ConfigTransformer\Kernel\ConfigTransformerKernel; +use Symplify\ConfigTransformer\Kernel\ConfigTransformerContainerFactory; $possibleAutoloadPaths = [ // dependency @@ -27,7 +27,7 @@ require_once $scoperAutoloadFilepath; } -$configTransformerKernel = new ConfigTransformerKernel(); +$configTransformerKernel = new ConfigTransformerContainerFactory(); $configTransformerKernel->boot(); $container = $configTransformerKernel->getContainer(); diff --git a/src/DependencyInjection/Compiler/LoadExtensionConfigsCompilerPass.php b/src/DependencyInjection/Compiler/LoadExtensionConfigsCompilerPass.php new file mode 100644 index 00000000000..309e02b0596 --- /dev/null +++ b/src/DependencyInjection/Compiler/LoadExtensionConfigsCompilerPass.php @@ -0,0 +1,26 @@ +getExtensions()); + + foreach ($extensionNames as $extensionName) { + $containerBuilder->loadFromExtension($extensionName, []); + } + + parent::process($containerBuilder); + } +} diff --git a/src/DependencyInjection/Loader/ParameterMergingPhpFileLoader.php b/src/DependencyInjection/Loader/ParameterMergingPhpFileLoader.php new file mode 100644 index 00000000000..b8d455ccb7e --- /dev/null +++ b/src/DependencyInjection/Loader/ParameterMergingPhpFileLoader.php @@ -0,0 +1,53 @@ +parametersMerger = new ParametersMerger(); + parent::__construct($containerBuilder, $fileLocator); + } + + /** + * Same as parent, just merging parameters instead overriding them + * + * @see https://github.com/symplify/symplify/pull/697 + */ + public function load(mixed $resource, string $type = null): mixed + { + // get old parameters + $parameterBag = $this->container->getParameterBag(); + $oldParameters = $parameterBag->all(); + + parent::load($resource); + + foreach ($oldParameters as $key => $oldValue) { + $currentParameterValue = $this->container->getParameter($key); + $newValue = $this->parametersMerger->merge($oldValue, $currentParameterValue); + + $this->container->setParameter($key, $newValue); + } + + return null; + } +} diff --git a/src/Kernel/ConfigTransformerContainerFactory.php b/src/Kernel/ConfigTransformerContainerFactory.php new file mode 100644 index 00000000000..8334d6fdea8 --- /dev/null +++ b/src/Kernel/ConfigTransformerContainerFactory.php @@ -0,0 +1,51 @@ +createDelegatingLoader($containerBuilder, getcwd()); + $delegatingLoader->load(__DIR__ . '/../../config/config.php'); + $delegatingLoader->load(PhpConfigPrinterConfig::FILE_PATH); + + $compilerPassConfig = $containerBuilder->getCompilerPassConfig(); + $compilerPassConfig->setMergePass(new LoadExtensionConfigsCompilerPass()); + + $containerBuilder->compile(); + + return $containerBuilder; + } + + private function createDelegatingLoader(ContainerBuilder $containerBuilder, string $currentWorkingDirectory): DelegatingLoader + { + $fileLocator = new FileLocator([$currentWorkingDirectory]); + + $loaders = [ + new GlobFileLoader($fileLocator), + new ParameterMergingPhpFileLoader($containerBuilder, $fileLocator), + ]; + + $loaderResolver = new LoaderResolver($loaders); + + return new DelegatingLoader($loaderResolver); + } +} diff --git a/src/Kernel/ConfigTransformerKernel.php b/src/Kernel/ConfigTransformerKernel.php deleted file mode 100644 index 86db0ed3d0f..00000000000 --- a/src/Kernel/ConfigTransformerKernel.php +++ /dev/null @@ -1,31 +0,0 @@ -load(__DIR__ . '/../../config/config.php'); - $loader->load(PhpConfigPrinterConfig::FILE_PATH); - } -} diff --git a/src/Utils/ParametersMerger.php b/src/Utils/ParametersMerger.php new file mode 100644 index 00000000000..ee99e0d56b7 --- /dev/null +++ b/src/Utils/ParametersMerger.php @@ -0,0 +1,60 @@ +mergeLeftToRightWithCallable( + $left, + $right, + fn (mixed $leftValue, mixed $rightValue): mixed => $this->merge($leftValue, $rightValue) + ); + } + + if ($left !== null) { + return $left; + } + + if (! \is_array($right)) { + return $left; + } + + return $right; + } + + /** + * @param array $left + * @param array $right + * @return mixed[] + */ + private function mergeLeftToRightWithCallable(array $left, array $right, callable $mergeCallback): array + { + foreach ($left as $key => $val) { + if (\is_int($key)) { + // prevent duplicated values in unindexed arrays + if (! \in_array($val, $right, \true)) { + $right[] = $val; + } + } else { + if (isset($right[$key])) { + $val = $mergeCallback($val, $right[$key]); + } + + $right[$key] = $val; + } + } + + return $right; + } +} diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 5f1fff7407c..d5afa0f39d9 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symplify\ConfigTransformer\Kernel\ConfigTransformerKernel; +use Symplify\ConfigTransformer\Kernel\ConfigTransformerContainerFactory; abstract class AbstractTestCase extends TestCase { @@ -14,10 +14,8 @@ abstract class AbstractTestCase extends TestCase protected function setUp(): void { - $configTransformerKernel = new ConfigTransformerKernel(); - $configTransformerKernel->boot(); - - $this->container = $configTransformerKernel->getContainer(); + $configTransformerContainerFactory = new ConfigTransformerContainerFactory(); + $this->container = $configTransformerContainerFactory->create(); } /** From 4763646914367571eae8f18dd071944b3fdbee19 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 16 Dec 2023 12:43:32 +0100 Subject: [PATCH 5/6] update fixture --- .../Loader/ParameterMergingPhpFileLoader.php | 2 +- .../ConfigFormatConverter/YamlToPhp/Fixture/normal/alias.yaml | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/DependencyInjection/Loader/ParameterMergingPhpFileLoader.php b/src/DependencyInjection/Loader/ParameterMergingPhpFileLoader.php index b8d455ccb7e..b9d46fe5ef8 100644 --- a/src/DependencyInjection/Loader/ParameterMergingPhpFileLoader.php +++ b/src/DependencyInjection/Loader/ParameterMergingPhpFileLoader.php @@ -7,7 +7,7 @@ use Symfony\Component\Config\FileLocatorInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -use Symplify\VendorPatches\Utils\ParametersMerger; +use Symplify\ConfigTransformer\Utils\ParametersMerger; /** * @api diff --git a/tests/Converter/ConfigFormatConverter/YamlToPhp/Fixture/normal/alias.yaml b/tests/Converter/ConfigFormatConverter/YamlToPhp/Fixture/normal/alias.yaml index 0d017e2a1ac..8278897861d 100644 --- a/tests/Converter/ConfigFormatConverter/YamlToPhp/Fixture/normal/alias.yaml +++ b/tests/Converter/ConfigFormatConverter/YamlToPhp/Fixture/normal/alias.yaml @@ -7,11 +7,9 @@ services: declare(strict_types=1); use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symfony\Component\EventDispatcher\EventDispatcher; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; return static function (ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); - $services->alias(EventDispatcherInterface::class, EventDispatcher::class); + $services->alias('Symfony\Component\EventDispatcher\EventDispatcherInterface', 'Symfony\Component\EventDispatcher\EventDispatcher'); }; From d0edc1d98f0b86bb7a87910cad484134cd7ba7ce Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 16 Dec 2023 12:58:07 +0100 Subject: [PATCH 6/6] fix cs --- bin/config-transformer.php | 10 +++++----- phpstan.neon | 1 + rector.php | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bin/config-transformer.php b/bin/config-transformer.php index cb2bb7a948c..a0835276d35 100755 --- a/bin/config-transformer.php +++ b/bin/config-transformer.php @@ -4,6 +4,7 @@ use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\ConsoleOutput; +use Symplify\ConfigTransformer\Console\ConfigTransformerApplication; use Symplify\ConfigTransformer\Kernel\ConfigTransformerContainerFactory; $possibleAutoloadPaths = [ @@ -27,12 +28,11 @@ require_once $scoperAutoloadFilepath; } -$configTransformerKernel = new ConfigTransformerContainerFactory(); -$configTransformerKernel->boot(); +$configTransformerContainerFactory = new ConfigTransformerContainerFactory(); +$container = $configTransformerContainerFactory->create(); -$container = $configTransformerKernel->getContainer(); - -$configTransformerApplication = $container->get(\Symplify\ConfigTransformer\Console\ConfigTransformerApplication::class); +/** @var ConfigTransformerApplication $configTransformerApplication */ +$configTransformerApplication = $container->get(ConfigTransformerApplication::class); $input = new ArgvInput(); $output = new ConsoleOutput(); diff --git a/phpstan.neon b/phpstan.neon index 02c9e3ebb77..cc368556d89 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,6 +2,7 @@ parameters: level: 8 paths: + - bin - src - config - tests diff --git a/rector.php b/rector.php index eac02194b32..2a97dee215d 100644 --- a/rector.php +++ b/rector.php @@ -10,18 +10,19 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->sets([ PHPUnitSetList::PHPUNIT_100, + PHPUnitSetList::PHPUNIT_CODE_QUALITY, + LevelSetList::UP_TO_PHP_81, SetList::CODE_QUALITY, SetList::DEAD_CODE, - LevelSetList::UP_TO_PHP_81, SetList::CODING_STYLE, SetList::TYPE_DECLARATION, SetList::NAMING, SetList::PRIVATIZATION, SetList::EARLY_RETURN, - PHPUnitSetList::PHPUNIT_CODE_QUALITY, ]); $rectorConfig->paths([ + __DIR__ . '/bin', __DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/tests',