web6/singleton
Composer 安装命令:
composer require web6/singleton
包简介
PHP Singleton design pattern
README 文档
README
Implementation of singleton design pattern in PHP5.4+ using a trait.
Install
Install via Composer
$ composer require web6/singleton
Usage
Configure autoload
Configure autoloading by including Composer's generated file :
include_once('vendor/autoload.php');
Create a singleton class
To create a singleton class simply use the W6\Sinfleton\SingletonTrait and move the __construct() logic to the init() method.
class App { use \W6\Singleton\SingletonTrait; public $message = 'Not inited'; protected function init() { $this->message = 'Inited'; } }
Use your class
Anywhere in your application you can request the same instance of the class.
$app = App::instance(); echo $app->message;
统计信息
- 总下载量: 48
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2019-05-19