Return the correct reflection class for the given callable.

@param callable $f
@throws AnnotationException
@return \ReflectionFunction|\ReflectionMethod
359771
public static function getReflection(callable $f)
    {
        if (is_string($f)) {
            if (strpos($f, '::', 1) !== false) {
                return new \ReflectionMethod($f);
            } else {
                return new \ReflectionFunction($f);
            }
        } elseif (is_array($f) && count($f) == 2) {
            return new \ReflectionMethod($f[0], $f[1]);
        } elseif ($f instanceof \Closure) {
            return new \ReflectionFunction($f);
        } elseif (is_object($f) && method_exists($f, '__invoke')) {
            return new \ReflectionMethod($f, '__invoke');
        }
        // if the tests above are exhaustive, we should never hit the next line.
        throw new AnnotationException("Unable to determine callable type.");
    }
920533
public static function call($key, callable $func)
    {
        $trace = debug_backtrace();
        if ($function = $trace[1]["function"]) {
            $key = $function . "_" . $key;
            if ($class = $trace[1]["class"]) {
                $key = str_replace("\\", "_", $class) . "_" . $key;
            }
        }

        if (static::check($key)) {
            return static::get($key);
        }

        $return = $func();

        static::set($key, $return);

        return $return;
    }
199431
private function createReflection(callable $callable)
    {
        if (is_string($callable) && strpos($callable, '::')) {
            $callable = explode('::', $callable);
        }

        if (is_array($callable)) {
            return new ReflectionMethod($callable[0], $callable[1]);
        }

        if (is_object($callable) && method_exists($callable, '__invoke')) {
            return new ReflectionMethod($callable, '__invoke');
        }

        return new ReflectionFunction($callable);
    }
289103
private static function callMapClass(string $function): \ReflectionClass
    {
        if (!isset(self::$functions[$function])) {
            self::$functions[$function] = self::forkCallMapClass(
                    new \ReflectionFunction($function)
            );
        }

        return self::$functions[$function];
    }
1227526
protected function resolveClass(string $concrete)
    {
        $resolved   = $this->resolveArguments($this->arguments);
        $reflection = new ReflectionClass($concrete);

        return $reflection->newInstanceArgs($resolved);
    }
289562
public function andThen(callable $f) {
        if( $this->value !== null ) return $f($this->get());
        if( $this->error !== null ) return $this;
        throw new \LogicException("Value and error cannot both be null");
    }
1064567
public static function fromCallable($callable)
    {
        if (!is_callable($callable))
        {
            throw new \InvalidArgumentException('You must provide a vaild PHP callable.');
        }
        elseif (is_string($callable) && strpos($callable, '::') > 0)
        {
            $callable = explode('::', $callable);
        }

        if (is_array($callable))
        {
            list($class, $method) = $callable;
            $reflection = new \ReflectionMethod($class, $method);
        }
        else
        {
            $reflection = new \ReflectionFunction($callable);
        }

        return new static($reflection);
    }
443175
protected function getCallableParameters(callable $callable)/*# : array */
    {
        // array type
        if (is_array($callable)) {
            $reflector = new \ReflectionClass($callable[0]);
            $method = $reflector->getMethod($callable[1]);

        // object with __invoke() defined
        } elseif ($this->isInvocable($callable)) {
            $reflector = new \ReflectionClass($callable);
            $method = $reflector->getMethod('__invoke');

        // simple function
        } else {
            $method = new \ReflectionFunction($callable);
        }

        return $method->getParameters();
    }
822324
public function guessIdentifier(callable $fn = null)
    {
        static $guesser;
        static $table;
        if (isset($table)) {
            return $table;
        }
        if (isset($fn)) {
            $guesser = $fn;
        }
        if (!isset($guesser)) {
            $guesser = function ($class) {
                $class = preg_replace('@\\\\?Model$@', '', $class);
                return Helper::normalize($class);
            };
        }
        $class = get_class($this);
        if (strpos($class, '@anonymous') !== false) {
            $class = (new ReflectionClass($this))->getParentClass()->name;
        }
        return $guesser($class);
    }
838307
public function map(callable $f) {
        if( $this->value !== null ) return Result::success($f($this->value));
        if( $this->error !== null ) return $this;
        throw new \LogicException("Value and error cannot both be null");
    }
272510
public function map(callable $f) : Result
    {
        $result = new self(array_map($f, $this->errors));
        $result->fatal = $this->fatal;

        return $result;
    }
622941
public static function getKey($callable)
    {
        /** @var string|null $class */
        $class = null;
        /** @var string|null $method */
        $method = null;

        if (is_string($callable)) {
            $method = $callable; // works for 'Cls::method' case as well
        } elseif (is_array($callable)) {
            $class = is_object($callable[0]) ? get_class($callable[0]) : $callable[0];
            $method = $callable[1];
        } elseif (is_object($callable)) {
            if ($callable instanceof \ReflectionFunctionAbstract) {
                if ($callable->isClosure()) {
                    return null;
                }

                $class = $callable instanceof \ReflectionMethod ? $callable->class : null;
                $method = $callable->name;
            } else {
                if ($callable instanceof \Closure) {
                    return null;
                }

                $class = get_class($callable);
                $method = '__invoke';
            }
        }

        return strtolower(($class ? $class . '::' : '') . $method);
    }
943648
public function translate(callable $f)
    {
        list($this->x, $this->y, $this->value) = $f($this->x, $this->y, $this->value);
    }
595886
public static function reflectionFunction($function, $arguments = []) {
        $method = is_array($function);

        if($method) {
            $reflection = new ReflectionMethod($function[0], $function[1]);
        }
        else {
            $reflection = new ReflectionFunction($function);
        }

        $args = self::getReflectionArgs($reflection, $arguments, $missing);

        if($missing) {
            $name = $reflection->getName();
            $parts = [];
            foreach($missing as $key => $name) {
                $parts[] = "'$name' (or '$key')";
            }
            $missing = implode(", ", $parts);
            throw new Exception("Can not call function '$name'. Argument(s) $missing need to be set.");
        }

        return $method ? $reflection->invokeArgs($function[0], $args) : $reflection->invokeArgs($args);
    }
851826
private static function getClass($value)
    {
        if (\is_object($value)) {
            return new \ReflectionObject($value);
        }

        if (!\is_string($value)) {
            throw new \InvalidArgumentException('Mirror expects an object or class');
        } elseif (!\class_exists($value) && !\interface_exists($value) && !\trait_exists($value)) {
            throw new \InvalidArgumentException('Unknown class or function: ' . $value);
        }

        return new \ReflectionClass($value);
    }
1312782
public static function createFromCallable(callable $callback): \ReflectionFunctionAbstract
    {
        if (\is_array($callback)) {
            return new \ReflectionMethod($callback[0], $callback[1]);
        }

        if (\is_object($callback)) {
            return new \ReflectionMethod($callback, '__invoke');
        }

        return new \eflectionFunction($callback);
    }
1231646
public static function fromReflection(\ReflectionFunctionAbstract $reflection, callable $callable)
    {
        if (is_array($callable)) {
            /** @var $reflection \ReflectionMethod */
            $thisObject = is_object($callable[0]) ? $callable[0] : null;
            $scopeType = $reflection->getDeclaringClass()->getName();
        } elseif (is_object($callable) && !($callable instanceof \Closure)) {
            /** @var $reflection \ReflectionMethod */
            $thisObject = $callable;
            $scopeType = $reflection->getDeclaringClass()->getName();
        } elseif ($reflection->isClosure()) {
            $thisObject = $reflection->getClosureThis();
            $scopeClass = $reflection->getClosureScopeClass();
            $scopeType = $scopeClass === null ? null : $scopeClass->getName();
        } else {
            $thisObject = null;
            $scopeType = null;
        }
        $variableTable = $reflection->getStaticVariables();

        return new self($thisObject, $scopeType, $variableTable);
    }