Repository: symfony/symfony
File: src/Symfony/Bundle/FrameworkBundle/Resources/config/object_mapper.php (PHP)

Code before:
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\ObjectMapper\Metadata\ObjectMapperMetadataFactoryInterface;
use Symfony\Component\ObjectMapper\Metadata\ReflectionObjectMapperMetadataFactory;
use Symfony\Component\ObjectMapper\ObjectMapper;
use Symfony\Component\ObjectMapper\ObjectMapperInterface;

return static function (ContainerConfigurator $container) {
    $container->services()
        ->set('object_mapper.metadata_factory', ReflectionObjectMapperMetadataFactory::class)
            ->args([
                '%object_mapper.map_classes%',
            ])
        ->alias(ObjectMapperMetadataFactoryInterface::class, 'object_mapper.metadata_factory')

        ->set('object_mapper', ObjectMapper::class)
            ->args([
                service('object_mapper.metadata_factory'),
                service('property_accessor')->ignoreOnInvalid(),
                tagged_locator('object_mapper.transform_callable'),
                tagged_locator('object_mapper.condition_callable'),
            ])
        ->alias(ObjectMapperInterface::class, 'object_mapper')
    ;
};


Review comment (suggestion):
After a discussion at the hackday, can we create a new `ObjectMapperMetadataFactory` (`ReverseClassObjectMapperMetadataFactory`). This one will decorate the `object_mapper.metadata_factory` service. 

Code after:
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Symfony\Component\ObjectMapper\Metadata\ObjectMapperMetadataFactoryInterface;
use Symfony\Component\ObjectMapper\Metadata\ReflectionObjectMapperMetadataFactory;
use Symfony\Component\ObjectMapper\Metadata\ReverseClassObjectMapperMetadataFactory;
use Symfony\Component\ObjectMapper\ObjectMapper;
use Symfony\Component\ObjectMapper\ObjectMapperInterface;

return static function (ContainerConfigurator $container) {
    $container->services()
        ->set('object_mapper.metadata_factory', ReflectionObjectMapperMetadataFactory::class)
        ->alias(ObjectMapperMetadataFactoryInterface::class, 'object_mapper.metadata_factory')

        ->set('object_mapper.metadata_factory.reverse_class', ReverseClassObjectMapperMetadataFactory::class)
            ->decorate('object_mapper.metadata_factory')
            ->args([
                service('.inner'),
                abstract_arg('class_map'),
            ])

        ->set('object_mapper', ObjectMapper::class)
            ->args([
                service('object_mapper.metadata_factory'),
                service('property_accessor')->ignoreOnInvalid(),
                tagged_locator('object_mapper.transform_callable'),
                tagged_locator('object_mapper.condition_callable'),
            ])
        ->alias(ObjectMapperInterface::class, 'object_mapper')
    ;
};