PHPackages                             celestriode/dynamic-registry - 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. celestriode/dynamic-registry

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

celestriode/dynamic-registry
============================

Simple, individual registries that are populated on-demand to save on memory.

v3.0.0(4y ago)0313MITPHPPHP ^8.0

Since Oct 16Pushed 4y ago1 watchersCompare

[ Source](https://github.com/celestriode/dynamic-registry)[ Packagist](https://packagist.org/packages/celestriode/dynamic-registry)[ RSS](/packages/celestriode-dynamic-registry/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (3)

Dynamic Registry
================

[](#dynamic-registry)

Create registries that are filled on-demand instead of wasting memory when they are never accessed.

Example
-------

[](#example)

### Extending

[](#extending)

Extend `AbstractRegistry` for each type of registry you want to keep a set of values for.

```
class ItemsRegistry extends AbstractRegistry
{
    public function getName() : string
    {
        return 'items';
    }
}

class EntitiesRegistry extends AbstractRegistry
{
    protected $defaultValues = [1, 2, 3]; // Optional.

    public function getName() : string
    {
        return 'entities';
    }
}
```

Or if you only want strings in the registry, you can extend `AbstractStringRegistry`. When a non-string value is added to such a registry, `InvalidValue` is thrown.

```
class ItemsRegistry extends AbstractStringRegistry
{
    public function getName() : string
    {
        return 'items';
    }
}
```

Or if you want a simple container and have no use for multiple unique registries, create a new `SimpleRegistry` object.

```
$registry = new SimpleRegistry(-1, -2, -3); // Optionally add values upon instantiation.
```

### Usage

[](#usage)

You can either use `new` to create a new object for your registry or obtain a singleton via `get()`.

```
$itemsRegistry = ItemsRegistry::get();
$entitiesRegistry = EntitiesRegistry::get(4, 5, 6); // Optionally add values upon FIRST get() call.
```

Apart from those initially-present values, you can create and register a dynamic populator. A dynamic populator adds values to the registry the first time that the registry has been queried via `has()` or if the registry has been forcibly populated with `populate()`.

```
class ItemsPopulator implements DynamicPopulatorInterface
{
    public function populate(AbstractRegistry $registry) : void
    {
        $registry->addValues('a', 'b', 'c');
    }
}
```

Of course, rather than dynamically populating with hard-coded values, you would instead populate the registry through some other means, such as from a database or via an external API. After registering the populator, once `has()` is called, the registry will be automatically populated and will return true if the value exists.

```
$itemsRegistry->has('a'); // false
$itemsRegistry->register(new ItemsPopulator());
$itemsRegistry->has('a'); // true
```

---

Be warned that attempting to add multiple of the same value will result in `InvalidValue` being thrown. To avoid this consequence and instead cause it to fail silently, override the `failSilently` method.

```
class ItemsRegistry extends AbstractStringRegistry
{
    public function getName() : string
    {
        return 'items';
    }

    public function failSilently(): bool
    {
        return true;
    }
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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 ~22 days

Total

4

Last Release

1606d ago

Major Versions

v1.0.1 → v2.0.02021-12-22

v2.0.0 → v3.0.02021-12-22

PHP version history (2 changes)v1.0.0PHP ^7.3|^8.0

v3.0.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/38850063?v=4)[Celestriode](/maintainers/Celestriode)[@celestriode](https://github.com/celestriode)

---

Top Contributors

[![celestriode](https://avatars.githubusercontent.com/u/38850063?v=4)](https://github.com/celestriode "celestriode (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/celestriode-dynamic-registry/health.svg)

```
[![Health](https://phpackages.com/badges/celestriode-dynamic-registry/health.svg)](https://phpackages.com/packages/celestriode-dynamic-registry)
```

PHPackages © 2026

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