codememory / singleton
Codememory pattern Singleton
Installs: 54
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:libary
Requires
- php: >=8.0
Requires (Dev)
- symfony/var-dumper: ^5.3
This package is auto-updated.
Last update: 2024-11-29 06:29:53 UTC
README
Установка
composer require codememory/singleton
Использование
<?php use Codememory\Patterns\Singleton\SingletonTrait; require_once 'vendor/autoload.php'; // Создаем класс, который будет использовать singleton class ClassWithSingleton { // Подключаем singleton и можно использовать use SingletonTrait; private int $number = 0; public function setNumber(int $number): void { $this->number = $number; } public function getNumber(): int { return $this->number; } } ClassWithSingleton::getInstance()->setNumber(10); echo ClassWithSingleton::getInstance()->getNumber(); // 10