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 static $instance;
private function __construct() {} /**
private function __clone() {} * @return static
private function __wakeup() {} */
public static function i(): self
static function i()
{ {
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() {}
}