Autowires given arguments using provided container.

@param ReflectionFunctionAbstract $reflection
@param array $arguments

@return array

@throws ContainerExceptionInterface if unset argument typehint can not be resolved from container
971165
public function autowireArguments(ReflectionFunctionAbstract $reflection, array $arguments)
    {
        $newArguments = $arguments;
        foreach ($reflection->getParameters() as $index => $parameter) {
            if ($this->isArgumentWireable($newArguments, $index, $parameter)) {
                $newArguments[$index] = $this->container->get($parameter->getClass()->getName());
            }
        }

        return $newArguments;
    }
480677
public function getParameter(\ReflectionParameter $parameter, array $args = [])
    {
        $class = $parameter->getClass();

        if ($class && $this->has($class->name)) {
            return $this->get($class->name);
        }

        if ($class && array_key_exists($class->name, $args)) {
            return $args[$class->name];
        }

        if (array_key_exists($parameter->name, $args)) {
            return $args[$parameter->name];
        }

        throw new NotFoundException("Unresolvable " . ($class ? $class->name : $parameter->name));
    }
1001086
public function build(ReflectionClass $reflectionClass, Service $annotation, Definition $definition)
    {
        /** @var Definition $definition */
        [$serviceId, $definition] = parent::build($reflectionClass, $annotation, $definition);

        $definition->setPublic(false);
        $this->container->setDefinition($serviceId, $definition);

        /** @var CompilerPassInterface $compilerPass */
        $compilerPass = $this->container->get($serviceId);
        $this->container->addCompilerPass(
            $compilerPass,
            $annotation->type,
            $annotation->priority
        );

        return [$serviceId, $definition];
    }
52653
private function resolveArguments(ReflectionClass $reflection, array $arguments, array $resolvers)
    {
        $newArguments = $arguments;

        foreach ($resolvers as $resolver) {
            $newArguments = $resolver->resolveArguments($reflection, $newArguments);
        }

        if (!$reflection->hasMethod('__construct')) {
            return $newArguments;
        }

        $constructor = $reflection->getConstructor();
        $newArguments = $this->argumentOrganiser->organiseArguments($constructor, $newArguments);
        $this->validator->validateArguments($constructor, $newArguments);

        return $newArguments;
    }
1096527
public function checkIfConstructorHasDefaultArgs($dependency, $arguments)
    {
        $parameters = $dependency->getDefaultValue();

        if (empty($parameters) && !empty($arguments)) {
            $parameters = $arguments;
        }

        return $parameters;
    }
689379
private function getFunctionArguments(\ReflectionFunctionAbstract $reflection, $values)
    {
        $arguments = [];
        if (!empty($reflection->getParameters())) {
            foreach ($values as $value) {
                $arguments[] = $value;
            }
        }
        return $arguments;
    }
543885
private function getInjector(\ReflectionClass $reflection): InjectorInterface
    {
        if (isset($this->injectors[$reflection->getName()])) {
            //Stated directly
            $injector = $this->get($this->injectors[$reflection->getName()]);
        } else {
            //Auto-injection!
            $injector = $this->get($reflection->getConstant('INJECTOR'));
        }

        if (!$injector instanceof InjectorInterface) {
            throw new InjectionException(sprintf(
                "Class '%s' must be an instance of InjectorInterface for '%s'",
                get_class($injector),
                $reflection->getName()
            ));
        }

        return $injector;
    }
910924
public function exec($arguments) {
        //parse
        $options = $this->parse();

        // check if help was requested
        if(is_integer($options)) {
            return $options;
        }

        // extract and remove special vars
        $instance = $options["__instance"];
        $method   = $options["__method"];

        unset($options["__instance"]);
        unset($options["__method"]);

        // execute action - print error on failure
        try {
            return (int)Misc::reflectionFunction([ $instance, $method ], self::adjustOptions($options));
        }
        catch(Exception $e) {
            return $this->printError($e->getMessage());
        }
    }
2689
protected function arguments(\ReflectionFunctionAbstract $reflection, $parameters = array())
    {
        $arguments = array();

        foreach ($reflection->getParameters() as $key => $parameter)
        {
            $name = $parameter->getName();

            if ($class = $parameter->getClass())
            {
                $name = $class->getName();
            }

            if (isset($parameters[$name]))
            {
                if ($parameter->isDefaultValueAvailable())
                {
                    $arguments[$name] = $parameter->getDefaultValue();
                }

                if ($parameters[$name])
                {
                    $arguments[$name] = $parameters[$name];
                }

                continue;
            }

            $arguments[$name] = $this->instance($name);
        }

        return $arguments;
    }
328500
public function getParameters(\ReflectionFunctionAbstract $reflection, array $args = [])
    {
        $dependencies = $reflection->getParameters();
        $parameters = [];

        foreach ($dependencies as $parameter) {
            $parameters[] = $this->getParameter($parameter, $args);
        }

        return $parameters;
    }
507417
private function resolverClass($dependency, $arguments)
    {
        list($resolveClass, $reflectionParam) = $this->injector->getReflectionParam($dependency);

        // Application and Container cannot be injected into controller currently
        // since Application constructor is protected
        if ($reflectionParam->IsInstantiable()) {
            return $this->makeInstance($resolveClass, $arguments);
        }

        return $this->injector->interfaceInjection($reflectionParam);
    }
335388
private function assertType(
        \ReflectionParameter $parameter,
        \ReflectionFunctionAbstract $context,
        $value
    ) {
        if (is_null($value)) {
            if (
                !$parameter->isOptional()
                && !($parameter->isDefaultValueAvailable() && $parameter->getDefaultValue() === null)
            ) {
                throw new ArgumentException($parameter, $context);
            }

            return;
        }

        $type = $parameter->getType();

        if ($type == 'array' && !is_array($value)) {
            throw new ArgumentException($parameter, $context);
        }

        if (($type == 'int' || $type == 'float') && !is_numeric($value)) {
            throw new ArgumentException($parameter, $context);
        }

        if ($type == 'bool' && !is_bool($value) && !is_numeric($value)) {
            throw new ArgumentException($parameter, $context);
        }
    }
839595
private function getInjectionFuncParams(Argument $argument) : array
    {
        $dependencyIndex = (string) $argument;
        if ($this->container->getContainer()[$dependencyIndex] instanceof DependencyProvider) {
            return $this->getInjectionProviderParams($argument);
        }

        return [new Node\Arg(new Scalar\String_((string) $argument))];
    }
387021
private static function getFunctionName(\ReflectionFunctionAbstract $reflection) : string
    {
        $name = $reflection->name.'()';

        if ($reflection instanceof \ReflectionMethod) {
            $name = $reflection->getDeclaringClass()->name.'::'.$name;
        }

        return $name;
    }
229705
private function computeArguments(
        \ReflectionMethod $constructor,
        MapInterface $properties
    ): MapInterface {
        $arguments = $properties->clear();

        foreach ($constructor->getParameters() as $parameter) {
            if ($this->canInject($parameter, $properties)) {
                $arguments = $arguments->put(
                    $parameter->name,
                    $properties->get($parameter->name)
                );
            }
        }

        return $arguments;
    }
413979
public static function createResourceForClass(\ReflectionClass $reflectionClass)
    {
        $metadata = array();

        if ($constructor = $reflectionClass->getConstructor()) {
            $metadata['__construct'] = self::getResourceMetadataForMethod($constructor);
        }

        foreach (self::getSetters($reflectionClass) as $reflectionMethod) {
            $metadata[$reflectionMethod->name] = self::getResourceMetadataForMethod($reflectionMethod);
        }

        return new AutowireServiceResource($reflectionClass->name, $reflectionClass->getFileName(), $metadata);
    }
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;
    }