byjg/singleton-pattern

A lightweight PHP implementation of the Design Pattern Singleton using trait.

Fund package maintenance!
byjg

Installs: 52 470

Dependents: 2

Suggesters: 0

Security: 0

Stars: 9

Watchers: 3

Forks: 3

Open Issues: 1

pkg:composer/byjg/singleton-pattern

5.0.0 2024-10-27 16:15 UTC

This package is auto-updated.

Last update: 2025-09-23 23:42:37 UTC


README

Build Status Opensource ByJG GitHub source GitHub license GitHub release

A lightweight PHP implementation of the Design Pattern Singleton using trait. Just one class and no dependencies.

Create your class

require "vendor/autoload.php";

class Example
{
    // You need to use the trait here
    use \ByJG\DesignPattern\Singleton;

    // Put your code below
}

REMEMBER: Your class cannot have a public constructor. If it is necessary, use a private or protected constructor instead. Singleton classes does not have arguments in the constructor;

Use your class

$example = Example::getInstance();

Install

composer require "byjg/singleton-pattern"

Run Tests

vendor/bin/phpunit

References

Dependencies

flowchart TD
    byjg/singleton-pattern
Loading

Open source ByJG