Resolves the specified parameters from a container.

@param  \ReflectionFunctionAbstract $reflection
@param  array                       $parameters
@return array
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;
    }
1221729
public function resolve(DefinitionInterface $definition)
    {
        switch (true) {
            case $definition instanceof ReferenceDefinitionInterface:
                return $this->container->get($definition->getTarget());

            case $definition instanceof ParameterDefinitionInterface:
                return $definition->getValue();

            case $definition instanceof ObjectDefinitionInterface:
                $reflection = new \ReflectionClass($definition->getClassName());

                // Create the instance
                $constructorArguments = $definition->getConstructorArguments();
                $constructorArguments = array_map([$this, 'resolveSubDefinition'], $constructorArguments);
                $service = $reflection->newInstanceArgs($constructorArguments);

                // Set properties
                foreach ($definition->getPropertyAssignments() as $propertyAssignment) {
                    $propertyName = $propertyAssignment->getPropertyName();
                    $service->$propertyName = $this->resolveSubDefinition($propertyAssignment->getValue());
                }

                // Call methods
                foreach ($definition->getMethodCalls() as $methodCall) {
                    $methodArguments = $methodCall->getArguments();
                    $methodArguments = array_map([$this, 'resolveSubDefinition'], $methodArguments);
                    call_user_func_array([$service, $methodCall->getMethodName()], $methodArguments);
                }

                return $service;

            case $definition instanceof FactoryCallDefinitionInterface:
                $factory = $definition->getFactory();
                $methodName = $definition->getMethodName();
                $arguments = (array) $definition->getArguments();
                $arguments = array_map([$this, 'resolveSubDefinition'], $arguments);

                if (is_string($factory)) {
                    return call_user_func_array([$factory, $methodName], $arguments);
                } elseif ($factory instanceof ReferenceDefinitionInterface) {
                    $factory = $this->container->get($factory->getTarget());
                    return call_user_func_array([$factory, $methodName], $arguments);
                }
                throw new InvalidDefinition(sprintf('Definition "%s" does not return a valid factory'));

            default:
                throw UnsupportedDefinition::fromDefinition($definition);
        }
    }
292825
public function resolve($factory=false, $parameters=[]) {
        if (!$factory && $this->instance)
            return $this->instance;

        $instance   = null;
        $definition = $this->definition;
        !$factory && $parameters = [];

        if (is_string($definition)) {                       // plain strings are class names without parameters
            if (!is_class($definition)) throw new ClassNotFoundException('Cannot resolve service "'.$this->name.'" (unknown class "'.$definition.'")');
            $instance = new $definition(...$parameters);
        }
        else if (is_object($definition)) {                  // objects may be a \Closure or an already resolved instance
            $instance = $definition instanceof \Closure ? $definition(...$parameters) : $definition;
        }
        else throw new IllegalTypeException('Cannot resolve service "'.$this->name.'" (illegal definition type: '.gettype($definition).')');

        if (!$factory)
            $this->instance = $instance;
        return $instance;
    }
1207151
protected function resolvePrimitive(ReflectionParameter $parameter)
    {
        if (! is_null($concrete = $this->getContextualConcrete('$'.$parameter->name))) {
            return $concrete instanceof Closure ? $concrete($this) : $concrete;
        }

        if ($parameter->isDefaultValueAvailable()) {
            return $parameter->getDefaultValue();
        }

        $this->unresolvablePrimitive($parameter);
    }
1291403
private function makeParameters(array $parameters): array
    {
        return array_map(function (ReflectionParameter $parameter) {
            $class = $parameter->getClass();

            if ($class instanceof ReflectionClass) {
                return $this->make($class->getName());
            }

            if ($parameter->isDefaultValueAvailable()) {
                return $parameter->getDefaultValue();
            }

            return null;
        }, $parameters);
    }
56734
private function resolveParameter(\ReflectionParameter $param, array $args)
    {
        $className = $param->getClass();
        if ($className !== null) {
            return $this->make($className->getName());
        } elseif (isset($args[$param->getName()])) {
            return $args[$param->getName()];
        } elseif ($param->isOptional()) {
            return $param->getDefaultValue();
        } else {
            throw new ClassResolvingException('Cannot resolve Parameter #'.$param->getPosition()." '".$param->getName()."'");
        }
    }
331208
public function resolve(array $parameters) : array
    {
        if (!$number = $this->reflection->getNumberOfParameters()) {
            return [];
        }

        $arguments = \array_fill(0, $number, null);

        foreach ($this->getParameters() as $pos => $parameter) {
            $result = $this->match($parameter, $parameters);

            if ($result) {
                $arguments[$pos] = $result[1];
                unset($parameters[$result[0]]);
                continue;
            }

            if ($parameter->isDefaultValueAvailable()) {
                $arguments[$pos] = $parameter->getDefaultValue();
                continue;
            }

            throw UnresolvableArgumentException::fromParameter($parameter);
        }

        return $arguments;
    }
942082
public function resolveCallable(?string $name, callable $closure, ?array $parameters = null)
    {
        $definitions = isset($name) && $this->container->isDefined($name)
            ? $this->container->getDefiniition($name) : null;

        $callable = $this->getCallable($closure);
        $parameters = $parameters ?? $this->resolveParameters($callable->getParameters() ?? null, $definitions);

        return $callable->invokeArgs($parameters);
    }
1222342
public function getDependencies(\ReflectionClass $reflected)
    {
        $dependencies = [];

        if ($constructor = $reflected->getConstructor()) {
            $parameters = $constructor->getParameters();
            foreach ($parameters as $parameter) {
                $dependencies[] = $this->getDependency($parameter, $reflected);
            }
        }

        return $dependencies;
    }
912370
public function resolveMethodDependencies(array $parameters, ReflectionFunctionAbstract $reflector)
    {
        foreach ($reflector->getParameters() as $key => $parameter) {
            $instance = $this->transformDependency($parameter, $parameters);

            if (!is_null($instance)) {
                $this->spliceIntoParameters($parameters, $key, $instance);
            }
        }

        return $parameters;
    }
680693
public function resolver($definition, array $args = [])
    {
        if ($definition instanceof Closure) {
            $resolvedDefinition = call_user_func_array($definition, $args);
        } elseif (is_object($definition)) {
            $resolvedDefinition = $definition;
        } elseif (is_string($definition)) {
            if (class_exists($definition)) {
                $reflectionObj = new ReflectionClass($definition);
                $resolvedDefinition = $reflectionObj->newInstanceArgs($args);
            } else {
                throw new Exception(sprintf('Class "%s" does not exist.', $definition));
            }
        } elseif (is_array($definition)) {
            $resolvedDefinition = self::fromArray($definition);
        } else {
            throw new Exception(sprintf('Definition type "%s" does not support.', gettype($definition)));
        }

        return $resolvedDefinition;
    }
387021
private static function getFunctionName(\ReflectionFunctionAbstract $reflection) : string
    {
        $name = $reflection->name.'()';

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

        return $name;
    }
914586
protected function resolve($abstract, array $parameters = [])
    {
        if ($this->bound($abstract)) {
            array_unshift($parameters, $this);

            return call_user_func_array($this->bindings[$abstract]['concrete'], $parameters);
        }

        $reflector = new ReflectionClass($abstract);

        if (!$constructor = $reflector->getConstructor()) {
            return new $abstract($parameters);
        }

        $constructorParams = $constructor->getParameters();

        $callParams = [];

        foreach ($constructorParams as $param) {
            if ($param->getClass()) {
                $callParams[] = $this->__invoke($param->getClass()->getName());
            }
        }

        foreach ($parameters as $key => $value) {
            $callParams[] = $value;
        }

        return $reflector->newInstanceArgs($callParams);
    }
689379
private function getFunctionArguments(\ReflectionFunctionAbstract $reflection, $values)
    {
        $arguments = [];
        if (!empty($reflection->getParameters())) {
            foreach ($values as $value) {
                $arguments[] = $value;
            }
        }
        return $arguments;
    }
476353
public function resolveMethodParameters($instance, $method, $parameters, $labels = false)
    {
        // method reflection
        $reflectionMethod = new ReflectionMethod($instance, $method);

        // resolved array of parameters
        return $this->resolveParameters($reflectionMethod->getParameters(), $parameters, $labels);
    }
365702
private function resolveParameterName(
        ContainerBuilder $container,
        $parameterName
    ) {
        if (!is_string($parameterName)) {
            return $parameterName;
        }

        return $container->hasParameter($parameterName)
            ? $container->getParameter($parameterName)
            : $parameterName;
    }
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;
    }