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

Commit

Permalink
chore(deps): upgrade services to make it work with 8.2.*
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwurtz authored and Korbeil committed Mar 14, 2024
1 parent 37aaeb2 commit 3cb1ad3
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 14 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 23 additions & 1 deletion 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,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;
Expand All @@ -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)
Expand Down Expand Up @@ -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']);
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
9 changes: 9 additions & 0 deletions src/Resources/config/custom_transformers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?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" />
</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

0 comments on commit 3cb1ad3

Please sign in to comment.