首页 > 其他 > 详细

每天laravel-20160817| Container -20

时间:2016-05-30 16:01:52      阅读:167      评论:0      收藏:0      [点我收藏+]
   /**
    * 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


本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1784359

每天laravel-20160817| Container -20

原文:http://jingshanls.blog.51cto.com/3357095/1784359

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!