nolikein/singleton

A singleton design pattern

2.0.1 2024-11-19 22:32 UTC

This package is auto-updated.

Last update: 2024-11-19 21:33:28 UTC


README

PHP Packagist version Packagist License Gitlab pipeline status Gitlab Code Coverage

A librairy to use the singleton design pattern. Thanks to the project of domnikl.

Installation

Install and Use Composer:

PHP 8.3

composer require nolikein/singleton ^2.0.0

PHP 8.2 and bellow

composer require nolikein/singleton ^1.1.0

Usage

You can create a singleton from 2 ways.

Extending

use Nolikein\Singleton\SingletonClass;

class MyClass extends SingletonClass {}

Using trait

use Nolikein\Singleton\SingletonTrait;

class MyClass
{
    use SingletonTrait;
}

Finally, you can create an instance:

$instance = MyClass::getInstance();

Testing

Run tests with coverage

displayed as html in tests/Coverage directory

docker compose run --rm php ./vendor/bin/phpunit --configuration phpunit.xml --coverage-text --color
sudo chown $USER:$USER -R tests/Coverage

Licence

The project is under lincence MIT.