Refactoring the TSimpleSingleton class.

This commit is contained in:
Ilya Bakhlin 2021-12-28 22:01:01 +01:00
parent 7cfedf6eff
commit 1f789219d9

View file

@ -1,16 +1,30 @@
<?php declare(strict_types=1); <?php
declare(strict_types = 1);
namespace Chandler\Patterns; namespace Chandler\Patterns;
/**
* @package Chandler\Patterns
*/
trait TSimpleSingleton trait TSimpleSingleton
{ {
private static $self = NULL; /**
* @var static
private function __construct() {} */
private function __clone() {} private static $instance;
private function __wakeup() {}
/**
static function i() * @return static
*/
public static function i(): self
{ {
return static::$self ?? static::$self = new static; if (is_null(static::$instance)) {
return static::$instance = new static();
} else {
return static::$instance;
}
} }
private final function __construct() {}
} }