Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

chore(deps): upgrade services to make it work with 8.2.* #12

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ jobs:
env:
SYMFONY_REQUIRE: "${{ matrix.symfony-versions }}"
- name: tests
run: vendor/bin/phpunit
run: SYMFONY_DEPRECATIONS_HELPER="disabled=1" vendor/bin/simple-phpunit
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
},
"require-dev": {
"moneyphp/money": "^4.2",
"phpunit/phpunit": "^8.0",
"nikic/php-parser": "^4.18 || ^5.0",
"symfony/framework-bundle": "^6.0 || ^7.0",
"symfony/phpunit-bridge": "^7.0",
"symfony/uid": "^6.3 || ^7.0",
"symfony/yaml": "^6.3 || ^7.0"
},
"conflict": {
"symfony/framework-bundle": "5.1.0",
"jolicode/automapper": ">=8.2"
"symfony/framework-bundle": "5.1.0"
},
"autoload": {
"psr-4": {
Expand Down
29 changes: 27 additions & 2 deletions src/DependencyInjection/AutoMapperExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,6 +13,8 @@
use AutoMapper\MapperGeneratorMetadataFactory;
use AutoMapper\MapperGeneratorMetadataInterface;
use AutoMapper\Normalizer\AutoMapperNormalizer;
use AutoMapper\Transformer\CustomTransformer\CustomTransformerInterface;
use AutoMapper\Transformer\CustomTransformer\CustomTransformersRegistry;
use AutoMapper\Transformer\SymfonyUidTransformerFactory;
use AutoMapper\Transformer\TransformerFactoryInterface;
use Symfony\Component\Config\Definition\ConfigurationInterface;
Expand All @@ -38,7 +41,16 @@ 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'));
$loader->load('services.xml');

if (class_exists(Generator::class)) {
$loader->load('generator.xml');
$loader->load('services.xml');
} else {
// AutoMapper 8.2
$loader->load('mapper_generator.xml');
$loader->load('custom_transformers.xml');
$loader->load('services_82.xml');
}

$container->getDefinition(MapperGeneratorMetadataFactory::class)
->replaceArgument(5, $config['date_time_format'])
Expand All @@ -48,6 +60,10 @@ public function load(array $configs, ContainerBuilder $container): void
$container->getDefinition(FileLoader::class)->replaceArgument(2, $config['hot_reload']);
$container->registerForAutoconfiguration(TransformerFactoryInterface::class)->addTag('automapper.transformer_factory');

if (interface_exists(CustomTransformerInterface::class)) {
$container->registerForAutoconfiguration(CustomTransformerInterface::class)->addTag('automapper.custom_transformer');
}

if (class_exists(AbstractUid::class)) {
$container
->getDefinition(SymfonyUidTransformerFactory::class)
Expand All @@ -70,7 +86,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']);
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/Compiler/PropertyInfoPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
)
Expand Down
25 changes: 23 additions & 2 deletions src/DependencyInjection/Compiler/TransformerFactoryPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace AutoMapper\Bundle\DependencyInjection\Compiler;

use AutoMapper\Generator\Generator;
use AutoMapper\Transformer\ChainTransformerFactory;
use AutoMapper\Transformer\CustomTransformer\CustomTransformerInterface;
use AutoMapper\Transformer\CustomTransformer\CustomTransformersRegistry;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -13,10 +16,28 @@ class TransformerFactoryPass implements CompilerPassInterface

public function process(ContainerBuilder $container): void
{
$selectors = [];

foreach ($this->findAndSortTaggedServices('automapper.transformer_factory', $container) as $definition) {
$selectors[] = $definition;
}

$definition = $container->getDefinition(ChainTransformerFactory::class);

foreach ($this->findAndSortTaggedServices('automapper.transformer_factory', $container) as $factory) {
$definition->addMethodCall('addTransformerFactory', [$factory]);
if (class_exists(Generator::class)) {
foreach ($selectors as $selector) {
$definition->addMethodCall('addTransformerFactory', [$selector]);
}
} else {
$definition->replaceArgument(0, $selectors);
}

if (interface_exists(CustomTransformerInterface::class)) {
$registry = $container->getDefinition(CustomTransformersRegistry::class);

foreach ($this->findAndSortTaggedServices('automapper.custom_transformer', $container) as $definition) {
$registry->addMethodCall('addCustomTransformer', [$definition]);
}
}
}
}
14 changes: 14 additions & 0 deletions src/Resources/config/custom_transformers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="AutoMapper\Transformer\CustomTransformer\CustomTransformersRegistry" />

<service id="AutoMapper\Transformer\CustomTransformer\CustomTransformerFactory">
<argument type="service" id="AutoMapper\Transformer\CustomTransformer\CustomTransformersRegistry" />
<tag name="automapper.transformer_factory" priority="1003" />
</service>
</services>
</container>
19 changes: 19 additions & 0 deletions src/Resources/config/generator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="AutoMapper\Loader\FileLoader">
<argument type="service" id="AutoMapper\Generator\Generator" />
<argument type="string">%automapper.cache_dir%</argument>
<argument></argument> <!-- Hot reload -->
</service>

<service id="AutoMapper\Generator\Generator">
<argument>null</argument>
<argument type="service" id="automapper.mapping.class_discriminator_from_class_metadata" />
<argument>false</argument>
</service>
</services>
</container>
22 changes: 22 additions & 0 deletions src/Resources/config/mapper_generator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="AutoMapper\Loader\FileLoader">
<argument type="service" id="AutoMapper\Generator\MapperGenerator" />
<argument type="string">%automapper.cache_dir%</argument>
<argument></argument> <!-- Hot reload -->
</service>

<service id="AutoMapper\Generator\MapperGenerator">
<argument type="service" id="AutoMapper\Generator\Shared\ClassDiscriminatorResolver" />
<argument>false</argument>
</service>

<service id="AutoMapper\Generator\Shared\ClassDiscriminatorResolver">
<argument type="service" id="automapper.mapping.class_discriminator_from_class_metadata" />
</service>
</services>
</container>
13 changes: 1 addition & 12 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,9 @@
</service>
<service id="AutoMapper\MapperGeneratorMetadataFactoryInterface" alias="AutoMapper\MapperGeneratorMetadataFactory" />

<service id="AutoMapper\Loader\FileLoader">
<argument type="service" id="AutoMapper\Generator\Generator" />
<argument type="string">%automapper.cache_dir%</argument>
<argument></argument> <!-- Hot reload -->
</service>
<service id="AutoMapper\Loader\ClassLoaderInterface" alias="AutoMapper\Loader\FileLoader" />

<service id="AutoMapper\Generator\Generator">
<argument>null</argument>
<argument type="service" id="jane.mapping.class_discriminator_from_class_metadata" />
<argument>false</argument>
</service>

<service id="jane.mapping.class_discriminator_from_class_metadata" class="Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata">
<service id="automapper.mapping.class_discriminator_from_class_metadata" class="Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata">
<argument type="service" id="serializer.mapping.class_metadata_factory" />
</service>

Expand Down
112 changes: 112 additions & 0 deletions src/Resources/config/services_82.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="AutoMapper\Bundle\AutoMapper">
<argument type="service" id="AutoMapper\Loader\ClassLoaderInterface" />
<argument type="service" id="AutoMapper\Transformer\ChainTransformerFactory" />
<argument type="service" id="AutoMapper\MapperGeneratorMetadataFactoryInterface" />

</service>
<service id="AutoMapper\AutoMapperInterface" alias="AutoMapper\Bundle\AutoMapper" public="true" />
<service id="AutoMapper\AutoMapperRegistryInterface" alias="AutoMapper\Bundle\AutoMapper" public="true" />

<service id="AutoMapper\Extractor\SourceTargetMappingExtractor">
<argument type="service" id="automapper.property_info" />
<argument type="service" id="automapper.property_info.reflection_extractor" />
<argument type="service" id="automapper.property_info.reflection_extractor" />
<argument type="service" id="AutoMapper\Transformer\TransformerFactoryInterface" />
</service>

<service id="AutoMapper\Extractor\FromTargetMappingExtractor">
<argument type="service" id="automapper.property_info" />
<argument type="service" id="automapper.property_info.reflection_extractor" />
<argument type="service" id="automapper.property_info.reflection_extractor" />
<argument type="service" id="AutoMapper\Transformer\TransformerFactoryInterface" />
<argument type="service" id="serializer.mapping.class_metadata_factory" />
</service>

<service id="AutoMapper\Extractor\FromSourceMappingExtractor">
<argument type="service" id="automapper.property_info" />
<argument type="service" id="automapper.property_info.reflection_extractor" />
<argument type="service" id="automapper.property_info.reflection_extractor" />
<argument type="service" id="AutoMapper\Transformer\TransformerFactoryInterface" />
<argument type="service" id="serializer.mapping.class_metadata_factory" />
</service>

<service id="AutoMapper\MapperGeneratorMetadataFactory">
<argument type="service" id="AutoMapper\Extractor\SourceTargetMappingExtractor" />
<argument type="service" id="AutoMapper\Extractor\FromSourceMappingExtractor" />
<argument type="service" id="AutoMapper\Extractor\FromTargetMappingExtractor" />
<argument>Symfony_Mapper_</argument>
<argument>true</argument>
<argument></argument> <!-- Date time format -->
<argument></argument> <!-- map_private_properties -->
</service>
<service id="AutoMapper\MapperGeneratorMetadataFactoryInterface" alias="AutoMapper\MapperGeneratorMetadataFactory" />

<service id="AutoMapper\Loader\ClassLoaderInterface" alias="AutoMapper\Loader\FileLoader" />

<service id="automapper.mapping.class_discriminator_from_class_metadata" class="Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata">
<argument type="service" id="serializer.mapping.class_metadata_factory" />
</service>

<service id="AutoMapper\Transformer\ChainTransformerFactory">
<argument type="collection" />
</service>

<service id="AutoMapper\Transformer\TransformerFactoryInterface" alias="AutoMapper\Transformer\ChainTransformerFactory" />

<service id="AutoMapper\Normalizer\AutoMapperNormalizer">
<argument type="service" id="AutoMapper\AutoMapperInterface" />
</service>

<service id="AutoMapper\Transformer\MultipleTransformerFactory">
<tag name="automapper.transformer_factory" priority="1002" />
</service>

<service id="AutoMapper\Transformer\NullableTransformerFactory">
<tag name="automapper.transformer_factory" priority="1001" />
</service>

<service id="AutoMapper\Transformer\UniqueTypeTransformerFactory">
<tag name="automapper.transformer_factory" priority="1000" />
</service>

<service id="AutoMapper\Transformer\EnumTransformerFactory">
<tag name="automapper.transformer_factory" priority="-999" />
</service>

<service id="AutoMapper\Transformer\DateTimeTransformerFactory">
<tag name="automapper.transformer_factory" priority="-1000" />
</service>

<service id="AutoMapper\Transformer\BuiltinTransformerFactory">
<tag name="automapper.transformer_factory" priority="-1001" />
</service>

<service id="AutoMapper\Transformer\ArrayTransformerFactory">
<tag name="automapper.transformer_factory" priority="-1002" />
</service>

<service id="AutoMapper\Transformer\ObjectTransformerFactory">
<tag name="automapper.transformer_factory" priority="-1003" />
</service>

<service id="AutoMapper\Transformer\SymfonyUidTransformerFactory" />

<service id="AutoMapper\Bundle\CacheWarmup\CacheWarmer">
<argument type="service" id="AutoMapper\AutoMapperRegistryInterface" />
<argument type="tagged_iterator" tag="automapper.cache_warmer_loader" />
<argument type="string">%automapper.cache_dir%</argument>
<tag name="kernel.cache_warmer" />
</service>

<service id="AutoMapper\Bundle\CacheWarmup\ConfigurationCacheWarmerLoader">
<argument/> <!-- mappers list from config -->
<tag name="automapper.cache_warmer_loader" />
</service>
</services>
</container>
Loading
Loading