景山编程-专注编程

景山编程-专注编程

每天laravel-20160817| Container -20
    /**
     * Register a new resolving callback by type of its first argument.
     *
     * @param  \Closure  $callback
     * @return void
     */
    // Register a new resolving callback by type of its first argument
    protected function resolvingCallback(Closure $callback)
    {
        $abstract = $this->getFunctionHint($callback);// get the abstract function

        if ($abstract) {// if get the abstract function set in
            $this->resolvingCallbacks[$abstract][] = $callback;// one is abstract function
        } else {
            $this->globalResolvingCallbacks[] = $callback;// other set in the global Resolving Call backs
        }
    }

    /**
     * Register a new after resolving callback by type of its first argument.
     *
     * @param  \Closure  $callback
     * @return void
     */
    protected function afterResolvingCallback(Closure $callback)
    {
        $abstract = $this->getFunctionHint($callback);// get the result

        if ($abstract) {
            $this->afterResolvingCallbacks[$abstract][] = $callback;// one is in the abstract
        } else {
            $this->globalAfterResolvingCallbacks[] = $callback;
        }
    }

    /**
     * Get the type hint for this closure's first argument.
     *
     * @param  \Closure  $callback
     * @return mixed
     */
    // hint is type  or a way
    protected function getFunctionHint(Closure $callback)
    {
        $function = new ReflectionFunction($callback);// get the new Reflection Function

        if ($function->getNumberOfParameters() == 0) {
            return;
        }// if $function

        $expected = $function->getParameters()[0];

        if (! $expected->getClass()) {// getClass
            return;
        }

        return $expected->getClass()->name;// get the class name.
    }
    // sorry ,this too easy
阅读更多
版权声明:随便转载了.............. https://blog.csdn.net/lijingshan34/article/details/51535692
个人分类: php
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

每天laravel-20160817| Container -20

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭