PHPackages                             lukaszmakuch/class-based-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. lukaszmakuch/class-based-registry

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

lukaszmakuch/class-based-registry
=================================

Registry that allows to associate a value to one ore more classes and then fetch this value by passing objects that implements these classes

v0.0.2(10y ago)03505MITPHP

Since Aug 12Pushed 10y ago1 watchersCompare

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

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

ClassBasedRegistry
==================

[](#classbasedregistry)

Allows to associate a value to one or more classes and then fetch this value by passing objects that implement these classes.

Usage
-----

[](#usage)

### Environment

[](#environment)

Let's assume that we have classes like these:

```
class Animal {}
class Elephant extends Animal {}
class Plant {}
```

To get a new instance of the registry create it:

```
$r = new \lukaszmakuch\ClassBasedRegistry\ClassBasedRegistry();
```

### Simple example

[](#simple-example)

Associate 42 with the Animal class:

```
$r->associateValueWithClasses(
    42,
    [Animal::class]
);
```

Fetch it by providing any animal...

```
$r->fetchValueByObjects([new Animal()]); //42
```

... that may be an elephant!

```
$r->fetchValueByObjects([new Elephant()]); //42
```

### Multiple classes

[](#multiple-classes)

It is possible to associate value with many classes:

```
$r->associateValueWithClasses(
    1970,
    [Animal::class, Plant::class]
);
```

While fetching objects may be passed in any order:

```
$r->fetchValueByObjects([new Plant(), new Elephant()]); //1970
```

### Throwing exceptions

[](#throwing-exceptions)

When it's not possible to obtain any value, then a \\lukaszmakuch\\ClassBasedRegistry\\Exception\\ValueNotFound exception is thrown:

```
try {
    $r->fetchValueByObjects([new Plant()]);
} catch (\lukaszmakuch\ClassBasedRegistry\Exception\ValueNotFound $e) {
  //it was not possible to fetch any value by a plant
}
```

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

[](#installation)

Use [composer](https://getcomposer.org) to get the latest version:

```
$ composer require lukaszmakuch/class-based-registry

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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

Total

2

Last Release

3767d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e08a5c26bd9824a0345f417660e2d1146f044c886266daf2dd0901720fbcf32?d=identicon)[lukaszmakuch](/maintainers/lukaszmakuch)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lukaszmakuch-class-based-registry/health.svg)

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

PHPackages © 2026

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