2017 © Pedro Peláez
 

library component-util-singleton

The Singleton (and Registry of Singletons a.k.a. Multiton) design pattern as a PHP component.

image

florianwolters/component-util-singleton

The Singleton (and Registry of Singletons a.k.a. Multiton) design pattern as a PHP component.

  • Saturday, October 11, 2014
  • by FlorianWolters
  • Repository
  • 1 Watchers
  • 11 Stars
  • 76,262 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 8 Versions
  • 7 % Grown

The README.md

Component\Util\Singleton

Component\Util\Singleton is a simple-to-use PHP component that provides the Singleton (and Registry of Singletons a.k.a. Multiton) creational design pattern., (*1)

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight Coverage Status, (*2)

Latest Stable Version Total Downloads Monthly Downloads Daily Downloads Latest Unstable Version License, (*3)

Stories in Ready Dependency Status Dependencies Status HHVM Status, (*4)

Table of Contents (ToC)

Introduction

Singleton is a creational design pattern and defined as follows:, (*5)

"Ensure a class only has once instance, and provide a global access point to it.", (*6)

-- E. Gamma, et al. Design Patterns: Elements of Reusable Object-Oriented software. Westford: Addison-Wesley, 1995., (*7)

Component\Util\Singleton contains of two traits:, (*8)

  • The trait [SingletonTrait][53]: A generic implementation of the Singleton creational design pattern.
  • The trait [MultitonTrait][54]: A generic implementation of the Registry of Singletons a.k.a. Multiton creational design pattern.

The generic implementations as traits make this component reusable (see the section Features below)., (*9)

Features

  • Allows to pass parameters to the static Creation Method getInstance(). The parameters are passed to the protected constructor of the class using the component.
  • Allows a number of unlimited classes to use the component.
    • A class which uses the [SingletonTrait][53] (or [MultitonTrait][54]) can still inherit from another class.
    • A class which extends a class using the [SingletonTrait][53] (or [MultitonTrait][54]) is a new Singleton (or Multiton). Therefore the component supports inheritance.
  • Disallows cloning and serializing of a Singleton (or Multiton) instance.
  • Disallows overriding of the methods getInstance(), __clone and __wakeup.
  • Follows the naming conventions for the Singleton design pattern (offers a static Creation Method getInstance()).
  • Artifacts tested with both static and dynamic test procedures:
    • Dynamic component tests (unit and integration tests) implemented with [PHPUnit][41].
    • Static code analysis performed using the following tools:
      • [PHP_CodeSniffer][40]: Style Checker
      • [PHP Mess Detector (PHPMD)][44]: Code Analyzer
      • [PHP Depend][45]: Code Metrics
      • [phpcpd][42]: Copy/Paste Detector (CPD)
      • [phpdcd][43]: Dead Code Detector (DCD)
      • [SensioLabs Security Checker][47]: Security Checker
    • Continuous Integration (CI) using the following web services:
  • Provides a Packagist package which can be installed using the dependency manager Composer. Click [here][51] for the package on Packagist.
  • Provides a complete Application Programming Interface (API) documentation generated with the documentation generator [Sami][46]. Click [here][52] for the API documentation.
  • Follows the following "standards" from the PHP Framework Interoperability Group (FIG). PSR stands for PHP Standards Recommendation:, (*10)

    • PSR-0: Autoloading Standards, (*11)

      Aims to provide a standard file, class and namespace convention to allow plug-and-play code., (*12)

    • PSR-1: Basic Coding Standard, (*13)

      Aims to ensure a high level of technical interoperability between shared PHP code., (*14)

    • PSR-2: Coding Style Guide, (*15)

      Provides a Coding Style Guide for projects looking to standardize their code., (*16)

    • PSR-4: Autoloader, (*17)

      A more modern take on autoloading reflecting advances in the ecosystem., (*18)

  • Follows the Semantic Versioning (SemVer) specification version 2.0.0.

Requirements

Production

  • PHP >= 5.4
  • Composer
  • [florianwolters/component-util-reflection][56]
  • [florianwolters/component-core-stringutils][57]

Development

  • [PHPUnit][41]
  • [phpcpd][42]
  • [phpdcd][43]
  • [PHP_CodeSniffer][40]
  • [PHP Mess Detector (PHPMD)][44]
  • [Sami][46]
  • [SensioLabs Security Checker][47]
  • [php-coveralls][48]

Installation

Component\Util\Singleton should be installed using the dependency manager Composer., (*19)

Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you., (*20)

The Composer installer can be downloaded with php., (*21)

php -r "readfile('https://getcomposer.org/installer');" | php

This will just check a few PHP settings and then download composer.phar to your working directory. This file is the Composer binary. It is a PHAR , which is an archive format for PHP which can be run on the command line, amongst other things., (*22)

To resolve and download dependencies, run the install command:, (*23)

php composer.phar install

If you are creating a component that relies on Component\Util\Singleton, please make sure that you add Component\Util\Singleton to your component's composer.json file:, (*24)

{
    "require": {
        "florianwolters/component-util-singleton": "0.3.*"
    }
}

Usage

The best documentation for Component\Util\Singleton are the unit tests, which are shipped in the package., (*25)

Additional documentation can be found in the [official Wiki][55] of the project., (*26)

Testing

phpunit

Contributing

Please see CONTRIBUTING for details., (*27)

Credits

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version., (*28)

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details., (*29)

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see https://gnu.org/licenses/lgpl.txt., (*30)

The Versions

29/06 2013

v0.3.2

0.3.2.0 http://github.com/FlorianWolters/PHP-Component-Util-Singleton

The Singleton (and Registry of Singletons a.k.a. Multiton) design pattern as a PHP component.

  Sources   Download

LGPL-3.0+

The Requires

 

pattern utility singleton creation

19/03 2013

v0.3.1

0.3.1.0 http://github.com/FlorianWolters/PHP-Component-Util-Singleton

The Singleton (and Registry of Singletons a.k.a. Multiton) design pattern as a PHP component.

  Sources   Download

LGPL-3.0+

The Requires

 

pattern utility singleton creation

13/12 2012

v0.3.0

0.3.0.0 http://github.com/FlorianWolters/PHP-Component-Util-Singleton

The Singleton (and Registry of Singletons a.k.a. Multiton) design pattern as a simple-to-use component.

  Sources   Download

LGPL-3.0+

The Requires

  • php >=5.4

 

pattern utility singleton creation

06/09 2012

v0.2.2

0.2.2.0 http://github.com/FlorianWolters/PHP-Component-Util-Singleton

The Singleton design pattern as a simple-to-use PHP component.

  Sources   Download

LGPL-3.0+

The Requires

  • php >=5.3.0

 

pattern utility singleton global creation

02/07 2012

v0.2.1

0.2.1.0 http://github.com/FlorianWolters/PHP-Component-Util-Singleton

The Singleton design pattern as a simple-to-use PHP component.

  Sources   Download

LGPL-3.0+

The Requires

  • php >=5.4.0

 

pattern utility singleton

01/07 2012

v0.2.0

0.2.0.0 http://github.com/FlorianWolters/PHP-Component-Util-Singleton

The Singleton design pattern as a simple-to-use PHP component.

  Sources   Download

LGPL-3.0+

The Requires

  • php >=5.4.0

 

pattern utility singleton

01/07 2012

v0.1.0

0.1.0.0 http://github.com/FlorianWolters/PHP-Component-Util-Singleton

The Singleton design pattern as a simple-to-use PHP component.

  Sources   Download

LGPL-3.0+

The Requires

  • php >=5.4.0

 

pattern utility