PHPackages                             afragen/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. afragen/singleton

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

afragen/singleton
=================

A singleton static proxy generator.

1.0.6(1mo ago)74.5k↓28.6%14MITPHPPHP &gt;=5.6.5

Since Nov 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/afragen/singleton)[ Packagist](https://packagist.org/packages/afragen/singleton)[ RSS](/packages/afragen-singleton/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (3)Used By (4)

singleton
=========

[](#singleton)

This is a singleton static proxy generator that I use in several projects instead of creating true Singletons. It was inspired by [Alain Schlesser’s post on Singletons](https://www.alainschlesser.com/singletons-shared-instances/).

I’ve moved this library into it’s own repository so that I will be better able to include it via composer.

I have written it to work with PSR-4.

`composer require afragen/singleton:dev-master`

When using this Singleton class in your project you will create an array of class instances.

Usage
-----

[](#usage)

```
@param string            $class_name Class name.
@param object            $caller     Originating object.
@param null|array|object $options    Options for class constructor.
                                     Optional.

Singleton::get_instance( $class_name, $calling_class, $options );
```

This will usually be called as follows.

`Singleton::get_instance( 'MyClass', $this );`

I do my best to automatically determine the namespace of the class. If the class is in a subfolder of `src` it will need to be designated in the call as follows.

If PSR-4 is set for the `src` directory and the class lives in `src/MySubDir/MyClass` the corresponding call would be as follows.

`Singleton::get_instance( 'MySubDir\MyClass', $this );`

I’m still learning how to properly set up using composer so this may be updated along the way.

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance91

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~549 days

Total

2

Last Release

41d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/82779a185fccde41e1dd3b914bde84cd6be76c8dcb8f6b983f461c8f5687a87e?d=identicon)[afragen](/maintainers/afragen)

---

Top Contributors

[![afragen](https://avatars.githubusercontent.com/u/1296790?v=4)](https://github.com/afragen "afragen (23 commits)")

---

Tags

wordpresssingleton

### Embed Badge

![Health badge](/badges/afragen-singleton/health.svg)

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

###  Alternatives

[aristath/kirki

Extending the WordPress customizer

1.3k73.1k4](/packages/aristath-kirki)[afragen/git-updater

A plugin to automatically update GitHub, Bitbucket, GitLab, or Gitea hosted plugins, themes, and language packs.

3.3k1.7k](/packages/afragen-git-updater)[tacowordpress/tacowordpress

WordPress custom post types that feel like CRUD models

232.2k](/packages/tacowordpress-tacowordpress)

PHPackages © 2026

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