2017 © Pedro PelĂĄez
 

library suda

Registry of values and dependency injector

image

guide42/suda

Registry of values and dependency injector

  • Thursday, October 19, 2017
  • by joksnet
  • Repository
  • 1 Watchers
  • 3 Stars
  • 54 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 14 Versions
  • 0 % Grown

The README.md

SUDA

Suda is a lightweight container for your services., (*1)

Quick Start

Creating and configuring the registry is as simple as giving an associative array that map a class to a factory or a key to a parameter value., (*2)

$di = new suda\Registry([
    MovieFinder::class => function(callable $make) {
        return new MovieFinder;
    },
    MovieLister::class => function(callable $make, MovieFinder $finder) {
        return new MovieLister($finder);
    },
]);

All objects are created once, when first requested, using the factory, and the same instance will be returned at each lookup., (*3)

$finder0 = $di[MovieFinder::class];
$finder1 = $di[MovieFinder::class];

assert($finder0 === $finder1);

Factories

Any callable that accepts a make function as first argument is a factory, any other arguments are resolved as dependencies. It purpose is to create the object when the class or interface is requested., (*4)

Factories can be stacked and called in a middleware fashion. The given make function when called without arguments will:, (*5)

  • Calls the previous factory if stacked,
  • Or tries to create the object of the concrete class key, resolving its dependencies.
$di[ConcreteHouse::class] = function(callable $make) {
    $house = $make(); // creates the object resolving dependencies
    return $house;
};
$di[ConcreteHouse::class] = function(callable $make) {
    $house = $make(); // calls the previous factory
    $house->build();
    return $house;
};

The make function also can be used to create any class with arguments:, (*6)

$di[NumberValidatorInterface::class] = function(callable $make) {
    return $make(BCNumberValidator::class, ['min' => 5]);
};

API

$di = new Registry;                                    // creates empty registry
$di = new Registry(array $values);                     // ... with assoc-array containing values or factories
$di = new Registry(array $values, Registry $delegate); // ... with registry to delegate dependencies

$di[string $classOrInterface] = callable $factory;     // stores a factory for abstract
$di[string $key] = mixed $value;                       // stores a parameter

$di(callable $fn);                                     // call a function resolving it's parameters
$di(callable $fn, array $arguments);                   // ... with given arguments

$di->freeze();                                         // disallow to store values or factories
$di->freeze(string $key);                              // ... for this entry key

Badges

Latest Stable Version Build Status Coverage Status, (*7)

The Versions

19/10 2017

dev-master

9999999-dev

Registry of values and dependency injector

  Sources   Download

ISC

The Requires

 

The Development Requires

by Juan M

dependency injection container di registry

29/06 2017

v0.13.0

0.13.0.0

Registry of values and dependency injector

  Sources   Download

ISC

The Requires

 

The Development Requires

by Juan M

dependency injection container di registry

28/06 2017

v0.12.0

0.12.0.0

PHP Registry

  Sources   Download

ISC

The Requires

 

The Development Requires

by Juan M

dependency injection container di registry

28/06 2017

v0.11.0

0.11.0.0

PHP Registry

  Sources   Download

ISC

The Requires

 

The Development Requires

by Juan M

dependency injection container di registry

27/06 2017

v0.10.0

0.10.0.0

PHP Registry

  Sources   Download

ISC

The Requires

 

The Development Requires

by Juan M

dependency injection container di registry

27/06 2017

v0.9.0

0.9.0.0

PHP Registry

  Sources   Download

ISC

The Requires

 

The Development Requires

by Juan M

dependency injection container di registry

27/06 2017

v0.8.0

0.8.0.0

PHP Registry

  Sources   Download

ISC

The Requires

 

The Development Requires

by Juan M

dependency injection container di registry

27/06 2017

v0.7.0

0.7.0.0

PHP Registry

  Sources   Download

ISC

The Requires

 

The Development Requires

by Juan M

dependency injection container di registry

20/10 2014

v0.6.0

0.6.0.0

PHP Registry

  Sources   Download

ISC

The Requires

 

The Development Requires

dependency injection container di registry

17/10 2014

v0.5.0

0.5.0.0

PHP Registry

  Sources   Download

ISC

The Requires

  • php >=5.3

 

container di registry

15/10 2014

v0.4.0

0.4.0.0

PHP Registry

  Sources   Download

ISC

The Requires

  • php >=5.3

 

container di registry

14/10 2014

v0.3.0

0.3.0.0

PHP Registry

  Sources   Download

ISC

The Requires

  • php >=5.3

 

container di registry

04/10 2014

v0.2.0

0.2.0.0

PHP Registry

  Sources   Download

ISC

The Requires

  • php >=5.3

 

container di registry

03/10 2014

v0.1.0

0.1.0.0

PHP Registry

  Sources   Download

ISC

The Requires

  • php >=5.3

 

container di registry