/** * Wrap a Closure such that it is shared. * * @param \Closure $closure * @return \ Closure */ public function share (closure $closure)// because this so we need php version is 5.4+ {// wrap a closure such that is shared return function ($container) use ($closure) { // we ' ll simply declare a static variable within the closures and if it has // not been set we will execute the given closures to resolve this value &nbsP;// and return it back to these consumers of the method as an instance. static $object;// check has, or closure it. if (Is_null ($object)) { $ object = $closure ($container);// use a closure class to bind to the container } return $object; };// a closure class is a special class } /** * "Extend" an abstract type in the container. * * @param string $abstract  &Nbsp;* @param \Closure $closure * @return void * * @throws \invalidargumentexception */ public function extend ( $abstract, closure $closure)// a extend type ,parameter is a abstract class,and other is closure. { $abstract = $this->normalize ($abstract);// get a normal string that we need if (Isset ($this->instances[$abstract]) {// check it is set in the instance array, $this->instances[$abstract] = $closure ($this->instances[$abstract], $this);// if isset ,use the closure function to action about it. $this->rebound ($abstract);// get the rebound function } else { $this->extenders[ $abstract][] = $closure;// set the extender } }
This article is from the "Focus on PHP" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1772050
Daily laravel-20160804| Container-7