Autowires the constructor or a method.

@param \ReflectionFunctionAbstract $reflectionMethod
@param array                       $arguments

@return array The autowired arguments

@throws AutowiringFailedException
484732
private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, array $arguments)
    {
        $class = $reflectionMethod instanceof \ReflectionMethod ? $reflectionMethod->class : $this->currentId;
        $method = $reflectionMethod->name;
        $parameters = $reflectionMethod->getParameters();
        if (method_exists('ReflectionMethod', 'isVariadic') && $reflectionMethod->isVariadic()) {
            array_pop($parameters);
        }

        foreach ($parameters as $index => $parameter) {
            if (array_key_exists($index, $arguments) && '' !== $arguments[$index]) {
                continue;
            }

            $type = ProxyHelper::getTypeHint($reflectionMethod, $parameter, true);

            if (!$type) {
                if (isset($arguments[$index])) {
                    continue;
                }

                // no default value? Then fail
                if (!$parameter->isDefaultValueAvailable()) {
                    // For core classes, isDefaultValueAvailable() can
                    // be false when isOptional() returns true. If the
                    // argument *is* optional, allow it to be missing
                    if ($parameter->isOptional()) {
                        continue;
                    }
                    $type = ProxyHelper::getTypeHint($reflectionMethod, $parameter, false);
                    $type = $type ? sprintf('is type-hinted "%s"', $type) : 'has no type-hint';

                    throw new AutowiringFailedException($this->currentId, sprintf('Cannot autowire service "%s": argument "$%s" of method "%s()" %s, you should configure its value explicitly.', $this->currentId, $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method, $type));
                }

                // specifically pass the default value
                $arguments[$index] = $parameter->getDefaultValue();

                continue;
            }

            if (!$value = $this->getAutowiredReference($ref = new TypedReference($type, $type, !$parameter->isOptional() ? $class : ''), 'for '.sprintf('argument "$%s" of method "%s()"', $parameter->name, $class.'::'.$method))) {
                $failureMessage = $this->createTypeNotFoundMessage($ref, sprintf('argument "$%s" of method "%s()"', $parameter->name, $class !== $this->currentId ? $class.'::'.$method : $method));

                if ($parameter->isDefaultValueAvailable()) {
                    $value = $parameter->getDefaultValue();
                } elseif (!$parameter->allowsNull()) {
                    throw new AutowiringFailedException($this->currentId, $failureMessage);
                }
                $this->container->log($this, $failureMessage);
            }

            $arguments[$index] = $value;
        }

        if ($parameters && !isset($arguments[++$index])) {
            while (0 <= --$index) {
                $parameter = $parameters[$index];
                if (!$parameter->isDefaultValueAvailable() || $parameter->getDefaultValue() !== $arguments[$index]) {
                    break;
                }
                unset($arguments[$index]);
            }
        }

        // it's possible index 1 was set, then index 0, then 2, etc
        // make sure that we re-order so they're injected as expected
        ksort($arguments);

        return $arguments;
    }
550384
protected function determineArgumentsFor(
        ReflectionMethod $method, 
        string $class, 
        string $method_name, 
        array $args, 
        string $selector, 
        Injector $injector
    )
    {
        $params = $method->getParameters();
        $method_args = [];

        // Determine values for each parameter
        $used_optional = false;
        foreach ($params as $param)
        {
            $name = $param->getName();

            if (array_key_exists($name, $args))
            {
                $method_args[] = $args[$name];
                continue;
            }

            $pclass = $param->getClass();
            if (null !== $pclass)
            {
                $instance = $injector->getInstance($pclass->getName(), $selector);
                $method_args[] = $instance;
                continue;
            }

            if ($param->isDefaultValueAvailable())
            {
                $default = $param->getDefaultValue();
                $method_args[] = $default;
                continue;
            }

            if ($param->isOptional())
            {
                // This and all remaining parameters have a default value
                break;
            }

            throw new DIException("Unable to determine value for parameter $name for $method_name of '$class'");
        }

        // There should be a argument for every parameter
        return $method_args;
    }
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;
    }
225479
private function resolveMethodArguments(\ReflectionMethod $method, array $incomeArgs)
    {
        $orderedArguments = [];
        foreach ($method->getParameters() as $parameter) {
            if ($parameter->isOptional()) {
                $orderedArguments[$parameter->getPosition()] = $parameter->getDefaultValue();
            }
            foreach ($incomeArgs as $key => $value) {
                if ($parameter->getName() === $key) {
                    $orderedArguments[$parameter->getPosition()] = $value;
                    continue 2;
                }
            }

            //inject root common argument
            if ($this->root && !isset($incomeArgs['root']) && 'root' === $parameter->getName()) {
                $orderedArguments[$parameter->getPosition()] = $this->root;
            }

            //inject context common argument
            if ($this->context
                && 'context' === $parameter->getName()
                && $parameter->getClass()
                && is_a($parameter->getClass()->getName(), ResolverContext::class, true)
            ) {
                $orderedArguments[$parameter->getPosition()] = $this->context;
            }
        }

        // verify required arguments and types
        foreach ($method->getParameters() as $index => $parameter) {
            $givenValue = $orderedArguments[$index] ?? null;
            // does not allow null on required arguments
            if (null === $givenValue && !$parameter->allowsNull()) {
                throw new BadRequestError();
            }
        }

        return $orderedArguments;
    }
1175312
private function orderArguments(ReflectionMethod $method, array $args): array
    {
        $result = [];
        if (!$args) {
            return $result;
        }

        foreach ($method->getParameters() as $param) {
            if (array_key_exists($param->getName(), $args)) {
                $arg = $args[$param->getName()];

                // Fetch entity from DB
                if ($arg instanceof EntityID) {
                    $arg = $arg->getEntity();
                }

                $result[] = $arg;
            }
        }

        return $result;
    }
1125691
public function execute($httpMethod, $url, array $parameters = [])
    {
        if ($this->config instanceof Config) {
            try {
                $this->response = $this->getClient()->{$httpMethod}($this->config->getAccountNumber() . $url, [
                    'json' => $parameters,
                ]);

                return json_decode((string) $this->response->getBody());

            } catch (ClientException $e) {
                throw new Handler($e);
            }

            return;
        }

        throw new \RuntimeException('The API requires a configuration instance.');
    }
1155526
protected function generateMethodSignature(\ReflectionMethod $reflectionMethod)
    {

        // initialize the array for the method params
        $params = array();

        // iterate over the reflection method's parameters
        foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
            // initialize the param
            $param = '';

            // add the type hint, if specified
            if ($typeHint = $reflectionParameter->getClass()) {
                $param .= sprintf('\%s ', $typeHint->getName());
            }

            // add the array type hint, if specified
            if ($reflectionParameter->isArray()) {
                $param .= 'array ';
            }

            // add the by reference symbol, if necessary
            if ($reflectionParameter->isPassedByReference()) {
                $param .= '&';
            }

            // prepare the parameter name
            $param .= sprintf('$%s', $reflectionParameter->getName());

            // query whether or not the parameter has a default value
            if ($reflectionParameter->isDefaultValueAvailable()) {
                // if yes, try to load the type
                $type = gettype($defaultValue = $reflectionParameter->getDefaultValue());

                // qoute it, if it's a string
                switch ($type) {
                    case 'string':
                        $param .= sprintf(' = "%s"', $defaultValue);
                        break;
                    case 'array':
                        $param .= ' = array(';
                        foreach ($defaultValue as $value) {
                            $param .= $value . ', ';
                        }
                        $param .= ')';
                        break;
                    case 'boolean':
                        $param .= sprintf(' = %s', $defaultValue ? 'true' : 'false');
                        break;
                    case 'integer':
                        $param .= sprintf(' = %s', $defaultValue);
                        break;
                    case 'double':
                        $param .= sprintf(' = %s', $defaultValue);
                        break;
                    default:
                        $param .= sprintf(' = null');

                }
            }

            // append the parameter to the array
            $params[] = $param;
        }

        // implode the paramters and return them as string
        return implode(', ', $params);
    }
601045
protected function getMethodCode(\ReflectionMethod $reflectionMethod)
    {
        $file = file($reflectionMethod->getFileName());

        $methodCodeLines = array();
        foreach (range($reflectionMethod->getStartLine(), $reflectionMethod->getEndLine() - 1) as $line) {
            $methodCodeLines[] = $file[$line];
        }

        return array_values($methodCodeLines);
    }
26307
protected function invokeMethod($object, $method, array $arguments = array())
    {
        return $this->getReflectionMethod($object, $method)->invokeArgs($object, $arguments);
    }
267046
private function overrideMethods(array $mockedMethods = null)
    {
        foreach ($this->extends as $className) {
            $reflectedClass = new ReflectionClass($className);

            foreach ($reflectedClass->getMethods() as $reflectedMethod) {
                /* @var $reflectedMethod \ReflectionMethod */
                if ($mockedMethods !== null && !in_array($reflectedMethod->getName(), $mockedMethods)) {
                    continue;
                }

                if ($reflectedMethod->isPrivate() || $reflectedMethod->isStatic() || $reflectedMethod->isConstructor()) {
                    continue;
                }

                $method = new MethodDefinition($reflectedMethod);

                $this->methods[$reflectedMethod->getName()] = $method;
                $this->mockedMethods[] = $reflectedMethod->getName();
            }
        }
    }
92986
private static function guessArgs(\ReflectionMethod $method)
    {
        $arguments = [];
        foreach ($method->getParameters() as $index => $parameter) {
            if (!$parameter->hasType()) {
                throw new InvalidArgumentException(\sprintf('Argument n°%s "$%s" on method "%s" cannot be auto-guessed as there is not type hint.', $index + 1, $parameter->getName(), $method->getName()));
            }

            try {
                $gqlType = self::resolveGraphqlTypeFromReflectionType($parameter->getType(), self::$validInputTypes, $parameter->isDefaultValueAvailable());
            } catch (\Exception $e) {
                throw new InvalidArgumentException(\sprintf('Argument n°%s "$%s" on method "%s" cannot be auto-guessed : %s".', $index + 1, $parameter->getName(), $method->getName(), $e->getMessage()));
            }

            $argumentConfig = [];
            if ($parameter->isDefaultValueAvailable()) {
                $argumentConfig['defaultValue'] = $parameter->getDefaultValue();
            }

            $argumentConfig['type'] = $gqlType;

            $arguments[$parameter->getName()] = $argumentConfig;
        }

        return $arguments;
    }
1093761
protected function getArguments(ReflectionMethod $method, RouteMatchInterface $routeMatch): array
    {
        $parameters = $routeMatch->getParameters();

        $arguments = [];
        foreach ($method->getParameters() as $parameter) {
            $name = $parameter->getName();

            if (array_key_exists($name, $parameters) === false) {
                if ($parameter->isDefaultValueAvailable() === true) {
                    $arguments[] = $parameter->getDefaultValue();
                } elseif ($parameter->allowsNull()) {
                    $arguments[] = null;
                } else {
                    throw new ParameterNotFound($name);
                }
            } else {
                $arguments[] = $parameters[$name];
            }
        }

        return $arguments;
    }
749179
protected function getMethod(RouteMatchInterface $routeMatch): ReflectionMethod
    {
        $action = $this->getAction($routeMatch);

        return new ReflectionMethod($this, $action . $this->getPostfix());
    }
1004254
private function autowireCalls(\ReflectionClass $reflectionClass, bool $isRoot): array
    {
        $this->decoratedId = null;
        $this->decoratedClass = null;
        $this->getPreviousValue = null;

        if ($isRoot && ($definition = $this->container->getDefinition($this->currentId)) && $this->container->has($this->decoratedId = $definition->innerServiceId)) {
            $this->decoratedClass = $this->container->findDefinition($this->decoratedId)->getClass();
        }

        foreach ($this->methodCalls as $i => $call) {
            $this->decoratedMethodIndex = $i;
            list($method, $arguments) = $call;

            if ($method instanceof \ReflectionFunctionAbstract) {
                $reflectionMethod = $method;
            } else {
                $definition = new Definition($reflectionClass->name);
                try {
                    $reflectionMethod = $this->getReflectionMethod($definition, $method);
                } catch (RuntimeException $e) {
                    if ($definition->getFactory()) {
                        continue;
                    }
                    throw $e;
                }
            }

            $arguments = $this->autowireMethod($reflectionMethod, $arguments);

            if ($arguments !== $call[1]) {
                $this->methodCalls[$i][1] = $arguments;
            }
        }

        return $this->methodCalls;
    }
1067120
public function injectionClass($controller, $method, $args, $decorators = [])
    {
        /**
         * @var DependentService $dependentService
         * @var DependentStruct $refClass
         */
        $dependentService = $this->container->dependentService;
        $refClass = $dependentService->newClass($controller);
        $closure = $refClass->getClosure($method);
        foreach ($decorators as $decorator) {
            $closure = $decorator(
                $this->controllerWrapper($closure)
            );
        }
        return $dependentService->call($closure, $args);
    }
379650
private function isArgumentWireable(array $arguments, $index, ReflectionParameter $parameter)
    {
        if (isset($arguments[$index]) || array_key_exists($index, $arguments)) {
            return false;
        }

        if (isset($arguments[$parameter->getName()]) || array_key_exists($parameter->getName(), $arguments)) {
            return false;
        }

        try {
            return (bool) $parameter->getClass();
        } catch (ReflectionException $e) {
            return false;
        }
    }
818229
private function executeMethod(array $arguments)
    {
        if ($this->reflection->isStatic()) {
            return $this->reflection->invokeArgs(null, $arguments);
        } elseif (is_object($this->callback[0])) {
            return $this->reflection->invokeArgs($this->callback[0], $arguments);
        }
        $instance = new $this->callback[0]();
        return $this->reflection->invokeArgs($instance, $arguments);
    }