How can I autoload singleton's in DooPHP?

553 Views Asked by At

I'm new to DooPHP, but it's freaking awesome so far. I'm just not sure how to autoload my own classes as singletons. Any help would be greatly appreciated.

2

There are 2 best solutions below

0
On BEST ANSWER

Just give your class a singleton method if you want to.

class Test {
    protected static $_instance;

    public static function getInstance() {
        if(self::$_instance===null){
             self::$_instance = new Test();
        }
        return self::$_instance;
    }
}

Use this wherever you want Test::getInstance();

Alternatively, you can create an instance of your class and set it to DooConfig object.

Doo::conf()->test = new Test();
//Or this in common.conf.php
$config['test'] = new Test();
2
On

Save it in the /protected/class folder. And it will be loaded automatically. Otherwise, check DooLoader.