Skip to content

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

License

Notifications You must be signed in to change notification settings

byjg/php-singleton-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3d2b2cc · Oct 27, 2024

History

39 Commits
Sep 12, 2024
Sep 12, 2024
Jan 9, 2024
Jan 9, 2024
Oct 16, 2022
Nov 7, 2018
Jul 13, 2015
Jan 4, 2024
Jan 4, 2019
Oct 27, 2024
Jul 13, 2015
May 21, 2023
Sep 12, 2024
Jun 10, 2018

Repository files navigation

Singleton Pattern

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

Loading
flowchart TD
    byjg/singleton-pattern

Open source ByJG