This project is not covered by Drupal’s security advisory policy.


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 Drupal\my_module;

use Drupal\singleton\Singleton\SingletonInterface;
use Drupal\singleton\Singleton\SingletonTrait;

 * 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 = \Drupal\my_module\ExampleSingletonClass::getInstance();


Drupal 7

Project information