You are here

Singleton.php in Convert Media Tags to Markup 8

Same filename and directory in other branches
  1. 2.x src/traits/Singleton.php

File

src/traits/Singleton.php
View source
<?php

namespace Drupal\convert_media_tags_to_markup\traits;


/**
 * Implements the Singleton design pattern.
 */
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;
  }

}

Traits

Namesort descending Description
Singleton Implements the Singleton design pattern.