首页 > 其他 > 详细

每天laravel-20160808| Container -11

时间:2016-05-17 11:46:59      阅读:165      评论:0      收藏:0      [点我收藏+]
/**
    * Bind a new callback to an abstract‘s rebind event.
    *
    * @param  string    $abstract
    * @param  \Closure  $callback
    * @return mixed
    */
   public function rebinding($abstract, Closure $callback)// means binding again
   {
       $this->reboundCallbacks[$this->normalize($abstract)][] = $callback;// set the callback function insert into the array store

       if ($this->bound($abstract)) {// if has bound function set
           return $this->make($abstract);// return the make result to what you want
       }
   }

   /**
    * Refresh an instance on the given target and method.
    *
    * @param  string  $abstract
    * @param  mixed   $target
    * @param  string  $method
    * @return mixed
    */
   public function refresh($abstract, $target, $method)// refresh means to make or fire it again
   {// use the set target and method
       return $this->rebinding($this->normalize($abstract), function ($app, $instance) use ($target, $method) {
           $target->{$method}($instance);
       });// return the rebinding
   }//"function use" type way to import  a closure function.
// that will use a variable out the function,
// the first good place i can see is reduce the parameters

   /**
    * Fire the "rebound" callbacks for the given abstract type.
    *
    * @param  string  $abstract
    * @return void
    */
   protected function rebound($abstract)// start to run the rebound callbacks for the given abstract type
   {
       $instance = $this->make($abstract);// the make function is the get the instance of the ab

       foreach ($this->getReboundCallbacks($abstract) as $callback) {//loop the abstract to call it
           call_user_func($callback, $this, $instance);// call user function
       }
   }


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

每天laravel-20160808| Container -11

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

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