okapi/singleton
最新稳定版本:1.0.3
Composer 安装命令:
composer require okapi/singleton
包简介
PHP Singleton is a PHP library that allows you to create singleton classes with a trait.
关键字:
README 文档
README
PHP Singleton
PHP Singleton is a PHP library that allows you to create singleton classes with a trait.
Installation
composer require okapi/singleton
Usage
<?php use Okapi\Singleton\Singleton; class GovernmentOfUSA { // Add the singleton trait use Singleton; /** * Function to register the singleton. * * This function and the "initialized" methods are completely optional. * * Can be static or non-static. */ public static function register(): void { // Get instance $instance = self::getInstance(); // For non-static just use $this // Make sure the instance is only registered once $instance->ensureNotInitialized(); // Do something // ... // Mark the instance as initialized $instance->setInitialized(); } /** * Custom function */ public function takeOverTheWorld(): void { // Make sure the instance is initialized $this->ensureInitialized(); // Do something // ... } } // Other file // Register the singleton GovernmentOfUSA::register(); // Take over the world $instance = GovernmentOfUSA::getInstance(); $instance->takeOverTheWorld(); // or GovernmentOfUSA::getInstance()->takeOverTheWorld();
Testing
- Run
composer run-script test
or - Run
composer run-script test-coverage
Show your support
Give a ⭐ if this project helped you!
📝 License
Copyright © 2023 Valentin Wotschel.
This project is MIT licensed.
统计信息
- 总下载量: 9.78k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-17