每天laravel-20160805| Container -8

来源:互联网 发布:淘宝 软件 编辑:程序博客网 时间:2024/06/07 10:34
    /**     * 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
0 0
原创粉丝点击