How can I autoload singleton's in DooPHP?
I'm new to DooPHP, but it's fr开发者_运维百科eaking awesome so far. I'm just not sure how to autoload my own classes as singletons. Any help would be greatly appreciated.
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();
Save it in the /protected/class folder. And it will be loaded automatically. Otherwise, check DooLoader.
精彩评论