function ArgumentsResolver::getReflector

Same name in other branches
  1. 9 core/lib/Drupal/Component/Utility/ArgumentsResolver.php \Drupal\Component\Utility\ArgumentsResolver::getReflector()
  2. 8.9.x core/lib/Drupal/Component/Utility/ArgumentsResolver.php \Drupal\Component\Utility\ArgumentsResolver::getReflector()
  3. 11.x core/lib/Drupal/Component/Utility/ArgumentsResolver.php \Drupal\Component\Utility\ArgumentsResolver::getReflector()

Gets a reflector for the access check callable.

The access checker may be either a procedural function (in which case the callable is the function name) or a method (in which case the callable is an array of the object and method name).

Parameters

callable $callable: The callable (either a function or a method).

Return value

\ReflectionFunctionAbstract The ReflectionMethod or ReflectionFunction to introspect the callable.

File

core/lib/Drupal/Component/Utility/ArgumentsResolver.php, line 121

Class

ArgumentsResolver
Resolves the arguments to pass to a callable.

Namespace

Drupal\Component\Utility

Code

protected function getReflector(callable $callable) {
    if (is_array($callable)) {
        return new \ReflectionMethod($callable[0], $callable[1]);
    }
    if (is_string($callable) && str_contains($callable, "::")) {
        return PHP_VERSION_ID < 80300 ? new \ReflectionMethod($callable) : \ReflectionMethod::createFromMethodName($callable);
    }
    return new \ReflectionFunction($callable);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.