Resolves definition decorator arguments.

@param ContainerBuilder $container The ContainerBuilder
@param array            $arguments An array of arguments
@param bool             $isRoot    If we are processing the root definitions or not

@return array
7941
private function resolveArguments(ContainerBuilder $container, array $arguments, $isRoot = false)
    {
        foreach ($arguments as $k => $argument) {
            if ($isRoot) {
                // yes, we are specifically fetching the definition from the
                // container to ensure we are not operating on stale data
                $arguments[$k] = $argument = $container->getDefinition($k);
                $this->currentId = $k;
            }
            if (is_array($argument)) {
                $arguments[$k] = $this->resolveArguments($container, $argument);
            } elseif ($argument instanceof Definition) {
                if ($argument instanceof DefinitionDecorator) {
                    $arguments[$k] = $argument = $this->resolveDefinition($container, $argument);
                    if ($isRoot) {
                        $container->setDefinition($k, $argument);
                    }
                }
                $argument->setArguments($this->resolveArguments($container, $argument->getArguments()));
                $argument->setMethodCalls($this->resolveArguments($container, $argument->getMethodCalls()));
                $argument->setProperties($this->resolveArguments($container, $argument->getProperties()));

                $configurator = $this->resolveArguments($container, array($argument->getConfigurator()));
                $argument->setConfigurator($configurator[0]);

                $factory = $this->resolveArguments($container, array($argument->getFactory()));
                $argument->setFactory($factory[0]);
            }
        }

        return $arguments;
    }
526049
private function createResolver(array $config, ContainerInterface $container)
    {
        $resolvers = [];
        if (isset($config['resolvers'])) {
            $resolvers = $this->createResolvers($config['resolvers'], $container);
        }

        $aggregate = new Resolver\AggregateResolver();
        foreach ($resolvers as $resolver) {
            $aggregate->attach($resolver);
        }

        if ($aggregate->hasType(Resolver\DefaultResolver::class)) {
            $defaultResolver = $aggregate->fetchByType(Resolver\DefaultResolver::class);
        } else {
            $defaultResolver = new Resolver\DefaultResolver();
            $aggregate->attach($defaultResolver, 0);
        }

        if (isset($config['paths']) && is_array($config['paths'])) {
            $this->injectResolverPaths($config['paths'], $defaultResolver);
        }

        if (isset($config['suffix']) && is_string($config['suffix']) && ! empty($config['suffix'])) {
            $defaultResolver->setSuffix($config['suffix']);
        }

        if (isset($config['separator']) && is_string($config['separator']) && ! empty($config['separator'])) {
            $defaultResolver->setSeparator($config['separator']);
        }

        return $aggregate;
    }
246536
public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(
            new DependencyInjection\Compiler\EventPropagationPass(),
            PassConfig::TYPE_BEFORE_OPTIMIZATION
        );
    }
331289
public static function buildDI(array $paths, bool $resolveEnvironment = false): ContainerBuilder
    {
        $container = new ContainerBuilder;

        $loader = static::buildConfigLoader($container, $paths);

        if (class_exists(Configuration::class) && class_exists(RuntimeInstantiator::class)) {
            $container->setProxyInstantiator(new RuntimeInstantiator);
        }

        $extensions = [];
        foreach (static::DI_EXTENSIONS as $extClass) {
            if (!class_exists($extClass)) {
                throw new RuntimeException("Symfony DI Extension not found: \"${extClass}\"");
            }

            $extensions[] = new $extClass;
        }

        foreach ($extensions as $ext) {
            $container->registerExtension($ext);
        }

        $loader->load(static::PRIMARY_CONFIGURATION_FILE);

        foreach ($extensions as $ext) {
            $container->loadFromExtension($ext->getAlias());
        }

        $container->compile($resolveEnvironment);

        return $container;
    }
1100249
private function loadRootNodeListener(ContainerBuilder $container)
    {

        $definition = new Definition('Behat\Behat\Output\Node\EventListener\JUnit\JUnitOutlineStoreListener', array(
                new Reference('output.node.printer.junit.suite')
            )
        );
        $container->setDefinition('output.node.listener.junit.outline', $definition);

        $definition = new Definition(
            'Behat\Behat\Output\Node\EventListener\JUnit\JUnitDurationListener'
        );

        $container->setDefinition('output.node.listener.junit.duration', $definition);

        $definition = new Definition('Behat\Testwork\Output\Node\EventListener\ChainEventListener', array(
            array(
                new Reference('output.node.listener.junit.duration'),
                new Reference('output.node.listener.junit.outline'),
                new Definition('Behat\Behat\Output\Node\EventListener\JUnit\JUnitFeatureElementListener', array(
                    new Reference('output.node.printer.junit.feature'),
                    new Reference('output.node.printer.junit.scenario'),
                    new Reference('output.node.printer.junit.step'),
                    new Reference('output.node.printer.junit.setup'),
                )),
            ),
        ));
        $container->setDefinition(self::ROOT_LISTENER_ID, $definition);
    }
368449
public function process(ContainerBuilder $container)
    {
        $bundles         = $container->getParameter('kernel.bundles');
        $bundleContainer = $container->getDefinition('atoum.configuration.bundle.container');
        $configuration   = $container->getParameterBag()->resolveValue($container->getParameter('atoum.bundles'));

        foreach ($configuration as $bundleName => $data) {
            if (!isset($bundles[$bundleName])) {
                throw new \LogicException(sprintf('Bundle "%s" does not exists.', $bundleName));
            }

            $rc        = new \ReflectionClass($bundles[$bundleName]);
            $directory = dirname($rc->getFileName());

            $directories = array_map(
                function ($v) use ($directory) {
                    return $directory.'/'.$v;
                },
                $data['directories']
            );

            $definition = new Definition(
                $container->getParameter('atoum.configuration.bundle.class'),
                array($bundleName, $directories)
            );

            $bundleContainer->addMethodCall('add', array($definition));
        }
    }
993408
private function resolveParams($params, $args)
    {
        foreach ($params as $param) {
            $class = $param->getClass();

            // if the param is not a class, check $args for the value
            if (\is_null($class)) {
                $this->resolveParam($args, $param);
                continue;
            }

            $className = $class->getName();

            // if the class exists in the container, inject it
            if ($this->resolveFromContainer($className)) {
                continue;
            }

            if ($class->isInterface()) {
                throw new ConcreteClassNotFoundException("$className is an interface with no bound implementation.");
            }

            // else the param is a class, so run $this->resolve on it
            $this->addToStack($this->resolve($className, $args));
        }
    }
1102790
public function resolve(Container $container, array $args = [], $explicit = null)
    {
        $definition = $this->definition;

        if (!is_null($explicit) && !empty($explicit)) {
            $definition = $explicit;
        }

        return $definition($container, $args);
    }
1001449
public function process(ContainerBuilder $container)
    {
        $parameterBag = $container->getParameterBag();

        foreach ($container->getDefinitions() as $id => $definition) {
            try {
                $definition->setClass($parameterBag->resolveValue($definition->getClass()));
                $definition->setFile($parameterBag->resolveValue($definition->getFile()));
                $definition->setArguments($parameterBag->resolveValue($definition->getArguments()));

                $factory = $definition->getFactory();

                if (is_array($factory) && isset($factory[0])) {
                    $factory[0] = $parameterBag->resolveValue($factory[0]);
                    $definition->setFactory($factory);
                }

                $calls = array();
                foreach ($definition->getMethodCalls() as $name => $arguments) {
                    $calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
                }
                $definition->setMethodCalls($calls);

                $definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
            } catch (ParameterNotFoundException $e) {
                $e->setSourceId($id);

                throw $e;
            }
        }

        $aliases = array();
        foreach ($container->getAliases() as $name => $target) {
            $aliases[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($target);
        }
        $container->setAliases($aliases);

        $parameterBag->resolve();
    }
649451
protected function prepare(ContainerInterface $container = null, array $arguments = [])
    {
        $result = [];

        foreach ($arguments as $k => $arg) {
            if (is_array($arg)) {
                $result[$k] = $this->prepare($container, $arg);
                continue;
            } elseif ($arg == '@Container') {
                $result[$k] = $container;
                continue;
            } elseif (strpos($arg, '@') !== 0) {
                $result[$k] = $arg;
                continue;
            }

            $arg = substr($arg, 1);

            if (!$container) {
                throw new ContainerException(sprintf('Unable to resolve dependency for "%s" - missing dependency "%s"', $this->class, $arg));
            }

            $result[$k] = $container->get($arg);
        }

        return $result;
    }
959424
public function resolve(\ReflectionMethod $function, array $arguments)
    {
        // No `@ScenarioStateArgument` annotation found
        if (null === $this->reader->getMethodAnnotation($function, ScenarioStateArgument::class)) {
            return $arguments;
        }

        $paramsKeys = array_map(function (\ReflectionParameter $element) {
            return $element->getName();
        }, $function->getParameters());
        $store = $this->store->getStore();

        // Prepare arguments from annotations
        /** @var ScenarioStateArgument[] $annotations */
        $annotations = $this->reader->getMethodAnnotations($function);
        foreach ($annotations as $annotation) {
            if ($annotation instanceof ScenarioStateArgument &&
                in_array($annotation->getArgument(), $paramsKeys) &&
                $store->hasStateFragment($annotation->getName())
            ) {
                $arguments[$annotation->getArgument()] = $store->getStateFragment($annotation->getName());
            }
        }

        // Reorder arguments
        $params = [];
        foreach ($function->getParameters() as $parameter) {
            $name = $parameter->getName();
            $params[$name] = isset($arguments[$name]) ? $arguments[$name] : $arguments[$parameter->getPosition()];
        }

        return $params;
    }
1254756
private function loadArgumentResolverFactory(ContainerBuilder $container)
    {
        $definition = new Definition('Behat\Behat\Context\Argument\CompositeArgumentResolverFactory');
        $container->setDefinition(self::AGGREGATE_RESOLVER_FACTORY_ID, $definition);
    }
1051904
public function resolve(
        DefinitionInterface $definition, array $parameters = [])
    {
        /** @var CallableDefinition $definition */
        $args = (empty($parameters)) ? $definition->getArgs(): $parameters;
        return call_user_func_array($definition->getCallable(), $args);
    }
104180
private function flattenParametersFromConfig(ContainerBuilder $container, $configs, $root)
    {
        $parameters = [];

        foreach ($configs as $key => $value) {
            $parameterKey = sprintf('%s_%s', $root, $key);
            if (is_array($value)) {
                $parameters = array_merge(
                    $parameters,
                    $this->flattenParametersFromConfig($container, $value, $parameterKey)
                );

                continue;
            }

            $parameters[$parameterKey] = $value;
        }

        return $parameters;
    }
502364
protected function getRootProviderName(ContainerInterface $container)
    {
        $rootProvider = $container->getBasicDefinition()->getRootDataProvider();

        if (!$rootProvider) {
            throw new DcGeneralRuntimeException(
                'Root data provider name not specified in DCA but rootEntries section specified.'
            );
        }

        if (!$container->getDataProviderDefinition()->hasInformation($rootProvider)) {
            throw new DcGeneralRuntimeException('Unknown root data provider but rootEntries section specified.');
        }

        return $rootProvider;
    }
1221364
protected function resolveServiceId(ContainerBuilder $container, array $attr): ?string
    {
        return isset($attr[$this->attrName]) ? $this->resolveParam($container, $attr[$this->attrName]) : null;
    }
210209
private function configurePlugins(ContainerBuilder $container, array $config)
    {
        if (!empty($config['authentication'])) {
            $this->configureAuthentication($container, $config['authentication']);
        }
        unset($config['authentication']);

        foreach ($config as $name => $pluginConfig) {
            $pluginId = 'httplug.plugin.'.$name;

            if ($this->isConfigEnabled($container, $pluginConfig)) {
                $def = $container->getDefinition($pluginId);
                $this->configurePluginByName($name, $def, $pluginConfig, $container, $pluginId);
            }
        }
    }