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

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

tlmcclatchey/registry
=====================

A tiny, DI-friendly in-memory registry with per-key locks and a global freeze switch.

v1.0(3mo ago)10MITPHPPHP ^8.4CI passing

Since Feb 15Pushed 3mo agoCompare

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

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Registry
========

[](#registry)

A tiny, dependency-injection-friendly in-memory registry with **per-key locks** and a **global freeze switch**.

Designed as a safer alternative to ad-hoc globals for configuration, runtime state, and bootstrapping data in PHP applications.

---

Features
--------

[](#features)

- Simple in-memory key/value storage
- **Per-key lock flags** to prevent specific mutations
- **Global freeze** to make the registry fully read-only after boot
- Clean interface for DI containers and frameworks
- Zero dependencies, tiny footprint

---

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

[](#installation)

```
composer require tlmcclatchey/registry
```

Requires **PHP 8.4+**.

---

Quick Start
-----------

[](#quick-start)

```
use TLMcClatchey\Registry\MemoryRegistry;

$registry = new MemoryRegistry();

// define keys
$registry->define('config', array: true);
$registry->assign('config', 'env', 'prod');

// set scalar value
$registry->set('debug', false);

// freeze registry after boot
$registry->freeze();

// reads still work
$env = $registry->get('config')['env'];
```

After calling `freeze()`, **all mutation operations throw**.

---

Core Concepts
-------------

[](#core-concepts)

### 1. Keys

[](#1-keys)

A key may contain:

- scalar value (`int|string|bool|float|null`)
- array value (for map/list-style storage)

```
$registry->set('version', '1.0.0');
$registry->define('services', array: true);
```

---

### 2. Assigning Array Values

[](#2-assigning-array-values)

```
$registry->assign('services', 'cache', 'redis');
$registry->assign('services', 'queue', 'sqs');
```

Check existence:

```
$registry->isAssigned('services', 'cache'); // true
```

---

### 3. Lock Flags

[](#3-lock-flags)

Each key can prevent specific mutations.

FlagPrevents`NO_SET`overwriting the whole value`NO_APPEND`appending to arrays`NO_PREPEND`prepending to arrays`NO_ASSIGN`assigning subkeys`NO_UNASSIGN`removing subkeys`NO_CLEAR`removing the key entirelyConvenience presets:

```
RegistryLocks::READONLY
RegistryLocks::READ_MODIFY
```

Example:

```
use TLMcClatchey\Registry\RegistryLocks;

$registry->define('config', lock: RegistryLocks::READONLY, array: true);

// any mutation now throws RegistryException
```

---

### 4. Global Freeze

[](#4-global-freeze)

Freeze the entire registry once bootstrapping is complete:

```
$registry->freeze();
```

After freezing:

- **All mutation methods throw `RegistryException`**
- **Read operations continue working**

Perfect for:

- application boot phases
- compiled container configs
- immutable runtime state

---

API Overview
------------

[](#api-overview)

### Read

[](#read)

```
$registry->get(string $key, mixed $default = null);
$registry->has(string $key);
$registry->all();
$registry->keys();
```

### Write

[](#write)

```
$registry->define(string $key, int $lock = 0, bool $array = false);
$registry->set(string $key, mixed $value, int $lock = 0);
$registry->clear(string $key);
```

### Array Operations

[](#array-operations)

```
$registry->assign(string $key, string $subkey, scalar|null $value);
$registry->unassign(string $key, string $subkey);
$registry->prepend(string $key, scalar|null $value);
$registry->append(string $key, scalar|null $value);
```

### Lifecycle

[](#lifecycle)

```
$registry->freeze();
$registry->isFrozen();
```

---

When to Use This
----------------

[](#when-to-use-this)

Good fit:

- boot configuration storage
- DI container build phase
- runtime feature flags
- small framework kernels
- CLI app state

Not intended for:

- persistence
- cross-request storage
- caching layers
- large datasets

---

Philosophy
----------

[](#philosophy)

This library exists for one reason:

> Sometimes you *do* need global state. You just don’t need **chaos**.

So instead of banning globals, this gives you:

- **rules**
- **immutability after boot**
- **predictable failure**

Like a registry… but with adult supervision.

---

License
-------

[](#license)

See the [LICENSE.md](LICENSE.md) file for full details.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance82

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

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

Unknown

Total

1

Last Release

92d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5991e71fdfcd1bc709602e9d809bded7c12649ba25084cc6f715caf45e2e52c1?d=identicon)[tlmcclatchey](/maintainers/tlmcclatchey)

---

Top Contributors

[![tlmcclatchey](https://avatars.githubusercontent.com/u/112527648?v=4)](https://github.com/tlmcclatchey "tlmcclatchey (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[opensrs/osrs-toolkit-php

OpenSRS PHP Toolkit

7668.6k](/packages/opensrs-osrs-toolkit-php)[magiccart/lookbook

Pin product to banner easy.

1319.7k](/packages/magiccart-lookbook)[dem13n/discussion-cards

Output of discussions in form of cards

164.6k](/packages/dem13n-discussion-cards)[tureki/phpcc

A PHP Library to use Google Closure Compiler compress Javascript

202.7k](/packages/tureki-phpcc)

PHPackages © 2026

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