Reference
http://fabien.potencier.org/article/17/on-php-5-3-lambda-functions-and-closures.

@param Closure $callable
@internal param $callable
@return Closure
327191
public function share(Closure $callable) : Closure
    {
        return function () use ($callable) {
            static $object;
            $c = $this;

            if (is_null($object) && $callable instanceof Closure) {
                $object = $callable($c);
            }

            return $object;
        };
    }
957258
public function execute($callable = null)
    {
        if ($callable && !is_callable($callable)) {
            throw new \InvalidArgumentException('The argument must be a callable object.');
        }

        $exception = null;
        $this->setRunning(true);

        try {
            if ($callable) {
                call_user_func($callable, $this);
            }

            $this->flushPipeline();
        } catch (\Exception $exception) {
            // NOOP
        }

        $this->setRunning(false);

        if ($exception) {
            throw $exception;
        }

        return $this->responses;
    }
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);
    }
1232404
public function traverseFilters(callable $callable)
    {
        foreach ($this->filters() as $expr) {
            /**
             * @param  FilterInterface           $expr The iterated filter expression object.
             * @param  FilterCollectionInterface $this The context of the traversal.
             * @return void
             */
            $callable($expr, $this);
            if ($expr instanceof FilterCollectionInterface) {
                $expr->traverseFilters($callable);
            }
        }

        return $this;
    }
917658
private function getRefParamsFromCallable(callable $callable, $funcName)
    {
        if (is_string($callable)) {
            $ref       = new ReflectionFunction($callable);
            $refParams = $ref->getParameters();
        } elseif (is_array($callable)) {
            $ref       = new ReflectionMethod($callable[0], $callable[1]);
            $refParams = $ref->getParameters();
        } elseif (is_object($callable)) {
            $ref       = new ReflectionMethod($callable, '__invoke');
            $refParams = $ref->getParameters();
        } else {
            throw new MarkupException(sprintf('type of callable function %s() is not supported', $funcName));
        }

        return $refParams;
    }
269268
public static function run( Callable $callable ) {

		try {

			// catch fatal errors
			register_shutdown_function(['\\yolk\\exceptions\\Handler', 'checkFatal']);

			// use our error handler
			$error_handler = set_error_handler(static::$error_handler);

			$args = func_get_args();
			array_shift($args);

			$result = call_user_func_array($callable, $args);

			// restore the original error handler
			// if $error_handler is null then passing it to set_error_handler() will fail on PHP < v5.5
			// so we create an empty error handler thereby causing PHP to run it's own handler.
			set_error_handler($error_handler ?: function() { return false; });

			return $result;

		}
		catch( \Exception $e ) {
			static::exception($e);
		}

	}
713087
private function getReflection(callable $callable): \ReflectionFunctionAbstract
    {
        if (\is_array($callable)) {
            //The callable is checked by PHP in the constructor by the type hiting
            $reflectionClass = new \ReflectionClass($callable[0]);

            return $reflectionClass->getMethod($callable[1]);
        }

        if (\is_object($callable) && !$callable instanceof \Closure) {
            //It's not a closure, so it's mandatory a invokable object (because the callable is valid)
            $reflectionClass = new \ReflectionClass($callable);

            return $reflectionClass->getMethod('__invoke');
        }

        return new \ReflectionFunction($callable);
    }
808195
public function call($key, $callable)
    {
        if (!is_callable($callable)) {
            throw new \InvalidArgumentException('Not a valid callable.');
        }

        if ($this->exists($key)) {
            return $this->get($key);
        }

        $args = func_get_args();
        array_shift($args);
        array_shift($args);

        $value = call_user_func_array($callable, $args);

        $this->set($key, $value);

        return $value;
    }
337790
public function loopThrough(Closure $callable)
    {
        $reference = $this->getReference();

        if (is_null($reference)) {
            $reference = $this->object;
        }

        $this->loop($reference, $callable);
    }
879876
public function getByCallable($callable)
    {
        if(!is_array($callable))
        {
            return null;
        }
        list($object, $methodName) = $callable;
        if($object instanceof IBean)
        {
            $className = get_parent_class($object);
        }
        else
        {
            $className = get_class($object);
        }
        $shortClassName = Imi::getClassShortName($className);
        
        $isClassView = false;
        $view = AnnotationManager::getMethodAnnotations($className, $methodName, View::class)[0] ?? null;
        if(null === $view)
        {
            $view = AnnotationManager::getClassAnnotations($className, View::class)[0] ?? null;
            if(null === $view)
            {
                $view = new View([
                    'template' => File::path($shortClassName, $methodName),
                ]);
            }
            else
            {
                $isClassView = true;
            }
        }

        // baseDir
        if(null === $view->baseDir && !$isClassView)
        {
            $classView = AnnotationManager::getClassAnnotations($className, View::class)[0] ?? null;
            if($classView)
            {
                $view->baseDir = $classView->baseDir;
            }
        }
        return $view;
    }
788521
public function read($table, callable $callable = null)
    {

        $this->connect($table);
        $read = new Read($this);

        return $callable($read);
    }
676048
protected static function share($callable)
    {
        if (!is_object($callable) || !method_exists($callable, '__invoke')) {
            throw new InvalidArgumentException('Service definition is not a Closure or invokable object.');
        }

        return function ($container) use ($callable) {
            static $object;

            if (null === $object) {
                $object = $callable($container);
            }

            return $object;
        };
    }
518924
private function hashCallable($callable)
    {
        $result = '';
        if (is_string($callable)) {
            $result = $callable;
        } else if (is_array($callable)) {
            $callableEntity = array_shift($callable);
            $result = is_object($callableEntity) ? get_class($callableEntity) : serialize($callableEntity);
            $result .= serialize($callable[0]);
        } else if ($callable instanceof \Closure) {
            $serializer = new Serializer();
            return $serializer->serialize($callable);
        } else if (is_object($callable)) {
            $result = serialize($callable);
        }
        return md5($result);
    }
685889
public function setCallable($callable)
    {
        $matches = array();
        if (is_string($callable) && preg_match('!^([^\:]+)\:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$!', $callable, $matches)) {
            $class = $matches[1];
            $method = $matches[2];
            $callable = function() use ($class, $method) {
                static $obj = null;
                if ($obj === null) {
                    $obj = new $class;
                }
                return call_user_func_array(array($obj, $method), func_get_args());
            };
        }

        if (!is_callable($callable)) {
            throw new \InvalidArgumentException('Route callable must be callable');
        }

        $this->callable = $callable;
    }
762743
private function _method($name, callable $callable)
    {
        $lastPattern = array_pop($this->_patterns);
        if ($lastPattern) {
            $methods = $lastPattern[6];//路由方法
            $methods[$name] = $callable;
            $lastPattern[6] = $methods;
            $this->_patterns[] = $lastPattern;
        }
        return $this;
    }
61786
public function callback($callable, $description = null): ValidatorChain
    {
        $rule = Validator::rule('callback', [$callable]);
        if (null !== $description) {
            $rule->setDescription($description);
        }
        $this->addRule($rule);
        return $this;
    }
1123775
protected function parse($callable)
    {
        list($callable, $args) = $this->parseArgs($callable);

        if ($this->isClassMethod($callable)) {
            $callable = $this->parseClassMethod($callable);
        } elseif ($this->isMutatorMethod($callable)) {
            $callable = [$this, $callable];
        } elseif (!function_exists($callable)) {
            throw new InvalidCallableException("Function [{$callable}] not found.");
        }

        return [$callable, $args];
    }