Resolve argument definitions into an array of arguments.

@param array  $argumentDefinitions The service arguments definition.

@return array The service constructor arguments.

@throws ContainerException On failure.
428265
private function resolveArguments(array $argumentDefinitions)
    {
        $arguments = [];

        foreach ($argumentDefinitions as $argumentDefinition) {
            if ($argumentDefinition instanceof ServiceReference) {
                $argumentServiceName = $argumentDefinition->getName();

                $arguments[] = $this->get($argumentServiceName);
            } elseif ($argumentDefinition instanceof ParameterReference) {
                $argumentParameterName = $argumentDefinition->getName();

                $arguments[] = $this->getParameter($argumentParameterName);
            } else {
                $arguments[] = $argumentDefinition;
            }
        }

        return $arguments;
    }
642197
private function findAndValidateMappingAwareDefinitionList(ContainerBuilder $container): array
    {
        $mappingAwareServiceDefinitionList = [];
        $methodAwareServiceIdList = array_keys($container->findTaggedServiceIds(self::JSONRPC_METHOD_AWARE_TAG));
        foreach ($methodAwareServiceIdList as $serviceId) {
            $definition = $container->getDefinition($serviceId);

            $this->checkMethodAwareServiceIdList($definition, $serviceId, $container);

            $mappingAwareServiceDefinitionList[$serviceId] = $definition;
        }

        return $mappingAwareServiceDefinitionList;
    }
864480
protected function getDefinition(
        /*# string */ $rawId,
        array $args
    )/*# : array */ {
        // get the definition
        $def = $this->getResolver()->getService($rawId);

        // fix class
        if (!is_array($def) || !isset($def['class'])) {
            $def = ['class' => $def];
        }

        // add arguments
        if (!empty($args)) {
            $def['args'] = $args;
        }

        return (array) $def;
    }
315935
private function processArgumentResolvers(ContainerBuilder $container)
    {
        $references = $this->processor->findAndSortTaggedServices($container, self::ARGUMENT_RESOLVER_TAG);
        $definition = $container->getDefinition(self::FACTORY_ID);

        foreach ($references as $reference) {
            $definition->addMethodCall('registerArgumentResolver', array($reference));
        }
    }
373381
private function createResolvers(array $config, ContainerInterface $container)
    {
        $resolvers = [];

        foreach ($config as $resolver) {
            if ($resolver instanceof Resolver\ResolverInterface) {
                $resolvers[] = $resolver;
                continue;
            }

            if (! is_string($resolver)) {
                continue;
            }

            if ($container->has($resolver)) {
                $resolvers[] = $container->get($resolver);
                continue;
            }

            if (class_exists($resolver)) {
                $resolvers[] = new $resolver();
                continue;
            }
        }

        return $resolvers;
    }
898291
protected function resolveArguments(
        ReflectionMethod $method,
        array $arguments
    ) {
        $params = $method->getParameters();
        $result = [];

        foreach ($params as $param) {
            /** @var ReflectionParameter $param */
            if (isset($arguments[$param->name])) {
                $result[$param->name] = $arguments[$param->name];
                continue;
            }

            $class = $param->getClass();
            if ($class) {
                $className = $class->getName();
                if ($this->isShared($className)) {
                    $result[$className] = isset($this->sharedInstances[$className])
                        ? $this->sharedInstances[$className]
                        : $this->get($className);
                } else {
                    $result[$className] = $this->create($className);
                }
            }
        }

        return $result;
    }
818631
private function resolveArgument($argument)
    {
        if ($argument instanceof Definition) {
            return $this->resolveDefinition($argument);
        }

        if ($argument instanceof Reference) {
            return $this->resolveReference($argument);
        }

        if (is_array($argument)) {
            return $this->resolveArguments($argument);
        }

        return $argument;
    }
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();
    }
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;
    }
233230
public function resolveArguments(ReflectionClass $classReflection, array $arguments = [])
    {
        $injArguments = $this->parseAnnotations(
            $this->getMethodAnnotations($classReflection)
        );

        if (!empty($injArguments)) {
            $arguments = [];
            foreach ($injArguments as $name => $service) {
                $arguments[$name] = $service;
            }
        }

        return $arguments;
    }
452959
private function generateServiceClosures(array $clientDefinitions): array
    {
        $clients = [];
        foreach (array_keys($clientDefinitions) as $key) {
            $clients[$key] = new ServiceClosureArgument(new Reference($key));
        }

        return $clients;
    }
1370162
private function resolveConstructorArguments(array $args, \ReflectionClass $reflection): array
    {
        $params = [];
        foreach ($reflection->getConstructor()->getParameters() as $param) {
            $params[$param->getName()] = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
        }
        return array_merge($params, array_intersect_key($args, $params));
    }
114216
public function resolveMetaArguments($arguments)
    {
        if ($this->isPreservedAs('multiple') && ! isset($arguments['key'])) {
            throw new MetaArgumentsException("You need to provide key for processing Taxonomy [{$this->slug}] meta.");
        }

        return array_merge($this->metaDefaults, $arguments);
    }
1144077
protected function resolveDefitions(PropertyDefinitionCollectionInterface $propertyDefinitionCollection = null)
    {
        if ($propertyDefinitionCollection instanceof PropertyDefinitionCollectionInterface) {
            return $propertyDefinitionCollection->import($this->propertiesAndTypes());
        }

        $className = $this->calledClassName();

        if ($this->runtimeCache->has($className, __METHOD__)) {
            return $this->runtimeCache->get($className, __METHOD__);
        }

        $propertyDefinitionCollection = $this->createPropertyDefinitionCollection();

        $propertyDefinitionCollection->import($this->propertiesAndTypes());

        $this->runtimeCache->set($className, $propertyDefinitionCollection, __METHOD__);

        return $propertyDefinitionCollection;
    }
400379
private function parseArgs($rawArgs) {
        if (!is_array($rawArgs)) {
            throw new ServiceContainerException('constructor-args or call argument must be array!');
        }

        if (empty($rawArgs)) {
            return [];
        }

        $args = [];
        foreach ($rawArgs as $rawArg) {
            $args[] = $this->parseArg($rawArg);
        }
        return $args;
    }
171780
private function defineParsers(ContainerBuilder $container): array
    {
        $testResultFactory = new Reference(TestResultFactory::class);
        $parserDefinitions = [
            TestStartParser::class => new Definition(TestStartParser::class),
            'paraunit.parser.pass_parser' => new Definition(GenericParser::class, [
                $testResultFactory,
                new Reference('paraunit.test_result.pass_container'),
                LogPrinter::STATUS_PASS,
            ]),
            'paraunit.parser.incomplete_parser' => new Definition(GenericParser::class, [
                $testResultFactory,
                new Reference('paraunit.test_result.incomplete_container'),
                LogPrinter::STATUS_ERROR,
                LogPrinter::MESSAGE_INCOMPLETE_TEST,
            ]),
            'paraunit.parser.skipped_parser' => new Definition(GenericParser::class, [
                $testResultFactory,
                new Reference('paraunit.test_result.skipped_container'),
                LogPrinter::STATUS_ERROR,
                LogPrinter::MESSAGE_SKIPPED_TEST,
            ]),
            'paraunit.parser.risky_parser' => new Definition(GenericParser::class, [
                $testResultFactory,
                new Reference('paraunit.test_result.risky_container'),
                LogPrinter::STATUS_ERROR,
                LogPrinter::MESSAGE_RISKY_TEST,
            ]),
            'paraunit.parser.warning_parser' => new Definition(GenericParser::class, [
                $testResultFactory,
                new Reference('paraunit.test_result.warning_container'),
                LogPrinter::STATUS_WARNING,
            ]),
            'paraunit.parser.failure_parser' => new Definition(GenericParser::class, [
                $testResultFactory,
                new Reference('paraunit.test_result.failure_container'),
                LogPrinter::STATUS_FAIL,
            ]),
            'paraunit.parser.error_parser' => new Definition(GenericParser::class, [
                $testResultFactory,
                new Reference('paraunit.test_result.error_container'),
                LogPrinter::STATUS_ERROR,
            ]),
            AbnormalTerminatedParser::class => new Definition(AbnormalTerminatedParser::class, [
                $testResultFactory,
                new Reference('paraunit.test_result.abnormal_terminated_container'),
                LogFetcher::LOG_ENDING_STATUS,
            ]),
            UnknownResultParser::class => new Definition(UnknownResultParser::class, [
                $testResultFactory,
                new Reference('paraunit.test_result.unknown_container'),
                '',
            ]),
        ];

        $parserReferences = [];
        foreach ($parserDefinitions as $name => $definition) {
            $container->setDefinition($name, $definition);
            $parserReferences[] = new Reference($name);
        }

        $container->setDefinition(DeprecationParser::class, new Definition(DeprecationParser::class, [
            new Reference('paraunit.test_result.deprecation_container'),
        ]));

        return $parserReferences;
    }
447908
private function getOptions(InputDefinition $definition, array $options): array
    {
        $argv = [];
        foreach ($options as $name => $value) {
            $definition->getOption($name) && $argv[] = sprintf('--%s=%s', $name, $value);
        }
        return $argv;
    }