A lightweight PHP implementation of the Design Pattern Singleton using trait.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json
example.php
phpunit.xml.dist
sonar-project.properties

README.md

Singleton Pattern

Build Status Maintainable Rate Reliability Rate Security Rate Quality Gate Code Coverage Bugs Code Smells Techinical Debt Vulnerabilities

Scrutinizer Code Quality Code Climate

Description

A lightweight PHP implementation of the Design Pattern Singleton using trait. Just one class and no dependencies.

Usage

Create your class

require "vendor/autoload.php";

class Example
{
    // You need to use the trait here
    use \ByJG\DesignPattern\Singleton;

    // Put your code below
}

REMEMBER: Your class cannot have a public constructor. If it is necessary, use a private or protected constructor instead. Singleton classes does not have arguments in the constructor;

Use your class

$example = Example::getInstance();

Install

Just type: composer require "byjg/singleton-pattern=~1.0"

References