PHPackages                             florianwolters/component-util-singleton - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. florianwolters/component-util-singleton

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

florianwolters/component-util-singleton
=======================================

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

v0.3.2(13y ago)13179.3k↑140.9%[1 issues](https://github.com/FlorianWolters/PHP-Component-Util-Singleton/issues)5LGPL-3.0+PHPPHP &gt;=5.4

Since Jul 1Pushed 11y ago2 watchersCompare

[ Source](https://github.com/FlorianWolters/PHP-Component-Util-Singleton)[ Packagist](https://packagist.org/packages/florianwolters/component-util-singleton)[ Docs](http://github.com/FlorianWolters/PHP-Component-Util-Singleton)[ RSS](/packages/florianwolters-component-util-singleton/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (8)Used By (5)

Component\\Util\\Singleton
==========================

[](#componentutilsingleton)

**Component\\Util\\Singleton** is a simple-to-use [PHP](https://php.net "PHP: Hypertext Preprocessor") component that provides the *Singleton* (and *Registry of Singletons* a.k.a. *Multiton*) creational design pattern.

[![Build Status](https://camo.githubusercontent.com/bd6750a4021d0f70e659e6aec248d983ee07026e79c29cd95b73575348842839/68747470733a2f2f7472617669732d63692e6f72672f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d5574696c2d53696e676c65746f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/FlorianWolters/PHP-Component-Util-Singleton)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/cfef7d9ae17b94db66464b54e3fdbcd4b9d198ade7471f210f640af99cdc5256/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d5574696c2d53696e676c65746f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/FlorianWolters/PHP-Component-Util-Singleton/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/fad375f857f2e5d3d7f311e03f12e2e9c3841795863913478d565b8d181e09ee/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d5574696c2d53696e676c65746f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/FlorianWolters/PHP-Component-Util-Singleton/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/23d0bb990d7d14cfdc0485c70033244a8e5732e9db7f46323b8be1c142315af0/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f65646336323338332d626632372d346533652d626433392d3337633635636362663332392f6d696e692e706e67)](https://insight.sensiolabs.com/projects/edc62383-bf27-4e3e-bd39-37c65ccbf329)[![Coverage Status](https://camo.githubusercontent.com/eeac61e06ce86d1f84d86c8caef30b5422c8286b98aeaa3dea074bf1855dd4be/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d5574696c2d53696e676c65746f6e2e737667)](https://coveralls.io/r/FlorianWolters/PHP-Component-Util-Singleton?branch=master)

[![Latest Stable Version](https://camo.githubusercontent.com/aecb04e6c0c8a9bf79af9bc69d923740c8b0a97f81322bb19d10fc529f0695e0/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d7574696c2d73696e676c65746f6e2f762f737461626c652e706e67)](https://packagist.org/packages/florianwolters/component-util-singleton)[![Total Downloads](https://camo.githubusercontent.com/53d9afe5a81a0e68fffd0a23df4b853e554afafa10a0a921495e0c87b49dd7a1/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d7574696c2d73696e676c65746f6e2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/florianwolters/component-util-singleton)[![Monthly Downloads](https://camo.githubusercontent.com/9157fc7ac360144acc94fa2c0c69e0f392e4e86ece5387662cad1b71f31cc8e1/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d7574696c2d73696e676c65746f6e2f642f6d6f6e74686c792e706e67)](https://packagist.org/packages/florianwolters/component-util-singleton)[![Daily Downloads](https://camo.githubusercontent.com/af0d4418c4bed9ca7de6cc9fedb10a5ffdd58747ee909d4ab44ad540f6e6b8d3/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d7574696c2d73696e676c65746f6e2f642f6461696c792e706e67)](https://packagist.org/packages/florianwolters/component-util-singleton)[![Latest Unstable Version](https://camo.githubusercontent.com/edbd9886f7a0b2dcee3ddb7e8fb87a93509ac35d3bb775980f47e1cf5133423d/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d7574696c2d73696e676c65746f6e2f762f756e737461626c652e706e67)](https://packagist.org/packages/florianwolters/component-util-singleton)[![License](https://camo.githubusercontent.com/1578307aa677921c1999ae2f92f67a3154879e4aa2e7050db71e52b4be10971c/68747470733a2f2f706f7365722e707567782e6f72672f666c6f7269616e776f6c746572732f636f6d706f6e656e742d7574696c2d73696e676c65746f6e2f6c6963656e73652e706e67)](https://packagist.org/packages/florianwolters/component-util-singleton)

[![Stories in Ready](https://camo.githubusercontent.com/b92681f13fd390f91fc72b2c97386a3c5c24dbcdb79830f93301661c010d2ec4/68747470733a2f2f62616467652e776166666c652e696f2f666c6f7269616e776f6c746572732f7068702d636f6d706f6e656e742d7574696c2d73696e676c65746f6e2e706e673f6c6162656c3d7265616479267469746c653d5265616479)](https://waffle.io/florianwolters/php-component-util-singleton)[![Dependency Status](https://camo.githubusercontent.com/4ace99abd2894f0f7399daf7b70981457807c35c2f0bb561ef31d6a1712e1622/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3531633333306638353836326334303030323030303533652f62616467652e737667)](https://www.versioneye.com/user/projects/51c330f85862c4000200053e)[![Dependencies Status](https://camo.githubusercontent.com/ee5e9e2a0eec259cd9b541ab10bfedc4dc42a127e0015be87b00e1b207b9d57c/68747470733a2f2f646570656e64696e672e696e2f466c6f7269616e576f6c746572732f5048502d436f6d706f6e656e742d5574696c2d53696e676c65746f6e2e706e67)](http://depending.in/FlorianWolters/PHP-Component-Util-Singleton)[![HHVM Status](https://camo.githubusercontent.com/1a40e4bf358db70189b7c17ec8c406a2eb7f1060bf3bd6ee53ab4ae885ba3be9/687474703a2f2f6868766d2e683463632e64652f62616467652f666c6f7269616e776f6c746572732f636f6d706f6e656e742d7574696c2d73696e676c65746f6e2e706e67)](http://hhvm.h4cc.de/package/florianwolters/component-util-singleton)

Table of Contents (ToC)
-----------------------

[](#table-of-contents-toc)

- [Introduction](#introduction)
- [Features](#features)
- [Requirements](#requirements)
- [Usage](#usage)
- [Installation](#installation)
- [Testing](#testing)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

Introduction
------------

[](#introduction)

*Singleton* is a *creational* design pattern and defined as follows:

> "Ensure a class only has once instance, and provide a global access point to it."

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

**Component\\Util\\Singleton** contains of two traits:

- The trait [`SingletonTrait`](src/php/FlorianWolters/Component/Util/Singleton/SingletonTrait.php "FlorianWolters\Component\Util\Singleton\SingletonTrait"): A generic implementation of the *Singleton*creational design pattern.
- The trait [`MultitonTrait`](src/php/FlorianWolters/Component/Util/Singleton/MultitonTrait.php "FlorianWolters\Component\Util\Singleton\MultitonTrait"): 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](#features) below).

Features
--------

[](#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`](src/php/FlorianWolters/Component/Util/Singleton/SingletonTrait.php "FlorianWolters\Component\Util\Singleton\SingletonTrait") (or [`MultitonTrait`](src/php/FlorianWolters/Component/Util/Singleton/MultitonTrait.php "FlorianWolters\Component\Util\Singleton\MultitonTrait")) can still inherit from another class.
    - A class which extends a class using the [`SingletonTrait`](src/php/FlorianWolters/Component/Util/Singleton/SingletonTrait.php "FlorianWolters\Component\Util\Singleton\SingletonTrait") (or [`MultitonTrait`](src/php/FlorianWolters/Component/Util/Singleton/MultitonTrait.php "FlorianWolters\Component\Util\Singleton\MultitonTrait")) 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](https://phpunit.de "PHPUnit").
    - Static code analysis performed using the following tools:
        - [PHP\_CodeSniffer](https://pear.php.net/package/PHP_CodeSniffer "PHP_CodeSniffer"): Style Checker
        - [PHP Mess Detector (PHPMD)](http://phpmd.org "PHPMD - PHP Mess Detector"): Code Analyzer
        - [PHP Depend](http://pdepend.org "PHP Depend - Software Metrics for PHP"): Code Metrics
        - [phpcpd](https://github.com/sebastianbergmann/phpcpd "sebastianbergmann/phpcpd · GitHub"): Copy/Paste Detector (CPD)
        - [phpdcd](https://github.com/sebastianbergmann/phpdcd "sebastianbergmann/phpdcd · GitHub"): Dead Code Detector (DCD)
        - [SensioLabs Security Checker](https://github.com/sensiolabs/security-checker "SensioLabs Security Checker"): Security Checker
    - Continuous Integration (CI) using the following web services:
        - [Scrutinizer CI](https://scrutinizer-ci.com "Scrutinizer CI")
        - [SensioLabsInsight](https://insight.sensiolabs.com "SensioLabsInsight")
        - [Coveralls](https://coveralls.io "Coveralls")
        - [VersionEye](https://versioneye.com "VersionEye")
        - [Depending](https://depending.in "Depending")
        - [Waffle](https://waffle.io "Waffle")
- Provides a [Packagist](https://packagist.org "Packagist") package which can be installed using the dependency manager [Composer](https://getcomposer.org "Composer"). Click [here](https://packagist.org/packages/florianwolters/component-util-singleton "florianwolters/component-util-singleton - Packagist") for the package on [Packagist](https://packagist.org "Packagist").
- Provides a complete Application Programming Interface (API) documentation generated with the documentation generator [Sami](https://github.com/fabpot/sami "fabpot/sami · GitHub"). Click [here](http://blog.florianwolters.de/PHP-Component-Util-Singleton "Application Programming Interface (API) documentation") for the API documentation.
- Follows the following "standards" from the [PHP Framework Interoperability Group (FIG)](http://php-fig.org "PHP-FIG — PHP Framework Interop Group"). PSR stands for PHP Standards Recommendation:
    - [PSR-0](http://php-fig.org/psr/psr-0 "PSR-0 requirements for autoloader interoperability"): Autoloading Standards

        > Aims to provide a standard file, class and namespace convention to allow plug-and-play code.
    - [PSR-1](http://php-fig.org/psr/psr-1 "PSR-1 basic coding style guide"): Basic Coding Standard

        > Aims to ensure a high level of technical interoperability between shared PHP code.
    - [PSR-2](http://php-fig.org/psr/psr-2 "PSR-2 coding style guide"): Coding Style Guide

        > Provides a Coding Style Guide for projects looking to standardize their code.
    - [PSR-4](http://php-fig.org/psr/psr-4 "PSR-4: Improved Autoloading"): Autoloader

        > A more modern take on autoloading reflecting advances in the ecosystem.
- Follows the [Semantic Versioning](http://semver.org "Semantic Versioning") (SemVer) specification version 2.0.0.

Requirements
------------

[](#requirements)

### Production

[](#production)

- [PHP](https://php.net "PHP: Hypertext Preprocessor") &gt;= 5.4
- [Composer](https://getcomposer.org "Composer")
- [florianwolters/component-util-reflection](https://github.com/FlorianWolters/PHP-Component-Util-Reflection "FlorianWolters/PHP-Component-Util-Reflection")
- [florianwolters/component-core-stringutils](https://github.com/FlorianWolters/PHP-Component-Core-StringUtils "FlorianWolters/PHP-Component-Core-StringUtils")

### Development

[](#development)

- [PHPUnit](https://phpunit.de "PHPUnit")
- [phpcpd](https://github.com/sebastianbergmann/phpcpd "sebastianbergmann/phpcpd · GitHub")
- [phpdcd](https://github.com/sebastianbergmann/phpdcd "sebastianbergmann/phpdcd · GitHub")
- [PHP\_CodeSniffer](https://pear.php.net/package/PHP_CodeSniffer "PHP_CodeSniffer")
- [PHP Mess Detector (PHPMD)](http://phpmd.org "PHPMD - PHP Mess Detector")
- [Sami](https://github.com/fabpot/sami "fabpot/sami · GitHub")
- [SensioLabs Security Checker](https://github.com/sensiolabs/security-checker "SensioLabs Security Checker")
- [php-coveralls](https://github.com/satooshi/php-coveralls "satooshi/php-coveralls · GitHub")

Installation
------------

[](#installation)

**Component\\Util\\Singleton** should be installed using the dependency manager [Composer](https://getcomposer.org "Composer").

> [Composer](https://getcomposer.org "Composer") is a tool for dependency management in [PHP](https://php.net "PHP: Hypertext Preprocessor"). It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

The [Composer](https://getcomposer.org "Composer") installer can be downloaded with `php`.

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

```

> This will just check a few [PHP](https://php.net "PHP: Hypertext Preprocessor") settings and then download `composer.phar`to your working directory. This file is the [Composer](https://getcomposer.org "Composer") binary. It is a PHAR ([PHP](https://php.net "PHP: Hypertext Preprocessor") archive), which is an archive format for [PHP](https://php.net "PHP: Hypertext Preprocessor") which can be run on the command line, amongst other things.

> To resolve and download dependencies, run the `install` command:

```
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:

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

Usage
-----

[](#usage)

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

Additional documentation can be found in the [official Wiki](/wiki "FlorianWolters/PHP-Component-Util-Singleton Wiki") of the project.

Testing
-------

[](#testing)

```
phpunit

```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Florian Wolters](https://github.com/FlorianWolters "FlorianWolters · GitHub")
- [All Contributors](https://github.com/FlorianWolters/PHP-Component-Util-Singleton/contributors "Contributors to FlorianWolters/PHP-Component-Util-Singleton")

License
-------

[](#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.

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.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see .

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~60 days

Recently: every ~90 days

Total

7

Last Release

4752d ago

PHP version history (3 changes)v0.1.0PHP &gt;=5.4.0

v0.2.2PHP &gt;=5.3.0

v0.3.0PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/75dd7e42d69a87c4a0c68b4f29f5d223eb1f9a3f647abafa72da80d2a06d2442?d=identicon)[FlorianWolters](/maintainers/FlorianWolters)

---

Top Contributors

[![FlorianWolters](https://avatars.githubusercontent.com/u/1318837?v=4)](https://github.com/FlorianWolters "FlorianWolters (75 commits)")[![sammarks](https://avatars.githubusercontent.com/u/424093?v=4)](https://github.com/sammarks "sammarks (1 commits)")

---

Tags

utilitypatternsingletoncreation

### Embed Badge

![Health badge](/badges/florianwolters-component-util-singleton/health.svg)

```
[![Health](https://phpackages.com/badges/florianwolters-component-util-singleton/health.svg)](https://phpackages.com/packages/florianwolters-component-util-singleton)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k430.4M1.7k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.3M192](/packages/danielstjules-stringy)[league/pipeline

A plug and play pipeline implementation.

1.0k17.2M88](/packages/league-pipeline)[phpcsstandards/phpcsutils

A suite of utility functions for use with PHP\_CodeSniffer

6340.1M95](/packages/phpcsstandards-phpcsutils)[zenstruck/callback

Callable wrapper to validate and inject arguments.

5610.3M6](/packages/zenstruck-callback)[statamic/stringy

A string manipulation library with multibyte support, forked from @statamic

245.0M18](/packages/statamic-stringy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
