byjg / singleton-pattern
使用trait实现的轻量级PHP单例设计模式。
4.9.0
2023-05-21 20:15 UTC
Requires (Dev)
- phpunit/phpunit: 5.7.*|7.4.*|^9.5
README
使用trait实现的轻量级PHP单例设计模式。仅一个类,无依赖。
创建您的类
require "vendor/autoload.php"; class Example { // You need to use the trait here use \ByJG\DesignPattern\Singleton; // Put your code below }
请注意:您的类不能有公共构造函数。如果需要,请使用私有或受保护的构造函数。单例类构造函数中没有参数;
使用您的类
$example = Example::getInstance();
安装
composer require "byjg/singleton-pattern"
运行测试
vendor/bin/phpunit