An open API service indexing awesome lists of open source software.

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: about 1 month 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.

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)