Call a string reference to a class using Class@method syntax.

@param  string  $target
@param  array  $parameters
@param  string|null  $defaultMethod

@return mixed

@throws \Exception
180901
protected function callClass($target, array $parameters = array(), $defaultMethod = null)
    {
        $segments = explode('@', $target);
        // If the listener has an @ sign, we will assume it is being used to delimit
        // the class name from the handle method name. This allows for handlers
        // to run multiple handler methods in a single class for convenience.
        $method = count($segments) == 2 ? $segments[1] : $defaultMethod;
        if (is_null($method)) {
            throw new \Exception('Method not provided.');
        }
        return $this->call([$this->make($segments[0]), $method], $parameters);
    }
1276198
protected function get($parameter, $default=null) {
		return isset($this->parameters[$parameter]) ? $this->parameters[$parameter] : $default;
	}
75957
public function getParameterType(
        ReflectionMethod $method,
        string $parameterName,
        ? string $default = null
    ) : ? string {
        $parameters = $method->getParameters();

        foreach ($parameters as $parameter) {
            if ($parameter->getName() === $parameterName) {
                $class = $parameter->getClass();

                return $class
                    ? $class->getName()
                    : $default;
            }
        }

        return $default;
    }
951873
public static MethodCallExpression applyDefaultMethodTarget(final MethodCallExpression methodCallExpression, final ClassNode targetClassNode) {
        return applyMethodTarget(methodCallExpression, targetClassNode, (ClassNode[])null);
    }
383301
private static function getCallable($target, array $construct_args)
    {
        if (empty($target)) {
            throw new RuntimeException('No callable provided');
        }

        if (is_string($target)) {
            //is a class "classname::method"
            if (strpos($target, '::') === false) {
                $class = $target;
                $method = '__invoke';
            } else {
                list($class, $method) = explode('::', $target, 2);
            }

            if (!class_exists($class)) {
                throw new RuntimeException("The class {$class} does not exists");
            }

            $fn = new \ReflectionMethod($class, $method);

            if (!$fn->isStatic()) {
                $class = new \ReflectionClass($class);
                $instance = $class->hasMethod('__construct') ? $class->newInstanceArgs($construct_args) : $class->newInstance();
                $target = [$instance, $method];
            }
        }

        //if it's callable as is
        if (is_callable($target)) {
            return $target;
        }

        throw new RuntimeException('Invalid callable provided');
    }
772373
public function getArgument($offset, $default = null)
    {
        $value = $this->io->getArgument($offset);

        if (!is_null($value)) {
            return $value;
        }

        if (is_callable($default)) {
            return call_user_func($default);
        }

        return $default;
    }
222302
protected function invoke($targetObject, $methodName, array $methodParams)
	{
		if (strpos($methodName, '.') !== false) {
			list($propertyName, $methodName) = explode('.', $methodName, 2);

			// access native array item
			if (is_array($targetObject)) {
				if (array_key_exists($propertyName, $targetObject)) {
					return $this->invoke(
						$targetObject[$propertyName],
						$methodName,
						$methodParams
					);
				}
			}

			// access array object
			else if ($targetObject instanceof \ArrayAccess) {
				if ($targetObject->offsetExists($propertyName)) {
					return $this->invoke(
						$targetObject->offsetGet($propertyName),
						$methodName,
						$methodParams
					);
				}
			}

			// access object property
			else if (is_object($targetObject)) {
				if (get_class($targetObject) == 'stdClass') {
					if (isset($targetObject->$propertyName)) {
						return $this->invoke(
							$targetObject->$propertyName,
							$methodName,
							$methodParams
						);
					}
				}
				else {
					$class = new \ReflectionClass($targetObject);

					if ($class->hasProperty($propertyName)) {
						$property = $class->getProperty($propertyName);
						if ($property->isPublic()) {
							return $this->invoke(
								$property->getValue($targetObject),
								$methodName,
								$methodParams
							);
						}
					}

					$getterName = 'get';
					$getterName .= implode('', array_map('ucfirst', explode('_', $propertyName)));
					if ($class->hasMethod($getterName)) {
						$getter = $class->getMethod($getterName);
						if ($getter->isPublic()) {
							return $this->invoke(
								$getter->invoke($targetObject),
								$methodName,
								$methodParams
							);
						}
					}
				}
			}
		}
		else if (is_object($targetObject)) {
			$class = new \ReflectionClass($targetObject);

			if ($class->hasMethod($methodName)) {
				$method = $class->getMethod($methodName);
				if ($method->isPublic()) {
					if (
						$this->logger !== null &&
						$this->logger->isHandling(\Monolog\Logger::DEBUG)
					) {
						$this->logger->addDebug(
							'Invoke method from remote',
							array(
								 'class' => get_class($targetObject),
								 'method' => $methodName,
								 'params' => $methodParams
							)
						);
					}

					return $method->invokeArgs($targetObject, $methodParams);
				}
			}
		}

		if (
			$this->logger !== null &&
			$this->logger->isHandling(\Monolog\Logger::DEBUG)
		) {
			$this->logger->addError(
				'Could not invoke method, because method not exists or not accessible',
				array(
					 'class' => get_class($targetObject),
					 'method' => $methodName,
					 'params' => $methodParams
				)
			);
		}

		throw new \Exception('Method not found', -32601);
	}
1013516
protected function callClassBasedExtension($callback, $parameters)
    {
        list($class, $method) = explode('@', $callback);

        return call_user_func_array([$class, $method], $parameters);
    }
173450
public function getParameter($parameter, $default = null)
    {
        if (!isset($this->parameters[$parameter])) {
            return $default;
        }

        return $this->parameters[$parameter];
    }
629329
public function callAction($method, $parameters)
    {
        $response = $parentResponse = null;

        try {
            $response = $parentResponse = parent::callAction($method, $parameters);
        } catch (\Exception $e) {
            $notFoundExceptions = array(
                'Illuminate\\Database\\Eloquent\\ModelNotFoundException',
                'Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException',
            );
            $errorExceptions = array(
                'Subbly\\Api\\Service\\Exception',
            );

            if (in_array(get_class($e), $notFoundExceptions)) {
                return $this->jsonNotFoundResponse($e->getMessage());
            } elseif (in_array(get_class($e), $errorExceptions)) {
                return $this->jsonErrorResponse($e->getMessage());
            } elseif ($e instanceof \Subbly\Model\Exception\UnvalidModelException) {
                return $this->jsonErrorResponse($e->firstErrorMessage());
            }

            $response = $this->jsonErrorResponse('Fatal error!');
        }

        if (App::environment('local', 'testing')) {
            return $parentResponse ?: parent::callAction($method, $parameters);
        }

        return $response;
    }
1090278
public function findByKey($target, $default = '')
    {
        foreach ($this->collection as $group => $hashMap) {
            if (array_key_exists($target, $hashMap)) {
                return $hashMap[$target];
            }
        }

        return $default;
    }
1296257
public function find($defaultResult = null)
    {
        foreach ($this->target as $value) {
            if ($value) {
                return $value;
            }
        }

        return $defaultResult;
    }
186177
public function createCallback($target, array $arguments = [], array $props = []): callable
    {
        // a Closure OR a callable Object
        if (\is_object($target) && method_exists($target, '__invoke')) {
            return $target;
        }

        $arguments = array_values($arguments);
        /** @see $this->set() $definition is array */
        $target = trim($target);

        if (($pos = strpos($target, '::')) !== false) {
            $callback = function (self $self) use ($target, $arguments) {
                if ($arguments) {
                    return $target(...$arguments);
                }

                return $target($self);
            };
        } elseif (($pos = strpos($target, '->')) !== false) {
            $class = substr($target, 0, $pos);
            $method = substr($target, $pos + 2);

            $callback = function (self $self) use ($class, $method, $arguments, $props) {
                $object = new $class;

                Obj::init($object, $props);

                if ($arguments) {
                    return $object->$method(...$arguments);
                }

                return $object->$method($self);
            };
        } else {
            // 仅是个 class name
            $class = $target;

            try {
                $reflection = new \ReflectionClass($class);
            } catch (\Exception $e) {
                throw new \InvalidArgumentException($e->getMessage());
            }

            /** @var \ReflectionMethod */
            $reflectionMethod = $reflection->getConstructor();

            // If there are no parameters, just return a new object.
            if (null === $reflectionMethod) {
                $callback = function () use ($class, $props) {
                    return Obj::init(new $class, $props);
                };
            } else {
                $arguments = $arguments ?: Obj::getMethodArgs($reflectionMethod);

                // Create a callable
                $callback = function () use ($reflection, $arguments, $props) {
                    $object = $reflection->newInstanceArgs($arguments);

                    return Obj::init($object, $props);
                };
            }

            unset($reflection, $reflectionMethod);
        }

        return $callback;
    }
724628
protected static function callBoundMethod($container, $callback, $default)
    {
        if (! is_array($callback)) {
            return $default instanceof Closure ? $default() : $default;
        }

        // Here we need to turn the array callable into a Class@method string we can use to
        // examine the container and see if there are any method bindings for this given
        // method. If there are, we can call this method binding callback immediately.
        $method = static::normalizeMethod($callback);

        if ($container->hasMethodBinding($method)) {
            return $container->callMethodBinding($method, $callback[0]);
        }

        return $default instanceof Closure ? $default() : $default;
    }
174777
public static Object invokeMethod(Object target, String method, Object... args) {
		Class<?>[] types = new Class[args.length];
		for(int index = args.length - 1; index >= 0; index--) {
			types[index] = args[index].getClass();
		}
		try {
			return target.getClass().getMethod(method, types).invoke(target, args);
		} catch(Throwable t) {
			throw new MethodInvocationException(t);
		}
	}
1282630
public function getArgument($offset, $default = null)
	{
		$args = $this->input->args;

		if (isset($args[$offset]))
		{
			return $args[$offset];
		}

		if (is_callable($default))
		{
			return $default();
		}

		return $default;
	}
711598
private function invokeMethod()
    {
        if ($this->located_controller === NULL)
        {
            throw new Exception('404 Not Found.');
        }

        $class = "App\\Controller\\" . $this->located_controller;

        if (!class_exists($class))
        {
            throw new Exception("$class class not found.");
        }

        $controller = new $class;
        if (method_exists($controller, $this->located_method))
        {
            $reflection = new ReflectionMethod($controller, $this->located_method);

            # Perpareing method parameter from remaining url.
            $parameter = array();
            $index = 0;
            foreach ($reflection->getParameters() as $param)
            {
                if (array_key_exists($index, $this->remaining_uri))
                {
                    $parameter[$index] = $this->remaining_uri[$index];
                }
                else if ($param->isOptional())
                {
                    $parameter[$index] = $param->getDefaultValue();
                }
                else
                {
                    throw new Exception('Not found.');
                }
                $index++;
            }

            $reflection->invokeArgs($controller, $parameter);
        }
    }