You are here

trait SemiSingletonTrait in RESTful 7.2

Class SemiSingletonTrait.

@package Drupal\restful\Plugin

Hierarchy

File

src/Plugin/SemiSingletonTrait.php, line 15
Contains \Drupal\restful\Plugin\SemiSingletonTrait.

Namespace

Drupal\restful\Plugin
View source
trait SemiSingletonTrait {

  /**
   * The already created manager.
   *
   * @var mixed
   */
  protected static $singleton;

  /**
   * Gets the singleton based on the factory callable.
   *
   * @param callable $factory
   *   The factory that creates the actual object.
   * @param array $params
   *   The parameters to be passed to the factory.
   *
   * @return mixed
   *   The singleton object.
   */
  protected static function semiSingletonInstance(callable $factory, array $params = array()) {
    if (!static::$singleton) {
      static::$singleton = call_user_func_array($factory, $params);
    }
    return static::$singleton;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SemiSingletonTrait::$singleton protected static property The already created manager.
SemiSingletonTrait::semiSingletonInstance protected static function Gets the singleton based on the factory callable.