Skip to content

请教一下,关于单例模式是只有controller下才会有的问题,还是任何一个类都会有这个问题? #441

Open
@euii

Description

@euii

我现在手里有一个旧的系统,我想改造它,系统中有一个Repository目录,这里面几乎所有的类都使用了类似的代码

class GeoCityRepository extends Base
{
    protected $geoCity;

    public function __construct()
    {
        parent::__construct();
        $this->geoCity = new GeoCity;
    }
}

我在常见问题文档中说controller挂在router下,router是单例所以controller里的__construct只走一次,我的疑问是运行在cli模式下是否所有的类都不能用上述形式的代码,还是仅仅是controller里不能使用上述形式的代码?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions