Register and override the DriverChain definition.

@param ContainerBuilder $container
@param EntityMapping    $entityMapping

@throws EntityManagerNotFoundException Entity Manager nod found
434591
private function addDriverInDriverChain(
        ContainerBuilder $container,
        EntityMapping $entityMapping
    ) {
        $chainDriverDefinition = $container
            ->getDefinition(
                'doctrine.orm.' . $entityMapping->getEntityManagerName() . '_metadata_driver'
            );

        $container->setParameter(
            'doctrine.orm.metadata.driver_chain.class',
            'Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain'
        );

        $chainDriverDefinition->addMethodCall('addDriver', [
            new Reference(
                'doctrine.orm.' . $entityMapping->getUniqueIdentifier() . '_metadata_driver'
            ),
            $entityMapping->getEntityNamespace(),
        ]);
    }
551262
public function process(ContainerBuilder $container)
    {
        $entityCollectionType = $container->getDefinition('majora.loader.bridge.form.type.entity_collection');
        $loaders = $container->findTaggedServiceIds('majora.loader_bridge.form');

        foreach ($loaders as $loaderId => $tags) {
            foreach ($tags as $attributes) {
                if (!isset($attributes['alias'])) {
                    throw new \RuntimeException('Alias required for "majora.loader_bridge.form" tag.');
                }

                $entityCollectionType->addMethodCall(
                    'registerLoader',
                    [$attributes['alias'], new Reference($loaderId)]
                );
            }
        }
    }
667841
public function process(ContainerBuilder $container)
    {
        try {
            $chainRouter = $container->getDefinition("router.chainRequest");
        } catch (InvalidArgumentException $e) {
            return;
        }

        foreach ($container->findTaggedServiceIds("router.register") as $id => $attributes) {
            $priority = isset($attributes[0]["priority"]) ? $attributes[0]["priority"] : 0;
            $router = $container->getDefinition($id);
            $router->addMethodCall("setOption", array("matcher_cache_class", $container::camelize("ProjectUrlMatcher".$id)));
            $router->addMethodCall("setOption", array("generator_cache_class", $container::camelize("ProjectUrlGenerator".$id)));

            $chainRouter->addMethodCall("add", array(new Reference($id), $priority));
        }
        if (\defined("THELIA_INSTALL_MODE") === false) {
            $modules = ModuleQuery::getActivated();

            /** @var Module $module */
            foreach ($modules as $module) {
                $moduleBaseDir = $module->getBaseDir();
                $routingConfigFilePath = $module->getAbsoluteBaseDir() . DS . "Config" . DS . "routing.xml";

                if (file_exists($routingConfigFilePath)) {
                    $definition = new Definition(
                        $container->getParameter("router.class"),
                        array(
                            new Reference("router.module.xmlLoader"),
                            $routingConfigFilePath,
                            array(
                                "cache_dir" => $container->getParameter("kernel.cache_dir"),
                                "debug" => $container->getParameter("kernel.debug"),
                                "matcher_cache_class" => $container::camelize("ProjectUrlMatcher".$moduleBaseDir),
                                "generator_cache_class" => $container::camelize("ProjectUrlGenerator".$moduleBaseDir),
                            ),
                            new Reference("request.context")
                        )
                    );

                    $container->setDefinition("router.".$moduleBaseDir, $definition);

                    $chainRouter->addMethodCall("add", array(new Reference("router.".$moduleBaseDir), 150 + $module->getPosition()));
                }
            }
        }
    }
640608
private function getMappedEntities(EntityManagerInterface $entityManager)
    {
        $entityClassNames = $entityManager
            ->getConfiguration()
            ->getMetadataDriverImpl()
            ->getAllClassNames();

        if ( ! $entityClassNames) {
            throw new \InvalidArgumentException(
                'You do not have any mapped Doctrine ORM entities according to the current configuration. '.
                'If you have entities or mapping files you should check your mapping configuration for errors.'
            );
        }

        return $entityClassNames;
    }
296939
public function process(ContainerBuilder $container)
    {
        $loaderTags = $container->findTaggedServiceIds('majora.loader');

        foreach ($loaderTags as $loaderId => $tags) {
            $loaderDefinition = $container->getDefinition($loaderId);
            $loaderReflection = new \ReflectionClass($loaderDefinition->getClass());

            foreach ($tags as $attributes) {
                $method = $loaderReflection->implementsInterface(LoaderInterface::class) ?
                    'configureMetadata' : ($loaderReflection->hasMethod('setUp') ?
                        'setUp' : ''
                    )
                ;
                if (isset($attributes['entityClass']) || isset($attributes['entityCollection'])) {
                    @trigger_error('"entityClass" and "entityCollection" attributes for tag "majora.loader" are deprecated and will be removed in 2.0. Please "entity" and "collection" instead.', E_USER_DEPRECATED);
                }
                $entityClass = isset($attributes['entity']) ? $attributes['entity'] : $attributes['entityClass'];
                $collectionClass = isset($attributes['collection']) ? $attributes['collection'] : $attributes['entityCollection'];
                $entityReflection = new \ReflectionClass($entityClass);

                // configureMetadata() call configuration
                if ($method) {
                    if (!$entityReflection->implementsInterface(CollectionableInterface::class)) {
                        throw new \InvalidArgumentException(sprintf(
                            'Cannot support "%s" class into "%s" : managed items have to be %s.',
                            $entityClass,
                            $loaderDefinition->getClass(),
                            CollectionableInterface::class
                        ));
                    }
                    $arguments = array(
                        $entityClass,
                        array_map(
                            function ($property) { return $property->getName(); },
                            $entityReflection->getProperties()
                        ),
                        $collectionClass,
                    );

                    $loaderDefinition->addMethodCall($method, $arguments);
                }

                // Doctrine case
                if ($loaderReflection->isSubclassOf(AbstractDoctrineLoader::class)) {

                    // "repository" attribute key only supported for doctrine loaders
                    // Repository is injected through mutator to avoid circular references
                    // with Doctrine events and connection
                    if (isset($attributes['repository'])) {
                        $loaderDefinition->addMethodCall(
                            'setEntityRepository',
                            array(new Reference($attributes['repository']))
                        );
                    }

                    // for Doctrine, loaders cannot self enable objects lazy loading
                    // due to general event trigger into all listener for each entites
                    // so we have to check class / attribute and register service into event proxy
                    if ($container->hasDefinition('majora.doctrine.event_proxy') && !empty($attributes['lazy'])) {
                        if (!$entityReflection->implementsInterface(LazyPropertiesInterface::class)) {
                            throw new \InvalidArgumentException(sprintf(
                                'Class %s has to implement %s to be able to lazy load her properties.',
                                $entityClass,
                                LazyPropertiesInterface::class
                            ));
                        }
                        $container->getDefinition('majora.doctrine.event_proxy')
                            ->addMethodCall('registerDoctrineLazyLoader', array(
                                $entityClass,
                                new Reference($loaderId),
                            ))
                        ;
                    }
                }
            }
        }
    }
195383
private function processRegisterApplicationFactory(ContainerBuilder $container)
    {
        $references = $this->processor->findAndSortTaggedServices($container, self::FACTORY_TAG);
        $definition = $container->getDefinition(Extension::APPLICATION_FACTORY_ID);
        foreach ($references as $reference) {
            $definition->addMethodCall('registerFactory', array($reference));
        }
    }
291205
public function process(ContainerBuilder $container)
    {
        if (!$container->has($this->getCollectorServiceName())) {
            return;
        }

        $definition = $container->findDefinition(
            $this->getCollectorServiceName()
        );

        $taggedServices = $container->findTaggedServiceIds(
            $this->getTagName()
        );
        foreach ($taggedServices as $id => $tags) {
            $definition->addMethodCall(
                $this->getCollectorMethodName(),
                [new Reference($id)]
            );
        }
    }
1271601
public function process(ContainerBuilder $container)
    {
        $this->processDriverPass($container);
        $this->processDriverElementPass($container);
        $this->processEventSubscriberPass($container);
        $this->processClassGenerator($container);

        $this->setPageObjectNamespaces($container);
        $this->injectSiteUrlIntoPageObjects($container);
    }
422473
public function process(ContainerBuilder $container)
    {
        // 1. Register custom repositories with Aggregate repository
        $aggregateRepositoryDefinition = $container->findDefinition(static::$aggregateRepositoryId);
        $customRepositoryTags = $container->findTaggedServiceIds(static::$customRepositoryTag);
        $customRepositoryReferences = [];

        foreach (array_keys($customRepositoryTags) as $id) {
            $customRepositoryReferences[] = new Reference($id);
        }

        $aggregateRepositoryDefinition->replaceArgument(1, $customRepositoryReferences);

        $topEzRepositoryAlias = $container->getAlias(static::$topEzRepositoryAliasId);

        // 2. Re-link eZ Platform's public top Repository alias
        $container->setAlias(static::$renamedTopEzRepositoryAliasId, (string)$topEzRepositoryAlias);

        // 3. Overwrite eZ Platform's public top Repository alias
        // to aggregate Repository implementation
        $container->setAlias(static::$topEzRepositoryAliasId, static::$aggregateRepositoryId);
    }
233077
private function loadContextInitializer(ContainerBuilder $container)
    {
        $definition = new Definition(
            'Behat\GuzzleExtension\Context\Initializer\GuzzleAwareInitializer',
            array(
                new Reference(self::GUZZLE_CLIENT_ID),
                '%guzzle.parameters%',
            )
        );
        $definition->addTag(
            ContextExtension::INITIALIZER_TAG,
            array('priority' => 0)
        );

        $container->setDefinition('guzzle.context_initializer', $definition);
    }
1185360
private function addObjectDirector(
        ContainerBuilder $container,
        MappingBag $mappingBag,
        string $objectManagerAliasName,
        string $objectRepositoryAliasName
    ) {
        $definition = new Definition('Mmoreram\BaseBundle\ORM\ObjectDirector');
        $definition->setArguments([
            new Reference($objectManagerAliasName),
            new Reference($objectRepositoryAliasName),
        ]);
        $definitionName = ltrim(($mappingBag->getContainerPrefix().'.object_director.'.$mappingBag->getEntityName()), '.');
        $container->setDefinition(
            $definitionName,
            $definition
        );
    }
379560
private function processTerminalFactoryRegistration(ContainerBuilder $container)
    {
        $references = $this->processor->findAndSortTaggedServices($container, self::TERMINAL_FACTORY_TAG);
        $definition = $container->getDefinition(Extension::TERMINAL_COLLECTION_FACTORY_ID);

        foreach ($references as $reference) {
            $definition->addMethodCall('registerTerminalFactory', array($reference));
        }
    }
557837
public function register(EntityDefinition $builder): void {
    $this->defs[$builder->full_name] = $builder;
    $this->unchecked[] = $builder;

    $binding_name = str_replace('\\', '.', $builder->full_name);
    $this->ioc->bind('bap.remodel.scopes.' . $binding_name, function() use($builder) {
      return $builder->scopes;
    });

    foreach($builder->virtuals as $virtual) {
      $this->ioc->bind("bap.remodel.virtuals.{$binding_name}.{$virtual->alias}", function() use($virtual) {
        return $virtual->callback;
      });
    }

    $this->tailor->bindCallback($builder->full_name, function(Generator $gen) use($builder): void {
      $this->checkDefinitions();

      $file = $gen->generate('Entity', $builder->toArray());
      $gen->includeFile($file);
    });

    foreach(static::CLASS_SUFFIXES as $class) {
      $this->tailor->bindCallback($builder->full_name . $class, function(Generator $gen) use($builder, $class): void {
        $this->checkDefinitions();

        $file = $gen->generate($class, $builder->toArray());
        $gen->includeFile($file);
      });
    }
  }
423443
public function entities($entityClassMapperClassMap)
    {
        foreach ($entityClassMapperClassMap as $entity => $mapper) {
            $this->entity($entity)->from($mapper);
        }
    }
582961
private function applyMappingParametrization(
        array $config,
        ContainerBuilder $container
    ) {
        if (!$this->mappingBagProvider instanceof MappingBagProvider) {
            return;
        }

        $mappingBagCollection = $this
            ->mappingBagProvider
            ->getMappingBagCollection();

        $mappedParameters = [];
        foreach ($mappingBagCollection->all() as $mappingBag) {
            $entityName = $mappingBag->getEntityName();
            $isOverwritable = $mappingBag->isOverwritable();
            $mappedParameters = array_merge($mappedParameters, [
                $mappingBag->getParamFormat('class') => $isOverwritable
                    ? $config['mapping'][$entityName]['class']
                    : $mappingBag->getEntityNamespace(),
                $mappingBag->getParamFormat('mapping_file') => $isOverwritable
                    ? $config['mapping'][$entityName]['mapping_file']
                    : $mappingBag->getEntityMappingFilePath(),
                $mappingBag->getParamFormat('manager') => $isOverwritable
                    ? $config['mapping'][$entityName]['manager']
                    : $mappingBag->getManagerName(),
                $mappingBag->getParamFormat('enabled') => $isOverwritable
                    ? $config['mapping'][$entityName]['enabled']
                    : $mappingBag->getEntityIsEnabled(),
            ]);
        }

        $container
            ->getParameterBag()
            ->add($mappedParameters);
    }
398735
public function mapper($entity, $entityMap = null)
    {
        if ($entity instanceof Wrapper) {
            throw new MappingException('Tried to instantiate mapper on wrapped Entity');
        }

        $entity = $this->resolveEntityClass($entity);

        $entity = $this->getInverseMorphMap($entity);

        // Return existing mapper instance if exists.
        if (array_key_exists($entity, $this->mappers)) {
            return $this->mappers[$entity];
        } else {
            return $this->buildMapper($entity, $entityMap);
        }
    }
662566
private function configureMetadataDriver(array $config, ContainerBuilder $container)
    {
        $container->register('doctrine.key_value.metadata.annotation.reader', 'Doctrine\Common\Annotations\AnnotationReader')
            ->setPublic(false);

        $container->register('doctrine.key_value.metadata.annotation', 'Doctrine\KeyValueStore\Mapping\AnnotationDriver')
            ->setPublic(false)
            ->addArgument(new Reference('doctrine.key_value.metadata.annotation.reader'));
    }