mirror of
https://github.com/openvk/chandler.git
synced 2025-03-29 12:38:12 +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;
|
||||
|
||||
/**
|
||||
* @package Chandler\Patterns
|
||||
*/
|
||||
trait TSimpleSingleton
|
||||
{
|
||||
private static $self = NULL;
|
||||
|
||||
private function __construct() {}
|
||||
private function __clone() {}
|
||||
private function __wakeup() {}
|
||||
|
||||
static function i()
|
||||
/**
|
||||
* @var static
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* @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