You are here

trait Singleton in Convert Media Tags to Markup 2.x

Same name and namespace in other branches
  1. 8 src/traits/Singleton.php \Drupal\convert_media_tags_to_markup\traits\Singleton

Implements the Singleton design pattern.

Hierarchy

  • trait \Drupal\convert_media_tags_to_markup\traits\Singleton
2 files declare their use of Singleton
App.php in src/ConvertMediaTagsToMarkup/App.php
DbReplacer.php in src/ConvertMediaTagsToMarkup/DbReplacer.php

File

src/traits/Singleton.php, line 8

Namespace

Drupal\convert_media_tags_to_markup\traits
View source
trait Singleton {

  /**
   * Interal instance variable used with the instance() method.
   *
   * @var object
   */
  private static $instance;

  /**
   * Implements the Singleton design pattern.
   *
   * Only one instance of the Concord class should exist per execution.
   *
   * @return Concord
   *   The single instance of the concord class.
   */
  public static function instance() {

    // See http://stackoverflow.com/questions/15443458
    $class = get_called_class();

    // Not sure why the linter tells me $instance is not used.
    // @codingStandardsIgnoreStart
    if (!$class::$instance) {

      // @codingStandardsIgnoreEnd
      $class::$instance = new $class();
    }
    return $class::$instance;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Singleton::$instance private static property Interal instance variable used with the instance() method.
Singleton::instance public static function Implements the Singleton design pattern.