mirror of
https://github.com/openvk/chandler.git
synced 2025-03-31 21:43:59 +03:00
Refactoring the TSimpleSingleton class.
This commit is contained in:
parent
7cfedf6eff
commit
1f789219d9
1 changed files with 23 additions and 9 deletions
|
@ -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() {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue