https://github.com/piotrpress/singleton
This library is a Singleton (anti)pattern implementation using a Traits with a support for an Object Inheritance and passing parameters to the constructor.
https://github.com/piotrpress/singleton
antipattern inheritance object-inheritance pattern singleton singleton-pattern singletonpattern singletons trait traits
Last synced: 5 months ago
JSON representation
This library is a Singleton (anti)pattern implementation using a Traits with a support for an Object Inheritance and passing parameters to the constructor.
- Host: GitHub
- URL: https://github.com/piotrpress/singleton
- Owner: PiotrPress
- License: gpl-3.0
- Created: 2021-11-13T15:31:41.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-15T20:35:54.000Z (over 1 year ago)
- Last Synced: 2025-08-13T03:57:34.626Z (5 months ago)
- Topics: antipattern, inheritance, object-inheritance, pattern, singleton, singleton-pattern, singletonpattern, singletons, trait, traits
- Language: PHP
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# Singleton
This library is a [Singleton](https://en.wikipedia.org/wiki/Singleton_pattern) (anti)pattern implementation using a [Traits](https://www.php.net/manual/en/language.oop5.traits.php) with a support for an [Object Inheritance](https://www.php.net/manual/en/language.oop5.inheritance.php) and passing parameters to the constructor.
## Installation
```console
composer require piotrpress/singleton
```
## Usage
```php
require __DIR__ . '/vendor/autoload.php';
use PiotrPress\Singleton;
class ExampleParent {
use Singleton;
}
class Example extends ExampleParent {
protected function __construct( $arg ) {}
}
Example::getInstance( 'arg' );
```
## Requirements
PHP >= `7.4` version.
## License
[GPL3.0](license.txt)