hyperf-chat/app/Traits/StaticInstance.php

36 lines
487 B
PHP
Raw Normal View History

2021-05-21 22:56:42 +08:00
<?php
namespace App\Traits;
/**
* Trait StaticInstance
*
* @package App\Traits
*/
trait StaticInstance
{
private static $instance;
2021-07-09 22:57:19 +08:00
private function __construct()
{
}
2021-05-21 22:56:42 +08:00
/**
* 获取单例
*
* @return static
*/
2021-08-09 22:15:17 +08:00
public static function getInstance()
2021-05-21 22:56:42 +08:00
{
2021-05-30 18:03:44 +08:00
if (is_null(static::$instance)) {
2021-06-04 19:55:20 +08:00
static::$instance = new static();
2021-05-21 22:56:42 +08:00
}
2021-05-30 18:03:44 +08:00
return static::$instance;
2021-05-21 22:56:42 +08:00
}
2021-06-29 17:30:43 +08:00
2021-07-08 22:28:51 +08:00
private function __clone()
2021-06-29 17:30:43 +08:00
{
}
2021-05-21 22:56:42 +08:00
}