- Direct superclass:\core\WAObject
- Direct known subclasses:\core\WABase
This is the simplest pattern class to extend to create a singleton.
A singleton is a class that can have only one instance through your whole aplication.
When you intend to create a second instance of the class, an error is thrown.
The class has a static method to get or create the unique instance easily without bothering where is the instance:
- getInstance('name_of_class') to get the unique instance of your class.
You should extend all your singletons from the Singleton class.
Be sure you call the constructor of your father class.
class DatabaseConnector extends \patterns\Singleton
... Lots of your code ...
$connector = \patterns\Singleton::getInstance('DatabaseConnector');
... Use your singleton ...
Creates the unique instance.
There is no constant into this class.
There are no attributes into this class.
3.4. Methods:public static getInstance($data)
This method is used to get the instance of the asked class.
If the instance does not exist yet, it will be create.
If the class does not exist, an error is thrown.public static hasInstance($data)
This method returns true if the instance already exists