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.5(1y ago)74.3k↓16.7%14MITPHPPHP &gt;=5.6.5

Since Nov 19Pushed 12mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)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

32

—

LowBetter than 72% of packages

Maintenance44

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity33

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

Unknown

Total

1

Last Release

545d 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 (22 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

[tgmpa/tgm-plugin-activation

TGM Plugin Activation is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins).

1.8k222.5k13](/packages/tgmpa-tgm-plugin-activation)[aristath/kirki

Extending the WordPress customizer

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

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

3.3k1.6k](/packages/afragen-git-updater)[justintadlock/hybrid-carbon

God-like post featured image script.

202.5k](/packages/justintadlock-hybrid-carbon)

PHPackages © 2026

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