vendor/doctrine/doctrine-bundle/DependencyInjection/DoctrineExtension.php line 569

Open in your IDE?
  1. <?php
  2. namespace Doctrine\Bundle\DoctrineBundle\DependencyInjection;
  3. use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
  4. use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
  5. use Doctrine\Bundle\DoctrineBundle\Attribute\AsMiddleware;
  6. use Doctrine\Bundle\DoctrineBundle\CacheWarmer\DoctrineMetadataCacheWarmer;
  7. use Doctrine\Bundle\DoctrineBundle\ConnectionFactory;
  8. use Doctrine\Bundle\DoctrineBundle\Dbal\ManagerRegistryAwareConnectionProvider;
  9. use Doctrine\Bundle\DoctrineBundle\Dbal\RegexSchemaAssetFilter;
  10. use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\IdGeneratorPass;
  11. use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass;
  12. use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
  13. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
  14. use Doctrine\Common\Annotations\Annotation;
  15. use Doctrine\DBAL\Connection;
  16. use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
  17. use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface;
  18. use Doctrine\DBAL\Schema\LegacySchemaManagerFactory;
  19. use Doctrine\ORM\Configuration as OrmConfiguration;
  20. use Doctrine\ORM\EntityManagerInterface;
  21. use Doctrine\ORM\Events;
  22. use Doctrine\ORM\Id\AbstractIdGenerator;
  23. use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver;
  24. use Doctrine\ORM\Proxy\Autoloader;
  25. use Doctrine\ORM\Proxy\ProxyFactory;
  26. use Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand;
  27. use Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand;
  28. use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
  29. use Doctrine\ORM\UnitOfWork;
  30. use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
  31. use InvalidArgumentException;
  32. use LogicException;
  33. use Symfony\Bridge\Doctrine\ArgumentResolver\EntityValueResolver;
  34. use Symfony\Bridge\Doctrine\Attribute\MapEntity;
  35. use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
  36. use Symfony\Bridge\Doctrine\IdGenerator\UlidGenerator;
  37. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  38. use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor;
  39. use Symfony\Bridge\Doctrine\SchemaListener\DoctrineDbalCacheAdapterSchemaListener;
  40. use Symfony\Bridge\Doctrine\SchemaListener\LockStoreSchemaListener;
  41. use Symfony\Bridge\Doctrine\SchemaListener\MessengerTransportDoctrineSchemaListener;
  42. use Symfony\Bridge\Doctrine\SchemaListener\PdoCacheAdapterDoctrineSchemaSubscriber;
  43. use Symfony\Bridge\Doctrine\SchemaListener\PdoSessionHandlerSchemaListener;
  44. use Symfony\Bridge\Doctrine\SchemaListener\RememberMeTokenProviderDoctrineSchemaListener;
  45. use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
  46. use Symfony\Component\Cache\Adapter\ArrayAdapter;
  47. use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
  48. use Symfony\Component\Config\Definition\ConfigurationInterface;
  49. use Symfony\Component\Config\FileLocator;
  50. use Symfony\Component\DependencyInjection\Alias;
  51. use Symfony\Component\DependencyInjection\ChildDefinition;
  52. use Symfony\Component\DependencyInjection\ContainerBuilder;
  53. use Symfony\Component\DependencyInjection\Definition;
  54. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  55. use Symfony\Component\DependencyInjection\Reference;
  56. use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
  57. use Symfony\Component\Form\AbstractType;
  58. use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransportFactory;
  59. use Symfony\Component\Messenger\MessageBusInterface;
  60. use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
  61. use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
  62. use Symfony\Component\VarExporter\LazyGhostTrait;
  63. use function array_intersect_key;
  64. use function array_keys;
  65. use function array_merge;
  66. use function class_exists;
  67. use function interface_exists;
  68. use function is_dir;
  69. use function method_exists;
  70. use function reset;
  71. use function sprintf;
  72. use function str_replace;
  73. use function trait_exists;
  74. use function trigger_deprecation;
  75. use const PHP_VERSION_ID;
  76. /**
  77.  * DoctrineExtension is an extension for the Doctrine DBAL and ORM library.
  78.  *
  79.  * @final since 2.9
  80.  */
  81. class DoctrineExtension extends AbstractDoctrineExtension
  82. {
  83.     private string $defaultConnection;
  84.     /**
  85.      * {@inheritDoc}
  86.      *
  87.      * @return void
  88.      */
  89.     public function load(array $configsContainerBuilder $container)
  90.     {
  91.         $configuration $this->getConfiguration($configs$container);
  92.         $config        $this->processConfigurationPrependingDefaults($configuration$configs);
  93.         if (! empty($config['dbal'])) {
  94.             $this->dbalLoad($config['dbal'], $container);
  95.             $this->loadMessengerServices($container);
  96.         }
  97.         if (empty($config['orm'])) {
  98.             return;
  99.         }
  100.         if (empty($config['dbal'])) {
  101.             throw new LogicException('Configuring the ORM layer requires to configure the DBAL layer as well.');
  102.         }
  103.         $this->ormLoad($config['orm'], $container);
  104.     }
  105.     /**
  106.      * Process user configuration and adds a default DBAL connection and/or a
  107.      * default EM if required, then process again the configuration to get
  108.      * default values for each.
  109.      *
  110.      * @param array<array<mixed>> $configs
  111.      *
  112.      * @return array<mixed>
  113.      */
  114.     private function processConfigurationPrependingDefaults(ConfigurationInterface $configuration, array $configs): array
  115.     {
  116.         $config      $this->processConfiguration($configuration$configs);
  117.         $configToAdd = [];
  118.         // if no DB connection defined, prepend an empty one for the default
  119.         // connection name in order to make Symfony Config resolve the default
  120.         // values
  121.         if (isset($config['dbal']) && empty($config['dbal']['connections'])) {
  122.             $configToAdd['dbal'] = ['connections' => [($config['dbal']['default_connection'] ?? 'default') => []]];
  123.         }
  124.         // if no EM defined, prepend an empty one for the default EM name in
  125.         // order to make Symfony Config resolve the default values
  126.         if (isset($config['orm']) && empty($config['orm']['entity_managers'])) {
  127.             $configToAdd['orm'] = ['entity_managers' => [($config['orm']['default_entity_manager'] ?? 'default') => []]];
  128.         }
  129.         if (! $configToAdd) {
  130.             return $config;
  131.         }
  132.         return $this->processConfiguration($configurationarray_merge([$configToAdd], $configs));
  133.     }
  134.     /**
  135.      * Loads the DBAL configuration.
  136.      *
  137.      * Usage example:
  138.      *
  139.      *      <doctrine:dbal id="myconn" dbname="sfweb" user="root" />
  140.      *
  141.      * @param array<string, mixed> $config    An array of configuration settings
  142.      * @param ContainerBuilder     $container A ContainerBuilder instance
  143.      */
  144.     protected function dbalLoad(array $configContainerBuilder $container)
  145.     {
  146.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/../Resources/config'));
  147.         $loader->load('dbal.xml');
  148.         if (empty($config['default_connection'])) {
  149.             $keys                         array_keys($config['connections']);
  150.             $config['default_connection'] = reset($keys);
  151.         }
  152.         $this->defaultConnection $config['default_connection'];
  153.         $container->setAlias('database_connection'sprintf('doctrine.dbal.%s_connection'$this->defaultConnection));
  154.         $container->getAlias('database_connection')->setPublic(true);
  155.         $container->setAlias('doctrine.dbal.event_manager', new Alias(sprintf('doctrine.dbal.%s_connection.event_manager'$this->defaultConnection), false));
  156.         $container->setParameter('doctrine.dbal.connection_factory.types'$config['types']);
  157.         $container->getDefinition('doctrine.dbal.connection_factory.dsn_parser')->setArgument(0array_merge(ConnectionFactory::DEFAULT_SCHEME_MAP$config['driver_schemes']));
  158.         $connections = [];
  159.         foreach (array_keys($config['connections']) as $name) {
  160.             $connections[$name] = sprintf('doctrine.dbal.%s_connection'$name);
  161.         }
  162.         $container->setParameter('doctrine.connections'$connections);
  163.         $container->setParameter('doctrine.default_connection'$this->defaultConnection);
  164.         $connWithLogging   = [];
  165.         $connWithProfiling = [];
  166.         $connWithBacktrace = [];
  167.         foreach ($config['connections'] as $name => $connection) {
  168.             if ($connection['logging']) {
  169.                 $connWithLogging[] = $name;
  170.             }
  171.             if ($connection['profiling']) {
  172.                 $connWithProfiling[] = $name;
  173.                 if ($connection['profiling_collect_backtrace']) {
  174.                     $connWithBacktrace[] = $name;
  175.                 }
  176.             }
  177.             $this->loadDbalConnection($name$connection$container);
  178.         }
  179.         $container->registerForAutoconfiguration(MiddlewareInterface::class)->addTag('doctrine.middleware');
  180.         $container->registerAttributeForAutoconfiguration(AsMiddleware::class, static function (ChildDefinition $definitionAsMiddleware $attribute) {
  181.             $priority = isset($attribute->priority) ? ['priority' => $attribute->priority] : [];
  182.             if ($attribute->connections === []) {
  183.                 $definition->addTag('doctrine.middleware'$priority);
  184.                 return;
  185.             }
  186.             foreach ($attribute->connections as $connName) {
  187.                 $definition->addTag('doctrine.middleware'array_merge($priority, ['connection' => $connName]));
  188.             }
  189.         });
  190.         $this->registerDbalMiddlewares($container$connWithLogging$connWithProfiling$connWithBacktrace);
  191.     }
  192.     /**
  193.      * Loads a configured DBAL connection.
  194.      *
  195.      * @param string               $name       The name of the connection
  196.      * @param array<string, mixed> $connection A dbal connection configuration.
  197.      * @param ContainerBuilder     $container  A ContainerBuilder instance
  198.      */
  199.     protected function loadDbalConnection($name, array $connectionContainerBuilder $container)
  200.     {
  201.         $configuration $container->setDefinition(sprintf('doctrine.dbal.%s_connection.configuration'$name), new ChildDefinition('doctrine.dbal.connection.configuration'));
  202.         unset($connection['logging']);
  203.         $dataCollectorDefinition $container->getDefinition('data_collector.doctrine');
  204.         $dataCollectorDefinition->replaceArgument(1$connection['profiling_collect_schema_errors']);
  205.         unset(
  206.             $connection['profiling'],
  207.             $connection['profiling_collect_backtrace'],
  208.             $connection['profiling_collect_schema_errors'],
  209.         );
  210.         if (isset($connection['auto_commit'])) {
  211.             $configuration->addMethodCall('setAutoCommit', [$connection['auto_commit']]);
  212.         }
  213.         unset($connection['auto_commit']);
  214.         if (isset($connection['disable_type_comments'])) {
  215.             $configuration->addMethodCall('setDisableTypeComments', [$connection['disable_type_comments']]);
  216.         }
  217.         unset($connection['disable_type_comments']);
  218.         if (isset($connection['schema_filter']) && $connection['schema_filter']) {
  219.             $definition = new Definition(RegexSchemaAssetFilter::class, [$connection['schema_filter']]);
  220.             $definition->addTag('doctrine.dbal.schema_filter', ['connection' => $name]);
  221.             $container->setDefinition(sprintf('doctrine.dbal.%s_regex_schema_filter'$name), $definition);
  222.         }
  223.         unset($connection['schema_filter']);
  224.         // event manager
  225.         $container->setDefinition(sprintf('doctrine.dbal.%s_connection.event_manager'$name), new ChildDefinition('doctrine.dbal.connection.event_manager'));
  226.         // connection
  227.         $options $this->getConnectionOptions($connection);
  228.         $connectionId sprintf('doctrine.dbal.%s_connection'$name);
  229.         $def $container
  230.             ->setDefinition($connectionId, new ChildDefinition('doctrine.dbal.connection'))
  231.             ->setPublic(true)
  232.             ->setArguments([
  233.                 $options,
  234.                 new Reference(sprintf('doctrine.dbal.%s_connection.configuration'$name)),
  235.                 // event manager is only supported on DBAL < 4
  236.                 method_exists(Connection::class, 'getEventManager') ? new Reference(sprintf('doctrine.dbal.%s_connection.event_manager'$name)) : null,
  237.                 $connection['mapping_types'],
  238.             ]);
  239.         $container
  240.             ->registerAliasForArgument($connectionIdConnection::class, sprintf('%sConnection'$name))
  241.             ->setPublic(false);
  242.         // Set class in case "wrapper_class" option was used to assist IDEs
  243.         if (isset($options['wrapperClass'])) {
  244.             $def->setClass($options['wrapperClass']);
  245.         }
  246.         if (! empty($connection['use_savepoints'])) {
  247.             $def->addMethodCall('setNestTransactionsWithSavepoints', [$connection['use_savepoints']]);
  248.         }
  249.         $container->setDefinition(
  250.             ManagerRegistryAwareConnectionProvider::class,
  251.             new Definition(ManagerRegistryAwareConnectionProvider::class, [$container->getDefinition('doctrine')]),
  252.         );
  253.         $configuration->addMethodCall('setSchemaManagerFactory', [new Reference($connection['schema_manager_factory'])]);
  254.         if (isset($connection['result_cache'])) {
  255.             $configuration->addMethodCall('setResultCache', [new Reference($connection['result_cache'])]);
  256.         }
  257.         if (class_exists(LegacySchemaManagerFactory::class)) {
  258.             return;
  259.         }
  260.         $container->removeDefinition('doctrine.dbal.legacy_schema_manager_factory');
  261.     }
  262.     /**
  263.      * @param array<string, mixed> $connection
  264.      *
  265.      * @return mixed[]
  266.      */
  267.     protected function getConnectionOptions(array $connection): array
  268.     {
  269.         $options $connection;
  270.         $connectionDefaults = [
  271.             'host' => 'localhost',
  272.             'port' => null,
  273.             'user' => 'root',
  274.             'password' => null,
  275.         ];
  276.         if ($options['override_url'] ?? false) {
  277.             $options['connection_override_options'] = array_intersect_key($options, ['dbname' => null] + $connectionDefaults);
  278.         }
  279.         unset($options['override_url']);
  280.         unset($options['schema_manager_factory']);
  281.         $options += $connectionDefaults;
  282.         foreach (['replicas''slaves'] as $connectionKey) {
  283.             foreach (array_keys($options[$connectionKey]) as $name) {
  284.                 $options[$connectionKey][$name] += $connectionDefaults;
  285.             }
  286.         }
  287.         if (isset($options['platform_service'])) {
  288.             $options['platform'] = new Reference($options['platform_service']);
  289.             unset($options['platform_service']);
  290.         }
  291.         unset($options['mapping_types']);
  292.         foreach (
  293.             [
  294.                 'options' => 'driverOptions',
  295.                 'driver_class' => 'driverClass',
  296.                 'wrapper_class' => 'wrapperClass',
  297.                 'keep_slave' => 'keepReplica',
  298.                 'keep_replica' => 'keepReplica',
  299.                 'replicas' => 'replica',
  300.                 'server_version' => 'serverVersion',
  301.                 'default_table_options' => 'defaultTableOptions',
  302.             ] as $old => $new
  303.         ) {
  304.             if (! isset($options[$old])) {
  305.                 continue;
  306.             }
  307.             $options[$new] = $options[$old];
  308.             unset($options[$old]);
  309.         }
  310.         foreach (['replica''slaves'] as $connectionKey) {
  311.             foreach ($options[$connectionKey] as $name => $value) {
  312.                 $driverOptions       $value['driverOptions'] ?? [];
  313.                 $parentDriverOptions $options['driverOptions'] ?? [];
  314.                 if ($driverOptions === [] && $parentDriverOptions === []) {
  315.                     continue;
  316.                 }
  317.                 $options[$connectionKey][$name]['driverOptions'] = $driverOptions $parentDriverOptions;
  318.             }
  319.         }
  320.         if (! empty($options['slaves']) || ! empty($options['replica'])) {
  321.             $nonRewrittenKeys = [
  322.                 'driver' => true,
  323.                 'driverClass' => true,
  324.                 'wrapperClass' => true,
  325.                 'keepSlave' => true,
  326.                 'keepReplica' => true,
  327.                 'platform' => true,
  328.                 'slaves' => true,
  329.                 'primary' => true,
  330.                 'replica' => true,
  331.                 'serverVersion' => true,
  332.                 'defaultTableOptions' => true,
  333.                 // included by safety but should have been unset already
  334.                 'logging' => true,
  335.                 'profiling' => true,
  336.                 'mapping_types' => true,
  337.                 'platform_service' => true,
  338.             ];
  339.             foreach ($options as $key => $value) {
  340.                 if (isset($nonRewrittenKeys[$key])) {
  341.                     continue;
  342.                 }
  343.                 $options['primary'][$key] = $value;
  344.                 unset($options[$key]);
  345.             }
  346.             if (empty($options['wrapperClass'])) {
  347.                 // Change the wrapper class only if user did not configure custom one.
  348.                 $options['wrapperClass'] = PrimaryReadReplicaConnection::class;
  349.             }
  350.         } else {
  351.             unset($options['slaves'], $options['replica']);
  352.         }
  353.         return $options;
  354.     }
  355.     /**
  356.      * Loads the Doctrine ORM configuration.
  357.      *
  358.      * Usage example:
  359.      *
  360.      *     <doctrine:orm id="mydm" connection="myconn" />
  361.      *
  362.      * @param array<string, mixed> $config    An array of configuration settings
  363.      * @param ContainerBuilder     $container A ContainerBuilder instance
  364.      */
  365.     protected function ormLoad(array $configContainerBuilder $container)
  366.     {
  367.         if (! class_exists(UnitOfWork::class)) {
  368.             throw new LogicException('To configure the ORM layer, you must first install the doctrine/orm package.');
  369.         }
  370.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/../Resources/config'));
  371.         $loader->load('orm.xml');
  372.         if (class_exists(AbstractType::class)) {
  373.             $container->getDefinition('form.type.entity')->addTag('kernel.reset', ['method' => 'reset']);
  374.         }
  375.         if (! class_exists(Annotation::class)) {
  376.             $container->removeAlias('doctrine.orm.metadata.annotation_reader');
  377.         }
  378.         // available in Symfony 6.3
  379.         $container->removeDefinition('doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_' . (class_exists(DoctrineDbalCacheAdapterSchemaListener::class) ? 'subscriber' 'listener'));
  380.         // available in Symfony 6.3
  381.         $container->removeDefinition('doctrine.orm.listeners.doctrine_token_provider_schema_' . (class_exists(RememberMeTokenProviderDoctrineSchemaListener::class) ? 'subscriber' 'listener'));
  382.         // available in Symfony 5.1 and up to Symfony 5.4 (deprecated)
  383.         if (! class_exists(PdoCacheAdapterDoctrineSchemaSubscriber::class)) {
  384.             $container->removeDefinition('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber');
  385.         }
  386.         if (! class_exists(PdoSessionHandlerSchemaListener::class)) {
  387.             $container->removeDefinition('doctrine.orm.listeners.pdo_session_handler_schema_listener');
  388.         }
  389.         // available in Symfony 6.3 and higher
  390.         if (! class_exists(LockStoreSchemaListener::class)) {
  391.             $container->removeDefinition('doctrine.orm.listeners.lock_store_schema_listener');
  392.         }
  393.         if (! class_exists(UlidGenerator::class)) {
  394.             $container->removeDefinition('doctrine.ulid_generator');
  395.         }
  396.         if (! class_exists(UuidGenerator::class)) {
  397.             $container->removeDefinition('doctrine.uuid_generator');
  398.         }
  399.         // available in Symfony 6.2 and higher
  400.         if (! class_exists(EntityValueResolver::class)) {
  401.             $container->removeDefinition('doctrine.orm.entity_value_resolver');
  402.             $container->removeDefinition('doctrine.orm.entity_value_resolver.expression_language');
  403.         } else {
  404.             if (! class_exists(ExpressionLanguage::class)) {
  405.                 $container->removeDefinition('doctrine.orm.entity_value_resolver.expression_language');
  406.             }
  407.             $controllerResolverDefaults = [];
  408.             if (! $config['controller_resolver']['enabled']) {
  409.                 $controllerResolverDefaults['disabled'] = true;
  410.             }
  411.             if (! $config['controller_resolver']['auto_mapping']) {
  412.                 $controllerResolverDefaults['mapping'] = [];
  413.             }
  414.             if ($config['controller_resolver']['evict_cache']) {
  415.                 $controllerResolverDefaults['evict_cache'] = true;
  416.             }
  417.             if ($controllerResolverDefaults) {
  418.                 $container->getDefinition('doctrine.orm.entity_value_resolver')->setArgument(2, (new Definition(MapEntity::class))->setArguments([
  419.                     null,
  420.                     null,
  421.                     null,
  422.                     $controllerResolverDefaults['mapping'] ?? null,
  423.                     null,
  424.                     null,
  425.                     null,
  426.                     $controllerResolverDefaults['evict_cache'] ?? null,
  427.                     $controllerResolverDefaults['disabled'] ?? false,
  428.                 ]));
  429.             }
  430.         }
  431.         // not available in Doctrine ORM 3.0 and higher
  432.         if (! class_exists(ConvertMappingCommand::class)) {
  433.             $container->removeDefinition('doctrine.mapping_convert_command');
  434.         }
  435.         if (! class_exists(EnsureProductionSettingsCommand::class)) {
  436.             $container->removeDefinition('doctrine.ensure_production_settings_command');
  437.         }
  438.         if (! class_exists(ClassMetadataExporter::class)) {
  439.             $container->removeDefinition('doctrine.mapping_import_command');
  440.         }
  441.         $entityManagers = [];
  442.         foreach (array_keys($config['entity_managers']) as $name) {
  443.             $entityManagers[$name] = sprintf('doctrine.orm.%s_entity_manager'$name);
  444.         }
  445.         $container->setParameter('doctrine.entity_managers'$entityManagers);
  446.         if (empty($config['default_entity_manager'])) {
  447.             $tmp                              array_keys($entityManagers);
  448.             $config['default_entity_manager'] = reset($tmp);
  449.         }
  450.         $container->setParameter('doctrine.default_entity_manager'$config['default_entity_manager']);
  451.         if ($config['enable_lazy_ghost_objects'] ?? false) {
  452.             // available in Symfony 6.2 and higher
  453.             /** @psalm-suppress UndefinedClass */
  454.             if (! trait_exists(LazyGhostTrait::class)) {
  455.                 throw new LogicException(
  456.                     'Lazy ghost objects cannot be enabled because the "symfony/var-exporter" library'
  457.                     ' version 6.2 or higher is not installed. Please run "composer require symfony/var-exporter:^6.2".',
  458.                 );
  459.             }
  460.             if (! class_exists(RuntimeReflectionProperty::class)) {
  461.                 throw new LogicException(
  462.                     'Lazy ghost objects cannot be enabled because the "doctrine/persistence" library'
  463.                     ' version 3.1 or higher is not installed. Please run "composer update doctrine/persistence".',
  464.                 );
  465.             }
  466.         } elseif (! method_exists(ProxyFactory::class, 'resetUninitializedProxy')) {
  467.             throw new LogicException(
  468.                 'Lazy ghost objects cannot be disabled for ORM 3.',
  469.             );
  470.         } elseif (PHP_VERSION_ID >= 80100) {
  471.             trigger_deprecation('doctrine/doctrine-bundle''2.11''Not setting "enable_lazy_ghost_objects" to true is deprecated.');
  472.         }
  473.         $options = ['auto_generate_proxy_classes''enable_lazy_ghost_objects''proxy_dir''proxy_namespace'];
  474.         foreach ($options as $key) {
  475.             $container->setParameter('doctrine.orm.' $key$config[$key]);
  476.         }
  477.         $container->setAlias('doctrine.orm.entity_manager'$defaultEntityManagerDefinitionId sprintf('doctrine.orm.%s_entity_manager'$config['default_entity_manager']));
  478.         $container->getAlias('doctrine.orm.entity_manager')->setPublic(true);
  479.         $config['entity_managers'] = $this->fixManagersAutoMappings($config['entity_managers'], $container->getParameter('kernel.bundles'));
  480.         foreach ($config['entity_managers'] as $name => $entityManager) {
  481.             $entityManager['name'] = $name;
  482.             $this->loadOrmEntityManager($entityManager$container);
  483.             if (interface_exists(PropertyInfoExtractorInterface::class)) {
  484.                 $this->loadPropertyInfoExtractor($name$container);
  485.             }
  486.             if (! interface_exists(LoaderInterface::class)) {
  487.                 continue;
  488.             }
  489.             $this->loadValidatorLoader($name$container);
  490.         }
  491.         if ($config['resolve_target_entities']) {
  492.             $def $container->findDefinition('doctrine.orm.listeners.resolve_target_entity');
  493.             foreach ($config['resolve_target_entities'] as $name => $implementation) {
  494.                 $def->addMethodCall('addResolveTargetEntity', [
  495.                     $name,
  496.                     $implementation,
  497.                     [],
  498.                 ]);
  499.             }
  500.             $def
  501.                 ->addTag('doctrine.event_listener', ['event' => Events::loadClassMetadata])
  502.                 ->addTag('doctrine.event_listener', ['event' => Events::onClassMetadataNotFound]);
  503.         }
  504.         $container->registerForAutoconfiguration(ServiceEntityRepositoryInterface::class)
  505.             ->addTag(ServiceRepositoryCompilerPass::REPOSITORY_SERVICE_TAG);
  506.         $container->registerForAutoconfiguration(EventSubscriberInterface::class)
  507.             ->addTag('doctrine.event_subscriber');
  508.         $container->registerForAutoconfiguration(AbstractIdGenerator::class)
  509.             ->addTag(IdGeneratorPass::ID_GENERATOR_TAG);
  510.         $container->registerAttributeForAutoconfiguration(AsEntityListener::class, static function (ChildDefinition $definitionAsEntityListener $attribute) {
  511.             $definition->addTag('doctrine.orm.entity_listener', [
  512.                 'event'          => $attribute->event,
  513.                 'method'         => $attribute->method,
  514.                 'lazy'           => $attribute->lazy,
  515.                 'entity_manager' => $attribute->entityManager,
  516.                 'entity'         => $attribute->entity,
  517.                 'priority'       => $attribute->priority,
  518.             ]);
  519.         });
  520.         $container->registerAttributeForAutoconfiguration(AsDoctrineListener::class, static function (ChildDefinition $definitionAsDoctrineListener $attribute) {
  521.             $definition->addTag('doctrine.event_listener', [
  522.                 'event'      => $attribute->event,
  523.                 'priority'   => $attribute->priority,
  524.                 'connection' => $attribute->connection,
  525.             ]);
  526.         });
  527.         /** @see DoctrineBundle::boot() */
  528.         $container->getDefinition($defaultEntityManagerDefinitionId)
  529.             ->addTag('container.preload', [
  530.                 'class' => Autoloader::class,
  531.             ]);
  532.     }
  533.     /**
  534.      * Loads a configured ORM entity manager.
  535.      *
  536.      * @param array<string, mixed> $entityManager A configured ORM entity manager.
  537.      * @param ContainerBuilder     $container     A ContainerBuilder instance
  538.      */
  539.     protected function loadOrmEntityManager(array $entityManagerContainerBuilder $container)
  540.     {
  541.         $ormConfigDef $container->setDefinition(sprintf('doctrine.orm.%s_configuration'$entityManager['name']), new ChildDefinition('doctrine.orm.configuration'));
  542.         $ormConfigDef->addTag(IdGeneratorPass::CONFIGURATION_TAG);
  543.         $this->loadOrmEntityManagerMappingInformation($entityManager$ormConfigDef$container);
  544.         $this->loadOrmCacheDrivers($entityManager$container);
  545.         if (isset($entityManager['entity_listener_resolver']) && $entityManager['entity_listener_resolver']) {
  546.             $container->setAlias(sprintf('doctrine.orm.%s_entity_listener_resolver'$entityManager['name']), $entityManager['entity_listener_resolver']);
  547.         } else {
  548.             $definition = new Definition('%doctrine.orm.entity_listener_resolver.class%');
  549.             $definition->addArgument(new Reference('service_container'));
  550.             $container->setDefinition(sprintf('doctrine.orm.%s_entity_listener_resolver'$entityManager['name']), $definition);
  551.         }
  552.         $methods = [
  553.             'setMetadataCache' => new Reference(sprintf('doctrine.orm.%s_metadata_cache'$entityManager['name'])),
  554.             'setQueryCache' => new Reference(sprintf('doctrine.orm.%s_query_cache'$entityManager['name'])),
  555.             'setResultCache' => new Reference(sprintf('doctrine.orm.%s_result_cache'$entityManager['name'])),
  556.             'setMetadataDriverImpl' => new Reference('doctrine.orm.' $entityManager['name'] . '_metadata_driver'),
  557.             'setProxyDir' => '%doctrine.orm.proxy_dir%',
  558.             'setProxyNamespace' => '%doctrine.orm.proxy_namespace%',
  559.             'setAutoGenerateProxyClasses' => '%doctrine.orm.auto_generate_proxy_classes%',
  560.             'setSchemaIgnoreClasses' => $entityManager['schema_ignore_classes'],
  561.             'setClassMetadataFactoryName' => $entityManager['class_metadata_factory_name'],
  562.             'setDefaultRepositoryClassName' => $entityManager['default_repository_class'],
  563.             'setNamingStrategy' => new Reference($entityManager['naming_strategy']),
  564.             'setQuoteStrategy' => new Reference($entityManager['quote_strategy']),
  565.             'setEntityListenerResolver' => new Reference(sprintf('doctrine.orm.%s_entity_listener_resolver'$entityManager['name'])),
  566.             'setLazyGhostObjectEnabled' => '%doctrine.orm.enable_lazy_ghost_objects%',
  567.         ];
  568.         if (! method_exists(OrmConfiguration::class, 'setLazyGhostObjectEnabled')) {
  569.             unset($methods['setLazyGhostObjectEnabled']);
  570.         }
  571.         $listenerId        sprintf('doctrine.orm.%s_listeners.attach_entity_listeners'$entityManager['name']);
  572.         $listenerDef       $container->setDefinition($listenerId, new Definition('%doctrine.orm.listeners.attach_entity_listeners.class%'));
  573.         $listenerTagParams = ['event' => 'loadClassMetadata'];
  574.         if (isset($entityManager['connection'])) {
  575.             $listenerTagParams['connection'] = $entityManager['connection'];
  576.         }
  577.         $listenerDef->addTag('doctrine.event_listener'$listenerTagParams);
  578.         if (isset($entityManager['second_level_cache'])) {
  579.             $this->loadOrmSecondLevelCache($entityManager$ormConfigDef$container);
  580.         }
  581.         if ($entityManager['repository_factory']) {
  582.             $methods['setRepositoryFactory'] = new Reference($entityManager['repository_factory']);
  583.         }
  584.         foreach ($methods as $method => $arg) {
  585.             $ormConfigDef->addMethodCall($method, [$arg]);
  586.         }
  587.         foreach ($entityManager['hydrators'] as $name => $class) {
  588.             $ormConfigDef->addMethodCall('addCustomHydrationMode', [$name$class]);
  589.         }
  590.         if (! empty($entityManager['dql'])) {
  591.             foreach ($entityManager['dql']['string_functions'] as $name => $function) {
  592.                 $ormConfigDef->addMethodCall('addCustomStringFunction', [$name$function]);
  593.             }
  594.             foreach ($entityManager['dql']['numeric_functions'] as $name => $function) {
  595.                 $ormConfigDef->addMethodCall('addCustomNumericFunction', [$name$function]);
  596.             }
  597.             foreach ($entityManager['dql']['datetime_functions'] as $name => $function) {
  598.                 $ormConfigDef->addMethodCall('addCustomDatetimeFunction', [$name$function]);
  599.             }
  600.         }
  601.         $enabledFilters    = [];
  602.         $filtersParameters = [];
  603.         foreach ($entityManager['filters'] as $name => $filter) {
  604.             $ormConfigDef->addMethodCall('addFilter', [$name$filter['class']]);
  605.             if ($filter['enabled']) {
  606.                 $enabledFilters[] = $name;
  607.             }
  608.             if (! $filter['parameters']) {
  609.                 continue;
  610.             }
  611.             $filtersParameters[$name] = $filter['parameters'];
  612.         }
  613.         $managerConfiguratorName sprintf('doctrine.orm.%s_manager_configurator'$entityManager['name']);
  614.         $container
  615.             ->setDefinition($managerConfiguratorName, new ChildDefinition('doctrine.orm.manager_configurator.abstract'))
  616.             ->replaceArgument(0$enabledFilters)
  617.             ->replaceArgument(1$filtersParameters);
  618.         if (! isset($entityManager['connection'])) {
  619.             $entityManager['connection'] = $this->defaultConnection;
  620.         }
  621.         $entityManagerId sprintf('doctrine.orm.%s_entity_manager'$entityManager['name']);
  622.         $container
  623.             ->setDefinition($entityManagerId, new ChildDefinition('doctrine.orm.entity_manager.abstract'))
  624.             ->setPublic(true)
  625.             ->setArguments([
  626.                 new Reference(sprintf('doctrine.dbal.%s_connection'$entityManager['connection'])),
  627.                 new Reference(sprintf('doctrine.orm.%s_configuration'$entityManager['name'])),
  628.                 new Reference(sprintf('doctrine.dbal.%s_connection.event_manager'$entityManager['connection'])),
  629.             ])
  630.             ->setConfigurator([new Reference($managerConfiguratorName), 'configure']);
  631.         $container
  632.             ->registerAliasForArgument($entityManagerIdEntityManagerInterface::class, sprintf('%sEntityManager'$entityManager['name']))
  633.             ->setPublic(false);
  634.         $container->setAlias(
  635.             sprintf('doctrine.orm.%s_entity_manager.event_manager'$entityManager['name']),
  636.             new Alias(sprintf('doctrine.dbal.%s_connection.event_manager'$entityManager['connection']), false),
  637.         );
  638.         if (! isset($entityManager['entity_listeners'])) {
  639.             return;
  640.         }
  641.         $entities $entityManager['entity_listeners']['entities'];
  642.         foreach ($entities as $entityListenerClass => $entity) {
  643.             foreach ($entity['listeners'] as $listenerClass => $listener) {
  644.                 foreach ($listener['events'] as $listenerEvent) {
  645.                     $listenerEventName $listenerEvent['type'];
  646.                     $listenerMethod    $listenerEvent['method'];
  647.                     $listenerDef->addMethodCall('addEntityListener', [
  648.                         $entityListenerClass,
  649.                         $listenerClass,
  650.                         $listenerEventName,
  651.                         $listenerMethod,
  652.                     ]);
  653.                 }
  654.             }
  655.         }
  656.     }
  657.     /**
  658.      * Loads an ORM entity managers bundle mapping information.
  659.      *
  660.      * There are two distinct configuration possibilities for mapping information:
  661.      *
  662.      * 1. Specify a bundle and optionally details where the entity and mapping information reside.
  663.      * 2. Specify an arbitrary mapping location.
  664.      *
  665.      * @param array<string, mixed> $entityManager A configured ORM entity manager
  666.      * @param Definition           $ormConfigDef  A Definition instance
  667.      * @param ContainerBuilder     $container     A ContainerBuilder instance
  668.      *
  669.      * @example
  670.      *
  671.      *  doctrine.orm:
  672.      *     mappings:
  673.      *         MyBundle1: ~
  674.      *         MyBundle2: yml
  675.      *         MyBundle3: { type: annotation, dir: Entities/ }
  676.      *         MyBundle4: { type: xml, dir: Resources/config/doctrine/mapping }
  677.      *         MyBundle5: { type: attribute, dir: Entities/ }
  678.      *         MyBundle6:
  679.      *             type: yml
  680.      *             dir: bundle-mappings/
  681.      *             alias: BundleAlias
  682.      *         arbitrary_key:
  683.      *             type: xml
  684.      *             dir: %kernel.project_dir%/src/vendor/DoctrineExtensions/lib/DoctrineExtensions/Entities
  685.      *             prefix: DoctrineExtensions\Entities\
  686.      *             alias: DExt
  687.      *
  688.      * In the case of bundles everything is really optional (which leads to autodetection for this bundle) but
  689.      * in the mappings key everything except alias is a required argument.
  690.      */
  691.     protected function loadOrmEntityManagerMappingInformation(array $entityManagerDefinition $ormConfigDefContainerBuilder $container)
  692.     {
  693.         // reset state of drivers and alias map. They are only used by this methods and children.
  694.         $this->drivers  = [];
  695.         $this->aliasMap = [];
  696.         $this->loadMappingInformation($entityManager$container);
  697.         $this->registerMappingDrivers($entityManager$container);
  698.         $container->getDefinition($this->getObjectManagerElementName($entityManager['name'] . '_metadata_driver'));
  699.         foreach (array_keys($this->drivers) as $driverType) {
  700.             $mappingService   $this->getObjectManagerElementName($entityManager['name'] . '_' $driverType '_metadata_driver');
  701.             $mappingDriverDef $container->getDefinition($mappingService);
  702.             $args             $mappingDriverDef->getArguments();
  703.             if ($driverType === 'annotation') {
  704.                 $args[2] = $entityManager['report_fields_where_declared'];
  705.             } elseif ($driverType === 'attribute') {
  706.                 $args[1] = $entityManager['report_fields_where_declared'];
  707.             } elseif ($driverType === 'xml') {
  708.                 $args[1] ??= SimplifiedXmlDriver::DEFAULT_FILE_EXTENSION;
  709.                 $args[2]   = $entityManager['validate_xml_mapping'];
  710.             } else {
  711.                 continue;
  712.             }
  713.             $mappingDriverDef->setArguments($args);
  714.         }
  715.         $ormConfigDef->addMethodCall('setEntityNamespaces', [$this->aliasMap]);
  716.     }
  717.     /**
  718.      * Loads an ORM second level cache bundle mapping information.
  719.      *
  720.      * @param array<string, mixed> $entityManager A configured ORM entity manager
  721.      * @param Definition           $ormConfigDef  A Definition instance
  722.      * @param ContainerBuilder     $container     A ContainerBuilder instance
  723.      *
  724.      * @example
  725.      *  entity_managers:
  726.      *      default:
  727.      *          second_level_cache:
  728.      *              region_lifetime: 3600
  729.      *              region_lock_lifetime: 60
  730.      *              region_cache_driver: apc
  731.      *              log_enabled: true
  732.      *              regions:
  733.      *                  my_service_region:
  734.      *                      type: service
  735.      *                      service : "my_service_region"
  736.      *
  737.      *                  my_query_region:
  738.      *                      lifetime: 300
  739.      *                      cache_driver: array
  740.      *                      type: filelock
  741.      *
  742.      *                  my_entity_region:
  743.      *                      lifetime: 600
  744.      *                      cache_driver:
  745.      *                          type: apc
  746.      */
  747.     protected function loadOrmSecondLevelCache(array $entityManagerDefinition $ormConfigDefContainerBuilder $container)
  748.     {
  749.         $driverId null;
  750.         $enabled  $entityManager['second_level_cache']['enabled'];
  751.         if (isset($entityManager['second_level_cache']['region_cache_driver'])) {
  752.             $driverName 'second_level_cache.region_cache_driver';
  753.             $driverMap  $entityManager['second_level_cache']['region_cache_driver'];
  754.             $driverId   $this->loadCacheDriver($driverName$entityManager['name'], $driverMap$container);
  755.         }
  756.         $configId   sprintf('doctrine.orm.%s_second_level_cache.cache_configuration'$entityManager['name']);
  757.         $regionsId  sprintf('doctrine.orm.%s_second_level_cache.regions_configuration'$entityManager['name']);
  758.         $driverId   $driverId ?: sprintf('doctrine.orm.%s_second_level_cache.region_cache_driver'$entityManager['name']);
  759.         $configDef  $container->setDefinition($configId, new Definition('%doctrine.orm.second_level_cache.cache_configuration.class%'));
  760.         $regionsDef $container
  761.             ->setDefinition($regionsId, new Definition('%doctrine.orm.second_level_cache.regions_configuration.class%'))
  762.             ->setArguments([$entityManager['second_level_cache']['region_lifetime'], $entityManager['second_level_cache']['region_lock_lifetime']]);
  763.         $slcFactoryId sprintf('doctrine.orm.%s_second_level_cache.default_cache_factory'$entityManager['name']);
  764.         $factoryClass $entityManager['second_level_cache']['factory'] ?? '%doctrine.orm.second_level_cache.default_cache_factory.class%';
  765.         $definition = new Definition($factoryClass, [new Reference($regionsId), new Reference($driverId)]);
  766.         $slcFactoryDef $container
  767.             ->setDefinition($slcFactoryId$definition);
  768.         if (isset($entityManager['second_level_cache']['regions'])) {
  769.             foreach ($entityManager['second_level_cache']['regions'] as $name => $region) {
  770.                 $regionRef  null;
  771.                 $regionType $region['type'];
  772.                 if ($regionType === 'service') {
  773.                     $regionId  sprintf('doctrine.orm.%s_second_level_cache.region.%s'$entityManager['name'], $name);
  774.                     $regionRef = new Reference($region['service']);
  775.                     $container->setAlias($regionId, new Alias($region['service'], false));
  776.                 }
  777.                 if ($regionType === 'default' || $regionType === 'filelock') {
  778.                     $regionId   sprintf('doctrine.orm.%s_second_level_cache.region.%s'$entityManager['name'], $name);
  779.                     $driverName sprintf('second_level_cache.region.%s_driver'$name);
  780.                     $driverMap  $region['cache_driver'];
  781.                     $driverId   $this->loadCacheDriver($driverName$entityManager['name'], $driverMap$container);
  782.                     $regionRef  = new Reference($regionId);
  783.                     $container
  784.                         ->setDefinition($regionId, new Definition('%doctrine.orm.second_level_cache.default_region.class%'))
  785.                         ->setArguments([$name, new Reference($driverId), $region['lifetime']]);
  786.                 }
  787.                 if ($regionType === 'filelock') {
  788.                     $regionId sprintf('doctrine.orm.%s_second_level_cache.region.%s_filelock'$entityManager['name'], $name);
  789.                     $container
  790.                         ->setDefinition($regionId, new Definition('%doctrine.orm.second_level_cache.filelock_region.class%'))
  791.                         ->setArguments([$regionRef$region['lock_path'], $region['lock_lifetime']]);
  792.                     $regionRef = new Reference($regionId);
  793.                     $regionsDef->addMethodCall('getLockLifetime', [$name$region['lock_lifetime']]);
  794.                 }
  795.                 $regionsDef->addMethodCall('setLifetime', [$name$region['lifetime']]);
  796.                 $slcFactoryDef->addMethodCall('setRegion', [$regionRef]);
  797.             }
  798.         }
  799.         if ($entityManager['second_level_cache']['log_enabled']) {
  800.             $loggerChainId   sprintf('doctrine.orm.%s_second_level_cache.logger_chain'$entityManager['name']);
  801.             $loggerStatsId   sprintf('doctrine.orm.%s_second_level_cache.logger_statistics'$entityManager['name']);
  802.             $loggerChaingDef $container->setDefinition($loggerChainId, new Definition('%doctrine.orm.second_level_cache.logger_chain.class%'));
  803.             $loggerStatsDef  $container->setDefinition($loggerStatsId, new Definition('%doctrine.orm.second_level_cache.logger_statistics.class%'));
  804.             $loggerChaingDef->addMethodCall('setLogger', ['statistics'$loggerStatsDef]);
  805.             $configDef->addMethodCall('setCacheLogger', [$loggerChaingDef]);
  806.             foreach ($entityManager['second_level_cache']['loggers'] as $name => $logger) {
  807.                 $loggerId  sprintf('doctrine.orm.%s_second_level_cache.logger.%s'$entityManager['name'], $name);
  808.                 $loggerRef = new Reference($logger['service']);
  809.                 $container->setAlias($loggerId, new Alias($logger['service'], false));
  810.                 $loggerChaingDef->addMethodCall('setLogger', [$name$loggerRef]);
  811.             }
  812.         }
  813.         $configDef->addMethodCall('setCacheFactory', [$slcFactoryDef]);
  814.         $configDef->addMethodCall('setRegionsConfiguration', [$regionsDef]);
  815.         $ormConfigDef->addMethodCall('setSecondLevelCacheEnabled', [$enabled]);
  816.         $ormConfigDef->addMethodCall('setSecondLevelCacheConfiguration', [$configDef]);
  817.     }
  818.     /**
  819.      * {@inheritDoc}
  820.      */
  821.     protected function getObjectManagerElementName($name): string
  822.     {
  823.         return 'doctrine.orm.' $name;
  824.     }
  825.     protected function getMappingObjectDefaultName(): string
  826.     {
  827.         return 'Entity';
  828.     }
  829.     protected function getMappingResourceConfigDirectory(?string $bundleDir null): string
  830.     {
  831.         if ($bundleDir !== null && is_dir($bundleDir '/config/doctrine')) {
  832.             return 'config/doctrine';
  833.         }
  834.         return 'Resources/config/doctrine';
  835.     }
  836.     protected function getMappingResourceExtension(): string
  837.     {
  838.         return 'orm';
  839.     }
  840.     /**
  841.      * {@inheritDoc}
  842.      */
  843.     protected function loadCacheDriver($cacheName$objectManagerName, array $cacheDriverContainerBuilder $container): string
  844.     {
  845.         $aliasId $this->getObjectManagerElementName(sprintf('%s_%s'$objectManagerName$cacheName));
  846.         switch ($cacheDriver['type'] ?? 'pool') {
  847.             case 'service':
  848.                 $serviceId $cacheDriver['id'];
  849.                 break;
  850.             case 'pool':
  851.                 $serviceId $cacheDriver['pool'] ?? $this->createArrayAdapterCachePool($container$objectManagerName$cacheName);
  852.                 break;
  853.             default:
  854.                 throw new InvalidArgumentException(sprintf(
  855.                     'Unknown cache of type "%s" configured for cache "%s" in entity manager "%s".',
  856.                     $cacheDriver['type'],
  857.                     $cacheName,
  858.                     $objectManagerName,
  859.                 ));
  860.         }
  861.         $container->setAlias($aliasId, new Alias($serviceIdfalse));
  862.         return $aliasId;
  863.     }
  864.     /**
  865.      * Loads a configured entity managers cache drivers.
  866.      *
  867.      * @param array<string, mixed> $entityManager A configured ORM entity manager.
  868.      */
  869.     protected function loadOrmCacheDrivers(array $entityManagerContainerBuilder $container)
  870.     {
  871.         if (isset($entityManager['metadata_cache_driver'])) {
  872.             $this->loadCacheDriver('metadata_cache'$entityManager['name'], $entityManager['metadata_cache_driver'], $container);
  873.         } else {
  874.             $this->createMetadataCache($entityManager['name'], $container);
  875.         }
  876.         $this->loadCacheDriver('result_cache'$entityManager['name'], $entityManager['result_cache_driver'], $container);
  877.         $this->loadCacheDriver('query_cache'$entityManager['name'], $entityManager['query_cache_driver'], $container);
  878.     }
  879.     private function createMetadataCache(string $objectManagerNameContainerBuilder $container): void
  880.     {
  881.         $aliasId $this->getObjectManagerElementName(sprintf('%s_%s'$objectManagerName'metadata_cache'));
  882.         $cacheId sprintf('cache.doctrine.orm.%s.%s'$objectManagerName'metadata');
  883.         $cache = new Definition(ArrayAdapter::class);
  884.         if (! $container->getParameter('kernel.debug')) {
  885.             $phpArrayFile         '%kernel.cache_dir%' sprintf('/doctrine/orm/%s_metadata.php'$objectManagerName);
  886.             $cacheWarmerServiceId $this->getObjectManagerElementName(sprintf('%s_%s'$objectManagerName'metadata_cache_warmer'));
  887.             $container->register($cacheWarmerServiceIdDoctrineMetadataCacheWarmer::class)
  888.                 ->setArguments([new Reference(sprintf('doctrine.orm.%s_entity_manager'$objectManagerName)), $phpArrayFile])
  889.                 ->addTag('kernel.cache_warmer', ['priority' => 1000]); // priority should be higher than ProxyCacheWarmer
  890.             $cache = new Definition(PhpArrayAdapter::class, [$phpArrayFile$cache]);
  891.         }
  892.         $container->setDefinition($cacheId$cache);
  893.         $container->setAlias($aliasId$cacheId);
  894.     }
  895.     /**
  896.      * Loads a property info extractor for each defined entity manager.
  897.      */
  898.     private function loadPropertyInfoExtractor(string $entityManagerNameContainerBuilder $container): void
  899.     {
  900.         $propertyExtractorDefinition $container->register(sprintf('doctrine.orm.%s_entity_manager.property_info_extractor'$entityManagerName), DoctrineExtractor::class);
  901.         $argumentId                  sprintf('doctrine.orm.%s_entity_manager'$entityManagerName);
  902.         $propertyExtractorDefinition->addArgument(new Reference($argumentId));
  903.         $propertyExtractorDefinition->addTag('property_info.list_extractor', ['priority' => -1001]);
  904.         $propertyExtractorDefinition->addTag('property_info.type_extractor', ['priority' => -999]);
  905.         $propertyExtractorDefinition->addTag('property_info.access_extractor', ['priority' => -999]);
  906.     }
  907.     /**
  908.      * Loads a validator loader for each defined entity manager.
  909.      */
  910.     private function loadValidatorLoader(string $entityManagerNameContainerBuilder $container): void
  911.     {
  912.         $validatorLoaderDefinition $container->register(sprintf('doctrine.orm.%s_entity_manager.validator_loader'$entityManagerName), DoctrineLoader::class);
  913.         $validatorLoaderDefinition->addArgument(new Reference(sprintf('doctrine.orm.%s_entity_manager'$entityManagerName)));
  914.         $validatorLoaderDefinition->addTag('validator.auto_mapper', ['priority' => -100]);
  915.     }
  916.     public function getXsdValidationBasePath(): string
  917.     {
  918.         return __DIR__ '/../Resources/config/schema';
  919.     }
  920.     public function getNamespace(): string
  921.     {
  922.         return 'http://symfony.com/schema/dic/doctrine';
  923.     }
  924.     /**
  925.      * {@inheritDoc}
  926.      */
  927.     public function getConfiguration(array $configContainerBuilder $container): Configuration
  928.     {
  929.         return new Configuration((bool) $container->getParameter('kernel.debug'));
  930.     }
  931.     protected function getMetadataDriverClass(string $driverType): string
  932.     {
  933.         return '%' $this->getObjectManagerElementName('metadata.' $driverType '.class') . '%';
  934.     }
  935.     private function loadMessengerServices(ContainerBuilder $container): void
  936.     {
  937.         // If the Messenger component is installed, wire it:
  938.         /** @psalm-suppress UndefinedClass Optional dependency */
  939.         if (! interface_exists(MessageBusInterface::class)) {
  940.             return;
  941.         }
  942.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/../Resources/config'));
  943.         $loader->load('messenger.xml');
  944.         // available in Symfony 6.3
  945.         $container->removeDefinition('doctrine.orm.messenger.doctrine_schema_' . (class_exists(MessengerTransportDoctrineSchemaListener::class) ? 'subscriber' 'listener'));
  946.         /**
  947.          * The Doctrine transport component (symfony/doctrine-messenger) is optional.
  948.          * Remove service definition, if it is not available
  949.          */
  950.         if (class_exists(DoctrineTransportFactory::class)) {
  951.             return;
  952.         }
  953.         $container->removeDefinition('messenger.transport.doctrine.factory');
  954.         $container->removeDefinition('doctrine.orm.messenger.doctrine_schema_subscriber');
  955.         $container->removeDefinition('doctrine.orm.messenger.doctrine_schema_listener');
  956.     }
  957.     private function createArrayAdapterCachePool(ContainerBuilder $containerstring $objectManagerNamestring $cacheName): string
  958.     {
  959.         $id sprintf('cache.doctrine.orm.%s.%s'$objectManagerNamestr_replace('_cache'''$cacheName));
  960.         $poolDefinition $container->register($idArrayAdapter::class);
  961.         $poolDefinition->addTag('cache.pool');
  962.         $container->setDefinition($id$poolDefinition);
  963.         return $id;
  964.     }
  965.     /**
  966.      * @param string[] $connWithLogging
  967.      * @param string[] $connWithProfiling
  968.      * @param string[] $connWithBacktrace
  969.      */
  970.     private function registerDbalMiddlewares(
  971.         ContainerBuilder $container,
  972.         array $connWithLogging,
  973.         array $connWithProfiling,
  974.         array $connWithBacktrace
  975.     ): void {
  976.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/../Resources/config'));
  977.         $loader->load('middlewares.xml');
  978.         $loggingMiddlewareAbstractDef $container->getDefinition('doctrine.dbal.logging_middleware');
  979.         foreach ($connWithLogging as $connName) {
  980.             $loggingMiddlewareAbstractDef->addTag('doctrine.middleware', ['connection' => $connName]);
  981.         }
  982.         $container->getDefinition('doctrine.debug_data_holder')->replaceArgument(0$connWithBacktrace);
  983.         $debugMiddlewareAbstractDef $container->getDefinition('doctrine.dbal.debug_middleware');
  984.         foreach ($connWithProfiling as $connName) {
  985.             $debugMiddlewareAbstractDef
  986.                 ->addTag('doctrine.middleware', ['connection' => $connName]);
  987.         }
  988.     }
  989. }