标签:laravel
/** * 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 // 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 * @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 } }
本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1772050
每天laravel-20160804| Container -7
标签:laravel
原文地址:http://jingshanls.blog.51cto.com/3357095/1772050