Skip to content

Commit

Permalink
feat(symfony): remove useless pass for property info, remove cache (#166
Browse files Browse the repository at this point in the history
)

I remove the compiler pass for property info, i think it was useless.

I also removed the cache for property info, we don't need it and it was
causing DX issues when changing metadata of a class (as data was cached
and not correctly reload)

Last thing i used only our own services for property info, i don't want
that other configuration messing up with our way of configuring those
classes
  • Loading branch information
Korbeil authored Jun 20, 2024
2 parents d3029fc + 8fc007f commit d993a89
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 89 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- [GH#166](https://github.com/jolicode/automapper/pull/166) Remove cache for property info, use specific services instead

## [9.1.1] - 2024-06-19
### Fixed
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Bundle/AutoMapperBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace AutoMapper\Symfony\Bundle;

use AutoMapper\Symfony\Bundle\DependencyInjection\AutoMapperExtension;
use AutoMapper\Symfony\Bundle\DependencyInjection\Compiler\PropertyInfoPass;
use AutoMapper\Symfony\Bundle\DependencyInjection\Compiler\TransformerFactoryPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
Expand All @@ -17,7 +16,6 @@ public function build(ContainerBuilder $container): void
{
parent::build($container);

$container->addCompilerPass(new PropertyInfoPass());
$container->addCompilerPass(new TransformerFactoryPass());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Uid\AbstractUid;
Expand Down Expand Up @@ -53,6 +54,7 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('expression_language.php');
$loader->load('generator.php');
$loader->load('metadata.php');
$loader->load('property_info.php');
$loader->load('provider.php');
$loader->load('symfony.php');
$loader->load('transformers.php');
Expand All @@ -67,6 +69,11 @@ public function load(array $configs, ContainerBuilder $container): void
->setArgument('$allowReadOnlyTargetToPopulate', $config['allow_readonly_target_to_populate'])
;

if ($config['map_private_properties']) {
$container->getDefinition('automapper.property_info.reflection_extractor')
->replaceArgument('$accessFlags', ReflectionExtractor::ALLOW_PUBLIC | ReflectionExtractor::ALLOW_PRIVATE | ReflectionExtractor::ALLOW_PROTECTED);
}

$container->setParameter('automapper.map_private_properties', $config['map_private_properties']);

$container->registerForAutoconfiguration(PropertyTransformerInterface::class)->addTag('automapper.property_transformer');
Expand Down

This file was deleted.

34 changes: 34 additions & 0 deletions src/Symfony/Bundle/Resources/config/property_info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use AutoMapper\Extractor\ReadWriteTypeExtractor;
use Symfony\Component\PropertyInfo\Extractor\PhpStanExtractor;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;

return static function (ContainerConfigurator $container) {
$container
->services()
->set('automapper.property_info.reflection_extractor', ReflectionExtractor::class)
->args([
'$mutatorPrefixes' => null,
'$accessorPrefixes' => null,
'$arrayMutatorPrefixes' => null,
'$enableConstructorExtraction' => true,
'$accessFlags' => ReflectionExtractor::ALLOW_PUBLIC,
])
->set('automapper.property_info.read_write_type_extractor', ReadWriteTypeExtractor::class)
->set('automapper.property_info.phpstan_extractor', PhpStanExtractor::class)
->set('automapper.property_info', PropertyInfoExtractor::class)
->args([
[service('automapper.property_info.reflection_extractor')],
[service('automapper.property_info.read_write_type_extractor'), service('automapper.property_info.phpstan_extractor'), service('automapper.property_info.reflection_extractor')],
[service('automapper.property_info.reflection_extractor')],
[service('automapper.property_info.reflection_extractor')],
[service('automapper.property_info.reflection_extractor')],
])
;
};

0 comments on commit d993a89

Please sign in to comment.