*/ class CallableReflectionFactory { /** * @param callable $callable * * @return \ReflectionFunctionAbstract */ public static function fromCallable($callable) { // Array callable if (is_array($callable)) { list($class, $method) = $callable; return new \ReflectionMethod($class, $method); } // Closure if ($callable instanceof \Closure) { return new \ReflectionFunction($callable); } // 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 return new \ReflectionFunction($callable); } }