2017 © Pedro PelĂĄez
 

library 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

image

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

  • Saturday, January 16, 2016
  • by lukaszmakuch
  • Repository
  • 1 Watchers
  • 0 Stars
  • 244 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

ClassBasedRegistry

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

Usage

Environment

Let's assume that we have classes like these:, (*2)

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

To get a new instance of the registry create it:, (*3)

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

Simple example

Associate 42 with the Animal class:, (*4)

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

Fetch it by providing any animal..., (*5)

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

... that may be an elephant!, (*6)

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

Multiple classes

It is possible to associate value with many classes:, (*7)

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

While fetching objects may be passed in any order:, (*8)

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

Throwing exceptions

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

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

Installation

Use composer to get the latest version:, (*10)

$ composer require lukaszmakuch/class-based-registry

The Versions

16/01 2016

dev-master

9999999-dev

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

  Sources   Download

MIT

The Development Requires

16/01 2016

v0.0.2

0.0.2.0

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

  Sources   Download

MIT

The Development Requires

12/08 2015

v0.0.1

0.0.1.0

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

  Sources   Download

MIT

The Development Requires