Load validators or code definitions from both configuration and tagged services

@param string           $tagName
@param ContainerBuilder $container
@param string           $methodForConfiguration
@param string           $methodForService
484035
protected function loadElements($tagName, ContainerBuilder $container, $methodForConfiguration, $methodForService)
    {
        $parserName = 'open_orchestra_bbcode.parser';
        $tagName = 'open_orchestra_bbcode.' . $tagName;

        if ($container->hasParameter($tagName)) {
            $parser = $container->getDefinition($parserName);
            $elements = $container->getParameter($tagName);
            $parser->addMethodCall($methodForConfiguration, array($elements));
        }

        $this->addStrategyToManager($container, $parserName, $tagName, $methodForService);
    }
646855
public function load (array $config, ContainerBuilder $container)
    {
        // parse configuration
        $parsedConfiguration = $this->processConfiguration(new Configuration(), $config);

        // load services
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');

        // build role collection
        $builder = new RoleCollectionBuilder();

        $roleCollectionDefinition = $container->getDefinition("becklyn.static_roles.role_collection");
        $roleCollectionDefinition->replaceArgument(0, $builder->prepareRoleCollection($parsedConfiguration["roles"]));
    }
1354482
private function loadAnnotationReader(ContainerBuilder $container)
    {
        $definition = new Definition('Behat\Behat\Hook\Context\Annotation\HookAnnotationReader');
        $definition->addTag(ContextExtension::ANNOTATION_READER_TAG, array('priority' => 50));
        $container->setDefinition(ContextExtension::ANNOTATION_READER_TAG . '.hook', $definition);
    }
731184
public function process(ContainerBuilder $container): void
    {
        if (!$container->hasDefinition(Aggregator::class)) {
            return;
        }

        $aggregatorDefinition = $container->getDefinition(Aggregator::class);
        $taggedServiceIds = $container->findTaggedServiceIds(self::TAG_CONFIG_PROVIDER);

        foreach ($taggedServiceIds as $taggedServiceId => $tags) {
            foreach ($tags as $tag) {
                $key = $tag['key'] ?? $taggedServiceId;
                $aggregatorDefinition->addMethodCall('addProvider', [$key, new Reference($taggedServiceId)]);
            }
        }
    }
362999
public function process(ContainerBuilder $container)
    {
        $taggedServices = $container->findTaggedServiceIds($this->tagName);
        foreach ($taggedServices as $id => $tags) {

            $definition = $container->getDefinition($id);
            foreach ($tags as $tag) {

                $references = $this->getSortedDependencies(
                    $container,
                    $this->buildOptionsFromServiceTag($id, $tag)
                );

                $this->configureConsumer($definition, $tag, $references);
            }
        }
    }
724208
public function load(array $config, ContainerBuilder $container)
    {
        $container->addObjectResource($this);

        $configuration = $this->getConfiguration($config, $container);
        if ($configuration instanceof ConfigurationInterface) {
            $config = $this->processConfiguration($configuration, $config);
            $this->applyParametrizedValues($config, $container);
        }

        $configFiles = $this->getConfigFiles($config);
        if (!empty($configFiles)) {
            $this->loadFiles($configFiles, $container);
        }

        $this->postLoad($config, $container);
    }
960451
protected function loadParameters(ContainerBuilder $container, array $config): void
    {
        $container->setParameter('fxp_require_asset.config.default_locale', $config['default_locale']);
        $container->setParameter('fxp_require_asset.config.fallback_locale', $config['fallback_locale']);
        $container->setParameter('fxp_require_asset.config.locales', $config['locales']);
    }
1334595
public function getMethodValidateAnnotations($className, $methodName)
    {
        $validateAnnotations = [];
        $methodTagsValues = $this->reflectionService->getMethodTagsValues($className, $methodName);
        if (isset($methodTagsValues['validate']) && is_array($methodTagsValues['validate'])) {
            foreach ($methodTagsValues['validate'] as $validateValue) {
                $parsedAnnotations = $this->parseValidatorAnnotation($validateValue);

                foreach ($parsedAnnotations['validators'] as $validator) {
                    array_push($validateAnnotations, [
                        'argumentName' => $parsedAnnotations['argumentName'],
                        'validatorName' => $validator['validatorName'],
                        'validatorOptions' => $validator['validatorOptions']
                    ]);
                }
            }
        }

        return $validateAnnotations;
    }
1040052
public static function loadProcessors(ContainerBuilder $container, $processorTagName)
    {
        $processors = [];
        $isDebug = $container->getParameter('kernel.debug');
        $taggedServices = $container->findTaggedServiceIds($processorTagName);
        foreach ($taggedServices as $id => $taggedAttributes) {
            foreach ($taggedAttributes as $attributes) {
                $action = '';
                if (!empty($attributes['action'])) {
                    $action = $attributes['action'];
                }
                unset($attributes['action']);

                $group = null;
                if (!empty($attributes['group'])) {
                    $group = $attributes['group'];
                } else {
                    unset($attributes['group']);
                }

                if (!$action && $group) {
                    throw new \InvalidArgumentException(
                        sprintf(
                            'Tag attribute "group" can be used only if '
                            . 'the attribute "action" is specified. Service: "%s".',
                            $id
                        )
                    );
                }

                $priority = 0;
                if (isset($attributes['priority'])) {
                    $priority = $attributes['priority'];
                }
                if (!$isDebug) {
                    unset($attributes['priority']);
                }

                $attributes = array_map(
                    function ($val) {
                        return ExpressionParser::parse($val);
                    },
                    $attributes
                );

                $processors[$action][$priority][] = [$id, $attributes];
            }
        }

        return $processors;
    }
1212049
public function process(ContainerBuilder $container)
    {
        $container->setAlias('router', 'joomla.router');

        $definition = $container->getDefinition('joomla.router');

        $taggedServices = $container->findTaggedServiceIds(
            'joomla.router'
        );

        $interface = RouterInterface::class;

        $sortedRouters = [];

        foreach ($taggedServices as $id => $tagAttributes) {
            $tagDefinition = $container->getDefinition($id);
            $tagClass = $container->getParameterBag()->resolveValue($tagDefinition->getClass());
            $tagClass = new \ReflectionClass($tagClass);

            if (!$tagClass->implementsInterface($interface)) {
                throw new \LogicException(
                    sprintf("Class of service %s does not implement interface %s", $id, $interface)
                );
            }

            $tagAttributes = current($tagAttributes);

            $priority = 0;
            if (isset($tagAttributes['priority'])) {
                $priority = $tagAttributes['priority'];
            }

            $sortedRouters[] = [$priority, new Reference($id)];
        }

        usort(
            $sortedRouters,
            function ($serviceA, $serviceB) {
                if ($serviceA[0] == $serviceB[0]) {
                    return 0;
                }

                return ($serviceA[0] < $serviceB[0]) ? 1 : -1;
            }
        );

        $sortedRouters = array_reverse($sortedRouters);

        foreach ($sortedRouters as $service) {
            $definition->addMethodCall(
                'addRouter',
                [$service[1]]
            );
        }

        $container->setParameter('router.options.generator_class', UrlGenerator::class);
        $container->setParameter('router.options.generator_base_class', UrlGenerator::class);
    }
1014361
private function findAndReplaceTaggedServices($id, array $service, ContainerBuilder $container)
    {
        $serviceConfig = $this->createServiceConfig($id, $service);

        if ($serviceConfig->has(ServiceConfig::CONTAINER)) {
            $replace = $this->getDefinitionsAsContainer($container, $serviceConfig);
        } else {
            $replace = $this->getDefinitionsAsArray($container, $serviceConfig);
        }

        $definition = $container->findDefinition($id);
        $definition->replaceArgument($this->findArgumentToReplace($definition, $serviceConfig), $replace);
    }
163704
public function process(ContainerBuilder $container)
    {
        $pool = $container->getDefinition('admin.configuration.pool');
        // get tagged services
        $configurations = array();
        foreach ($container->findTaggedServiceIds('admin.configuration') as $id => $attributes) {
            $configurations[$id] = $attributes;
        }
        $pool->addMethodCall('setConfigurations', array($configurations));
    }
718572
public function loadJoomlaConfig(ContainerBuilder $container)
    {
        if (!defined('JPATH_CONFIGURATION')) {
            define('JPATH_CONFIGURATION', $container->getParameter('joomla.config_dir'));
        }

        if (class_exists('\JProxy_Config', false)) {
            return;
        }

        // Pre-Load configuration. Don't remove the Output Buffering due to BOM issues, see JCode 26026
        ob_start();
        if (file_exists(JPATH_CONFIGURATION . '/configuration.php')) {
            $config = OverrideUtils::classReplace(JPATH_CONFIGURATION . '/configuration.php', 'JConfig', 'JProxy_Config');
        } else {
            $config = 'class JProxy_Config {}';
        }
        eval($config);
        ob_end_clean();
    }
616940
public function loadDefinitionsFromConfiguration($codeDefinitions)
    {
        foreach ($codeDefinitions as $definition) {
            if (isset($definition['tag']) && isset($definition['html'])) {
                $parameters = (isset($definition['parameters'])) ? $definition['parameters'] : array();
                $optionValidator = (isset($parameters['option_validator']) && isset($this->validators[$parameters['option_validator']])) ?
                    array($this->validators[$parameters['option_validator']]) : array();
                $bodyValidator = (isset($parameters['body_validator']) && isset($this->validators[$parameters['body_validator']])) ?
                    $this->validators[$parameters['body_validator']] : null;
                $this->addCodeDefinition(
                    $this->definitionFactory->create(
                        $definition['tag'],
                        $definition['html'],
                        (isset($parameters['use_option'])) ? $parameters['use_option'] : false,
                        (isset($parameters['parse_content'])) ? $parameters['parse_content'] : true,
                        (isset($parameters['nest_limit'])) ? $parameters['nest_limit'] : -1,
                        $optionValidator, // seems there's a bug here, validators should be instanciated here
                        $bodyValidator
                    )
                );
            }
        }
    }
815573
public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('joomla.component.module.module_manager')) {
            return;
        }

        $moduleManagerDefinition = $container->getDefinition('joomla.component.module.module_manager');
        $taggedServices = $container->findTaggedServiceIds('joomla.module');

        foreach (array_keys($taggedServices) as $id) {
            $moduleDefinition = $container->getDefinition($id);
            $reflection = new \ReflectionClass($moduleDefinition->getClass());

            if (!$reflection->implementsInterface(ModuleRendererInterface::class)) {
                throw new \InvalidArgumentException(sprintf(
                    'Module service class %s does not implement %s',
                    $id,
                    ModuleRendererInterface::class
                ));
            }

            $moduleDefinition->addMethodCall('setFormFactory', [ new Reference('form.factory') ]);
            $moduleDefinition->addMethodCall('setTwigEnvironment', [ new Reference('twig') ]);
            $moduleDefinition->setScope(ContainerInterface::SCOPE_PROTOTYPE);
            $moduleManagerDefinition->addMethodCall('addModuleService', [ $id ]);
        }
    }
144749
public function loadTagSynonyms($tagPath, Request $request)
    {
        $offset = $request->query->has('offset') ? (int) $request->query->get('offset') : 0;
        $limit = $request->query->has('limit') ? (int) $request->query->get('limit') : 25;

        $tagId = $this->extractTagIdFromPath($tagPath);
        $synonyms = $this->tagsService->loadTagSynonyms(
            $this->tagsService->loadTag($tagId),
            $offset >= 0 ? $offset : 0,
            $limit >= 0 ? $limit : 25
        );

        $restSynonyms = [];
        foreach ($synonyms as $synonym) {
            $restSynonyms[] = new Values\RestTag($synonym, 0, 0);
        }

        return new Values\CachedValue(
            new Values\TagList(
                $restSynonyms,
                $request->getPathInfo()
            ),
            ['tagId' => $tagId]
        );
    }
180332
private function findServiceIdsByTag(ContainerBuilder $container, ServiceConfig $serviceConfig)
    {
        $tag = $serviceConfig->get(ServiceConfig::FIND_TAG);

        $serviceIds = array();

        foreach ($container->findTaggedServiceIds($tag) as $id => $services) {
            foreach ((array) $services as $service) {
                if (null === $name = $this->findName($service, $serviceConfig)) {
                    throw new \InvalidArgumentException(
                        sprintf(
                            'Service "%s" must define a name attribute like "key" or "type" for "%s" tags.',
                            $id,
                            $tag
                        )
                    );
                }

                $serviceIds[$service[$name]] = $id;
            }
        }

        return $serviceIds;
    }