Singleton
Categories
Component ID
2915571
Component name
Singleton
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Downloads
214
Component created
Component changed
Component body
Description
This module utilizes the Singleton design pattern inspired by petrknap/php-singleton
PHP library through composer. This module is only an API to allow you to utilize singletons
for classes you create and does not provide any UI or CLI.
How to use
In your PHP class
namespace Drupalmy_module;
use DrupalsingletonSingletonSingletonInterface;
use DrupalsingletonSingletonSingletonTrait;
/**
* Implementation of Singleton design pattern.
*/
class ExampleSingletonClass implements SingletonInterface {
use SingletonTrait;
public function foo() {
return t('bar');
}
}
When you implement this singleton, it would look something like this:
$my_instance = Drupalmy_moduleExampleSingletonClass::getInstance();