Skip to content

michaelspiss/singleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Singleton

A trait to implement the Singleton design pattern without any dependencies.

Build Status Coverage Status

Why?

There already are plenty other singleton packages, so why another one? Simply, because most of those packages implement a factory, rather than a singleton pattern. This and many more things bothered me about them, so here is a simple, dependency-free and fully tested singleton.

Installation

$ composer require michaelspiss/singleton

Basic Usage

One line is enough to turn a class into a singleton:

<?php

class StorageProvider {
    
    use MichaelSpiss\DesignPatterns\Singleton;
    
    ...
}

To retrieve the singleton instance, simply call

$singleton = StorageProvider::getInstance();

Read more

There really isn't much left to say, but if you want to know more about constructors for singletons or forbidden actions you should check out the wiki!

PHP Requirements

  • PHP >= 5.4

License

MIT

About

A trait to implement the singleton design pattern without any dependencies.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages