byjg/singleton-pattern

使用trait实现的轻量级PHP单例设计模式。

4.9.0 2023-05-21 20:15 UTC

This package is auto-updated.

Last update: 2024-09-12 02:30:03 UTC


README

Build Status Opensource ByJG GitHub source GitHub license GitHub release

使用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

参考

依赖项

开源ByJG