标签:laravel
/** * Register an existing instance as shared in the container. * * @param string $abstract * @param mixed $instance * @return void */ public function instance($abstract, $instance)// Register an existing instance as shared in the container. { $abstract = $this->normalize($abstract);// get a normal string. // First, we will extract the alias from the abstract if it is an array so we // are using the correct name when binding the type. If we get an alias it // will be registered with the container so we can resolve it out later. if (is_array($abstract)) {// check it is a array list($abstract, $alias) = $this->extractAlias($abstract);// list the array to the variable. // like extract function $this->alias($abstract, $alias);// set alias by abstract and alias } // First, we will extract the alias from the abstract if it is an array. // so we are using the correct name when binding the type. // if we get an alias it will be registered the container so we can resolve it out later. unset($this->aliases[$abstract]);// un set the aliases by key ,the key is abstract class. // We‘ll check to determine if this type has been bound before, and if it has // we will fire the rebound callbacks registered with the container and it // can be updated with consuming classes that have gotten resolved here. $bound = $this->bound($abstract); // we will check to determine if this type has been bound before, // and if it has we will fire the rebound callbacks registered with the container // and it can be updated with consuming classes that have gotten resolved here. $this->instances[$abstract] = $instance;// set instance if ($bound) { $this->rebound($abstract);// if it is bound ,use the rebound function. } }// last we has a summary // this function has two base action // one is abstract,other is bounding // set the instance and alias
本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1772496
每天laravel-20160805| Container -8
标签:laravel
原文地址:http://jingshanls.blog.51cto.com/3357095/1772496