Resolve a method for method injection.

@param string $class
@param string $method
@param array $extraMappings Optional
@return array [$instance, (string)$method, (array)$args]
425064
public function getMethod($class, $method, $extraMappings = []) {
		if (isset($this->aliases[$class])) {
			$class = $this->aliases[$class];
		}

		return [
			$this->getSingleton($class),
			$this->resolveArgs($class, $method, " when resolving method $class::$method", $extraMappings)
		];
	}
1158794
protected function createGuzzleRequest($method, $uri, array $extraParameters)
    {
        $extraParameters = $this->mergeGuzzleRequestExtraParams($extraParameters);

        return new Request(
            strtoupper($method),
            $uri,
            $extraParameters['headers'],
            $extraParameters['body'],
            $extraParameters['protocolVersion']
        );
    }
625049
protected function callWithDependencies($instance, $method)
    {
        return call_user_func_array(
            [$instance, $method], $this->resolveClassMethodDependencies([], $instance, $method)
        );
    }
982402
public function bindMany(string $class, array $methods)
  {
    /**
     * Map through the functions
     *
     * @param Closure $closure
     */
    array_map(function ($closure) use ($class) {

      $info = new ReflectionFunction($closure);

      $doc  = explode(PHP_EOL, $info->getDocComment());

      /**
       * Filter out the stuff that's not needed
       */
      array_filter($doc, function($comment) use ($class, $closure) {

        /**
         * Register a new function if its not commented out
         */
        if (str_contains($comment, '@method') && !str_contains($comment, '//')) {

          /**
           * Filter out "*" and "@method"
           */
          $filtered = array_diff(
            array_filter(explode(' ', $comment)
          ), ['*', '@method']);

          /**
           * Return the name of the method
           */
          $method = array_first($filtered, function($value) {
            if (ends_with($value, '()')) return $value;
          });

          /**
           * Bind new method to $class
           */
          if ($method) {
            $this->bind($class, substr($method, 0, strlen($method) - 2), $closure);
          }

        }

      });
    }, $methods);
  }
2905
public function injection($method, $inherentParams=[])
    {
        if (! $this->reflection->hasMethod($method)) {
            throw new \InvalidArgumentException('Method not exists.');
        }
        $instances = $this->dependentService->getParams($this->reflection, $method, count($inherentParams));
        $params = array_merge($instances, $inherentParams);
        $closure = $this->getClosure($method);
        return call_user_func_array($closure, $params);
    }
582501
public function resolveMethod($class, $method, $params = [], $isRoute = false)
    {
        $reflectionMethod = new ReflectionMethod($class, $method);

        $dependencies = $reflectionMethod->getParameters();

        return $this->getDependencies($dependencies, $params, $isRoute);
    }
134412
public function getSpecificSubclassMapping(string $class): self
    {
        if ($this->class->getClassName() === $class) {
            return $this;
        }

        if (!is_subclass_of($class, $this->class->getClassName(), true)) {
            throw InvalidArgumentException::format(
                'Invalid class supplied to %s: must be a subclass of %s, %s given',
                __METHOD__, $this->class->getClassName(), $class
            );
        }

        foreach ($this->subClassMappings as $mapping) {
            if (is_subclass_of($class, $mapping->getDefinition()->getClassName(), true)) {
                return $mapping->getDefinition()->getSpecificSubclassMapping($class);
            }
        }

        throw InvalidArgumentException::format(
            'Invalid class supplied to %s: cannot find mapping for %s',
            __METHOD__, $class
        );
    }
171572
protected function resolveClassMethodDependencies( array $parameters, $instance, $method )
	{
		if ( !method_exists( $instance, $method ) )
			return $parameters;

		return $this->resolveMethodDependencies( $parameters, new ReflectionMethod( $instance, $method ) );
	}
316705
public static function fromMethod(
        string $method,
        string $class = null,
        bool $withParents = false
    ): array
    {
        if ($class) {

            try {

                $refMethod = new \ReflectionMethod($class, $method);
            }
            catch (\ReflectionException $e) {

                throw new Exception(
                    "Method '{$class}::{$method}' not found.",
                    Exception::METHOD_NOT_FOUND
                );
            }
        }
        else {

            try {

                $refMethod = new \ReflectionMethod($method);
            }
            catch (\ReflectionException $e) {

                throw new Exception(
                    "Method '{$method}' not found.",
                    Exception::METHOD_NOT_FOUND
                );
            }
        }

        $docComment = $refMethod->getDocComment();

        if ($withParents) {

            $refClass = $refMethod->getDeclaringClass();

            while (1) {

                if ($refClass = $refClass->getParentClass()) {

                    try {

                        $refMethod = $refClass->getMethod($method);
                    }
                    catch (\ReflectionException $e) {

                        break;
                    }

                    if (!$refMethod) {

                        continue;
                    }

                    if ($parentDoc = $refMethod->getDocComment()) {

                        $docComment = $docComment === false ?
                            $parentDoc :
                            "{$parentDoc}{$docComment}";
                    }
                }
                else {

                    break;
                }
            }
        }

        unset($refMethod, $refClass);

        if ($docComment === false) {

            return [];
        }

        return Parser::parseDocComment($docComment);
    }
165247
protected function callOnceBeforeMethodHooks($classInstance, $method, array $args = [])
    {
        $method = self::getCalledMethod($method);

        $onceBeforeMethodName = 'onceBefore'.ucfirst($method);
        if ( ! isset($this->instanceOnceCalledMethods['before'][$onceBeforeMethodName])) {
            if (isset($this->hooks[$onceBeforeMethodName])) {
                foreach ($this->hooks[$onceBeforeMethodName] as $callable) {
                    try {
                        $return = $this->callCallable($classInstance, $callable, $args, $method, false);
                    } catch (CancelPropagationException $e) {
                        break;
                    }

                    if ($return !== null) {
                        return $return;
                    }
                }

                $this->instanceOnceCalledMethods['before'][$onceBeforeMethodName] = true;
            }
        }

        $return = $this->callGlobalOnceBeforeMethodHooks($classInstance, $method, $onceBeforeMethodName);

        if ($return !== null) {
            return $return;
        }
    }
902579
public function make($class, array $params = null)
    {
        if ($class == 'array') {
            return [];
        }

        $reflected = $this->reflect($class);

        if (empty($reflected->getConstructor())) {

            if ($reflected->isInterface()) {

                if ($match = $this->findMatchInParams($reflected, $params)) {
                    return $this->make($match->getName());
                }

                throw new IocNotResolvableException(
                    'Cannot instantiate ' . $reflected->getName()
                );
            }

            return $reflected->newInstance();
        }

        $dependencies = $this->getDependencies($reflected);

        $instanceArgs = $this->resolveDependencies($dependencies, $params);

        $instanceArgs = $this->setArgsValues($params, $instanceArgs);

        if (count($dependencies) != count($instanceArgs)) {
            throw new UnresolvedDependenciesException(
                'Could not resolve all dependencies', [
                'Required' => $dependencies,
                'Resolved' => $instanceArgs
            ]);
        }
        $instanceArgs = $this->mergeArgsAndParams($instanceArgs, $params);

        return $reflected->newInstanceArgs($instanceArgs);
    }
317608
protected function _injectMethodsAndProperties(
        DefinitionInterface $definition, $instance)
    {
        $classReflection = new ReflectionClass($instance);

        /** @var ObjectDefinition $definition */

        // Property injections
        foreach ($definition->getProperties() as $property)
        {
            $this->_propertyInjection($instance, $property, $classReflection);
        }

        // Method injections
        foreach ($definition->getMethods() as $method) {
            $this->_methodInjection($instance, $method, $classReflection);
        }
    }
1085258
protected function callAfterHooks($classInstance, $method, array $args = [])
    {
        $return = $this->callAfterAllHooks($classInstance, $method);

        if ($return !== null) {
            return $return;
        }

        $return = $this->callAfterMethodHooks($classInstance, $method, $args);

        if ($return !== null) {
            return $return;
        }

        $return = $this->callOnceAfterHooks($classInstance, $method, $args);

        if ($return !== null) {
            return $return;
        }
    }
1106966
public function callMethod($class, $method, array $args = array())
    {
        $method = $this->findMethod($class, $method);
        $method->setAccessible(true);

        return $method->invokeArgs(
            is_object($class) ? $class : null,
            $args
        );
    }
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;
    }
401561
public function resolveInjectable(Container $container, $class)
    {
        $id = $this->key === null ? $class : $this->key;

        if ($container->has($id)) {
            return $container->get($id, $this->new);
        }

        if (!class_exists($id)) {
            throw new DependencyResolutionException(
                sprintf('Class: "%s" not exists.', $id)
            );
        }

        return $container->newInstance($id);
    }
886287
public function callClassMethod($class, $method, ...$arguments)
	{
		$resolvedParameters = [];
		$reflectedClass = new ReflectionCLass($class);
		if (!$reflectedClass->hasMethod($method)) {
			throw new ReflectionException('Call to undefined method ' . $method);
		}

		$methodName = $method;
		$method = $reflectedClass->getMethod($method);
		$methodParameters = $method->getParameters();

		if (count($methodParameters) < 1) {
			return $method;
		}

		$resolvedParameters = array_map(function($param) use ($reflectedClass) {
			$type = $param->getType();

			if (preg_match("/(.*?)\\\/", $type)) {
				$type = (String) $type;
				return new $type;
			}

			if (!$param->isDefaultValueAvailable()) {
				return $param = '';
			}

			return $param->getDefaultValue();
			
		}, $methodParameters);

		$resolvedParameters = array_filter($resolvedParameters);
		$resolvedParameters = array_merge($resolvedParameters, $arguments);

		if ($methodName == '__construct') {
			return $reflectedClass->newInstanceArgs($resolvedParameters);
		}

		return $method->invokeArgs($class, $resolvedParameters);
	}