nolikein / singleton
A singleton design pattern
2.0.1
2024-11-19 22:32 UTC
Requires
- php: ^8.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^9
- romanzipp/php-cs-fixer-config: ^3.3
This package is auto-updated.
Last update: 2024-12-19 21:50:13 UTC
README
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.