You are here

trait Singleton in Anti Spam by CleanTalk 8.4

Same name and namespace in other branches
  1. 9.1.x src/lib/Cleantalk/Common/Templates/Singleton.php \Cleantalk\Common\Templates\Singleton

Trait Singleton

@package CleanTalk @Version 1.1.0 @author Cleantalk team (welcome@cleantalk.org) @copyright (C) 2014 CleanTalk team (http://cleantalk.org) @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html

Hierarchy

1 file declares its use of Singleton
SuperGlobalVariables.php in src/lib/Cleantalk/Common/Variables/SuperGlobalVariables.php

File

src/lib/Cleantalk/Common/Templates/Singleton.php, line 15

Namespace

Cleantalk\Common\Templates
View source
trait Singleton {
  public static $instance;
  public function __construct() {
  }
  public function __wakeup() {
  }
  public function __clone() {
  }

  /**
   * Constructor
   * @return $this
   */
  public static function getInstance() {
    $args = func_get_args();
    if (!isset(static::$instance) || !$args) {
      static::$instance = new static();
      if (!empty($args)) {
        static::$instance
          ->init($args);
      }
      else {
        static::$instance
          ->init();
      }
    }
    return static::$instance;
  }

  /**
   * Alternative constructor
   *
   * @param null $args
   */
  protected function init($args = null) {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Singleton::$instance public static property 5
Singleton::getInstance public static function Constructor
Singleton::init protected function Alternative constructor
Singleton::__clone public function
Singleton::__construct public function
Singleton::__wakeup public function