2017 © Pedro Peláez
 

library cairon

Configuration wrapper for auryn dependency injector

image

shadowhand/cairon

Configuration wrapper for auryn dependency injector

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 55 % Grown

The README.md

cairon

Become a Supporter Latest Stable Version License Build Status Code Coverage Scrutinizer Code Quality, (*1)

A tiny wrapper around an auryn that provides configuration capabilities. Attempts to be PSR-1, PSR-2, and PSR-4 compliant., (*2)

Usage

The basic purpose of cairon is to apply callable configurations to auryn., (*3)

This is done using either configure() with a list of callables, or apply() with a single callable., (*4)

use Auryn\Injector;
use Cairon\InjectorConfig;

$injector = InjectorConfig::make()
    ->configure([
        Acme\Injector\Foo::class,
        ['SomeClass::staticMethod']
        function (Injector $injector) { /* ... */ }
        // ...
    ])
    ->apply([$someObject, 'method'])
    ->injector();

Callables

The only requirement for the callable is that it accept an instance of Auryn\Injector as the first and only argument:, (*5)

fn(Injector $injector): void

Note: If the provided configuration is not currently callable, it is assumed to be a class name and will be resolved by calling Injector::make()., (*6)

Best Practice

The preferred approach to using cairon is by creating a closure that is included. This removes the need to create a concrete class for configuration and promotes the idea that auryn is only used in bootstrapping., (*7)

For example, we could create config/injection/psr7.php:, (*8)

use Auryn\Injector;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\ServerRequestFactory;

return function (Injector $injector) {
    $injector->alias(ServerRequestInterface::class, ServerRequest::class);
    $injector->delegate(ServerRequestInterface::class, 'ServerRequestFactory::fromGlobals');
};

And then apply it in our bootstrap:, (*9)

use Cairon\InjectorConfig;

$injector = InjectorConfig::make()
    ->configure([
        require __DIR__ . '/config/injection/psr7.php',
    ])
    ->injector();

Existing Injector

If you already have an instance of Auryn\Injector it can be provided to the constructor:, (*10)

$injector = new Injector();

$config = InjectorConfig::make($injector);

assert($injector === $config->injector());

Inspiration

The theory behind cairon comes from elazar/auryn-configuration. This same theory was also adopted by equip/config. My goal was to simplify the theory into a wrapper that could be used with any callable, without implementing a concrete interface., (*11)

License

MIT., (*12)

The Versions

01/04 2017

dev-master

9999999-dev

Configuration wrapper for auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

01/04 2017

0.1.0

0.1.0.0

Configuration wrapper for auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires