Invoker\Reflection\CallableReflection::create PHP Метод

create() публичный статический Метод

public static create ( callable $callable ) : ReflectionFunctionAbstract
$callable callable
Результат ReflectionFunctionAbstract
    public static function create($callable)
    {
        // Closure
        if ($callable instanceof \Closure) {
            return new \ReflectionFunction($callable);
        }
        // Array callable
        if (is_array($callable)) {
            list($class, $method) = $callable;
            if (!method_exists($class, $method)) {
                throw NotCallableException::fromInvalidCallable($callable);
            }
            return new \ReflectionMethod($class, $method);
        }
        // Callable object (i.e. implementing __invoke())
        if (is_object($callable) && method_exists($callable, '__invoke')) {
            return new \ReflectionMethod($callable, '__invoke');
        }
        // Callable class (i.e. implementing __invoke())
        if (is_string($callable) && class_exists($callable) && method_exists($callable, '__invoke')) {
            return new \ReflectionMethod($callable, '__invoke');
        }
        // Standard function
        if (is_string($callable) && function_exists($callable)) {
            return new \ReflectionFunction($callable);
        }
        throw new NotCallableException(sprintf('%s is not a callable', is_string($callable) ? $callable : 'Instance of ' . get_class($callable)));
    }

Usage Example

Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function call($callable, array $parameters = array())
 {
     if ($this->container) {
         $callable = $this->resolveCallableFromContainer($callable);
     }
     $this->assertIsCallable($callable);
     $callableReflection = CallableReflection::create($callable);
     $args = $this->parameterResolver->getParameters($callableReflection, $parameters, array());
     $this->assertMandatoryParametersAreResolved($args, $callableReflection);
     // Sort by array key because invokeArgs ignores numeric keys
     ksort($args);
     if ($callableReflection instanceof \ReflectionFunction) {
         return $callableReflection->invokeArgs($args);
     }
     /** @var \ReflectionMethod $callableReflection */
     if ($callableReflection->isStatic()) {
         // Static method
         $object = null;
     } elseif (is_object($callable)) {
         // Callable object
         $object = $callable;
     } else {
         // Object method
         $object = $callable[0];
     }
     return $callableReflection->invokeArgs($object, $args);
 }
All Usage Examples Of Invoker\Reflection\CallableReflection::create
CallableReflection