2021-05-21 22:56:42 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Traits;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trait StaticInstance
|
|
|
|
*
|
|
|
|
* @package App\Traits
|
|
|
|
*/
|
|
|
|
trait StaticInstance
|
|
|
|
{
|
|
|
|
private static $instance;
|
|
|
|
|
2021-05-30 18:03:44 +08:00
|
|
|
private function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-21 22:56:42 +08:00
|
|
|
/**
|
|
|
|
* 获取单例
|
|
|
|
*
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
static public function getInstance()
|
|
|
|
{
|
2021-05-30 18:03:44 +08:00
|
|
|
if (is_null(static::$instance)) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
private function __clone()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|