From e68bd61a98ee0401fd8ac3720de7c19484e27946 Mon Sep 17 00:00:00 2001 From: Joel Wurtz Date: Mon, 11 Mar 2024 15:16:47 +0100 Subject: [PATCH] chore(deps): upgrade services to make it work with 8.2.* --- composer.json | 3 ++- .../AutoMapperExtension.php | 26 +++++++++++++++++-- .../Compiler/PropertyInfoPass.php | 4 +++ src/Resources/config/custom_transformers.xml | 9 +++++++ src/Resources/config/generator.xml | 19 ++++++++++++++ src/Resources/config/mapper_generator.xml | 22 ++++++++++++++++ src/Resources/config/services.xml | 13 +--------- 7 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 src/Resources/config/custom_transformers.xml create mode 100644 src/Resources/config/generator.xml create mode 100644 src/Resources/config/mapper_generator.xml diff --git a/composer.json b/composer.json index bb027ed..2881d41 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,9 @@ "phpstan/phpdoc-parser": "^1.25" }, "require-dev": { + "nikic/php-parser": "^4.18 || ^5.0", "moneyphp/money": "^4.2", - "phpunit/phpunit": "^8.0", + "phpunit/phpunit": "^9.0", "symfony/framework-bundle": "^6.0 || ^7.0", "symfony/uid": "^6.3 || ^7.0", "symfony/yaml": "^6.3 || ^7.0" diff --git a/src/DependencyInjection/AutoMapperExtension.php b/src/DependencyInjection/AutoMapperExtension.php index 6346bac..03a6ce3 100644 --- a/src/DependencyInjection/AutoMapperExtension.php +++ b/src/DependencyInjection/AutoMapperExtension.php @@ -2,6 +2,7 @@ namespace AutoMapper\Bundle\DependencyInjection; +use AutoMapper\Bundle\AutoMapper; use AutoMapper\Bundle\CacheWarmup\CacheWarmerLoaderInterface; use AutoMapper\Bundle\CacheWarmup\ConfigurationCacheWarmerLoader; use AutoMapper\Bundle\Configuration\MapperConfigurationInterface; @@ -12,6 +13,7 @@ use AutoMapper\MapperGeneratorMetadataFactory; use AutoMapper\MapperGeneratorMetadataInterface; use AutoMapper\Normalizer\AutoMapperNormalizer; +use AutoMapper\Transformer\CustomTransformer\CustomTransformersRegistry; use AutoMapper\Transformer\SymfonyUidTransformerFactory; use AutoMapper\Transformer\TransformerFactoryInterface; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -24,7 +26,7 @@ class AutoMapperExtension extends Extension { - public function getConfiguration(array $config, ContainerBuilder $container): null|ConfigurationInterface + public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface { return new Configuration($container->getParameter('kernel.debug')); } @@ -38,6 +40,17 @@ public function load(array $configs, ContainerBuilder $container): void $container->registerForAutoconfiguration(MapperConfigurationInterface::class)->addTag('automapper.mapper_configuration'); $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + + if (class_exists(Generator::class)) { + $loader->load('generator.xml'); + } else { + $loader->load('mapper_generator.xml'); + } + + if (class_exists(CustomTransformersRegistry::class)) { + $loader->load('custom_transformers.xml'); + } + $loader->load('services.xml'); $container->getDefinition(MapperGeneratorMetadataFactory::class) @@ -70,7 +83,16 @@ public function load(array $configs, ContainerBuilder $container): void ->addArgument(new Reference($config['name_converter'])); } - if ($config['allow_readonly_target_to_populate']) { + if (class_exists(CustomTransformersRegistry::class)) { + $autoMapperDefinition = $container->getDefinition(AutoMapper::class); + + $mapperDefinition = $autoMapperDefinition->getArgument(2); + + $autoMapperDefinition->replaceArgument(2, new Reference(CustomTransformersRegistry::class)); + $autoMapperDefinition->addArgument($mapperDefinition); + } + + if (class_exists(Generator::class) && $config['allow_readonly_target_to_populate']) { $container ->getDefinition(Generator::class) ->replaceArgument(2, $config['allow_readonly_target_to_populate']); diff --git a/src/DependencyInjection/Compiler/PropertyInfoPass.php b/src/DependencyInjection/Compiler/PropertyInfoPass.php index 1a2f1e8..a268f82 100644 --- a/src/DependencyInjection/Compiler/PropertyInfoPass.php +++ b/src/DependencyInjection/Compiler/PropertyInfoPass.php @@ -25,6 +25,10 @@ public function process(ContainerBuilder $container): void new Definition( ReflectionExtractor::class, [ + '$mutatorPrefixes' => null, + '$accessorPrefixes' => null, + '$arrayMutatorPrefixes' => null, + '$enableConstructorExtraction' => true, '$accessFlags' => ReflectionExtractor::ALLOW_PUBLIC | ReflectionExtractor::ALLOW_PROTECTED | ReflectionExtractor::ALLOW_PRIVATE, ] ) diff --git a/src/Resources/config/custom_transformers.xml b/src/Resources/config/custom_transformers.xml new file mode 100644 index 0000000..9cfc64c --- /dev/null +++ b/src/Resources/config/custom_transformers.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/src/Resources/config/generator.xml b/src/Resources/config/generator.xml new file mode 100644 index 0000000..a175e05 --- /dev/null +++ b/src/Resources/config/generator.xml @@ -0,0 +1,19 @@ + + + + + + + %automapper.cache_dir% + + + + + null + + false + + + diff --git a/src/Resources/config/mapper_generator.xml b/src/Resources/config/mapper_generator.xml new file mode 100644 index 0000000..2b6a8c3 --- /dev/null +++ b/src/Resources/config/mapper_generator.xml @@ -0,0 +1,22 @@ + + + + + + + %automapper.cache_dir% + + + + + + false + + + + + + + diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index eba5e4b..ed61a68 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -46,20 +46,9 @@ - - - %automapper.cache_dir% - - - - null - - false - - -