mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-25 01:25:34 +08:00
improve SingletonTrait compatibility
This commit is contained in:
@@ -7,5 +7,6 @@ parameters:
|
|||||||
- '#Used constant OS_TYPE_(LINUX|WINDOWS) not found#'
|
- '#Used constant OS_TYPE_(LINUX|WINDOWS) not found#'
|
||||||
- '#Constant .* not found#'
|
- '#Constant .* not found#'
|
||||||
- '#PHPDoc tag @throws with type Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#'
|
- '#PHPDoc tag @throws with type Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#'
|
||||||
|
- '#Unsafe usage of new static#'
|
||||||
dynamicConstantNames:
|
dynamicConstantNames:
|
||||||
- SWOOLE_VERSION
|
- SWOOLE_VERSION
|
||||||
|
|||||||
@@ -1,30 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/** @noinspection PhpUnused */
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace ZM\Utils;
|
namespace ZM\Utils;
|
||||||
|
|
||||||
trait SingletonTrait
|
trait SingletonTrait
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @deprecated 将会于未来版本移除
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
protected static $cached = [];
|
protected static $cached = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var self
|
* @var null|static
|
||||||
*/
|
*/
|
||||||
private static $instance;
|
protected static $instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return self
|
* 获取类实例
|
||||||
* @noinspection PhpMissingReturnTypeInspection
|
*
|
||||||
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function getInstance()
|
public static function getInstance()
|
||||||
{
|
{
|
||||||
if (self::$instance === null) {
|
if (is_null(static::$instance)) {
|
||||||
self::$instance = new self();
|
static::$instance = new static();
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$instance;
|
return static::$instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user