Container.php 中的属性 protected $name好像没用?

浏览:86 发布日期:2019/09/06 分类:ThinkPHP5专区 关键字: TP5 TP6 容器
源代码是:    public function make($abstract, $vars = [], $newInstance = false)
    {
        if (true === $vars) {
            // 总是创建新的实例化对象
            $newInstance = true;
            $vars        = [];
        }

        $abstract = isset($this->name[$abstract]) ? $this->name[$abstract] : $abstract;

        if (isset($this->instances[$abstract]) && !$newInstance) {
            return $this->instances[$abstract];
        }

        if (isset($this->bind[$abstract])) {
            $concrete = $this->bind[$abstract];

            if ($concrete instanceof Closure) {
                $object = $this->invokeFunction($concrete, $vars);
            } else {
                $this->name[$abstract] = $concrete;
                return $this->make($concrete, $vars, $newInstance);
            }
        } else {
            $object = $this->invokeClass($abstract, $vars);
        }

        if (!$newInstance) {
            $this->instances[$abstract] = $object;
        }

        return $object;
    }
我把源代码的删除 $abstract = isset($this->name[$abstract]) ? $this->name[$abstract] : $abstract;
$this->name[$abstract] = $concrete;
得到下面的代码,且运行正常    public function make($abstract, $vars = [], $newInstance = false)
    {

        if (true === $vars) {
            // 总是创建新的实例化对象
            $newInstance = true;
            $vars        = [];
        }


        if (isset($this->instances[$abstract]) && !$newInstance) {
            return $this->instances[$abstract];
        }
        
        if (isset($this->bind[$abstract])) {
            $concrete = $this->bind[$abstract];

            if ($concrete instanceof Closure) {
                $object = $this->invokeFunction($concrete, $vars);
            } else {

                return $this->make($concrete, $vars, $newInstance);
            }
        } else {

            $object = $this->invokeClass($abstract, $vars);
        }

        if (!$newInstance) {
            $this->instances[$abstract] = $object;
        }

        return $object;
    }
请问 $this->name 这个属性到底有什么用呀?
最佳答案
评论( 相关
后面还有条评论,点击查看>>