您的位置:首页 > 编程语言 > PHP开发

每天laravel-20160805| Container -8

2016-05-12 09:37 525 查看
/**
* 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: