2017 © Pedro Peláez
 

library container

Container wrapper for Auryn dependency injector

image

northwoods/container

Container wrapper for Auryn dependency injector

  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 16 Versions
  • 17 % Grown

The README.md

Northwoods Container

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

Auryn is awesome, so why not use it as a container when packages require it?, (*2)

Note: This goes completely against the philosophy of not using Auryn as a service locator. This package is only meant to be a pragmatic solution for Auryn users that want to use a package that requires a service locator., (*3)

Attempts to be PSR-1, PSR-2, PSR-4, and PSR-11 compliant., (*4)

Install

composer require northwoods/container

Usage

use Auryn\Injector;
use Northwoods\Container\InjectorContainer;
use Psr\Container\ContainerInterface;

// Make an Injector and configure it.
$injector = new Injector();

// Optional: Declare a single container instance.
$injector->share(ContainerInterface::class);

// Use InjectorContainer as the implementation of ContainerInterface.
$injector->alias(ContainerInterface::class, InjectorContainer::class);

// InjectorContainer will wrap this Injector instance.
$injector->define(InjectorContainer::class, [':injector' => $injector]);

Configuration

This package provides a InjectorBuilder that can be used to configure Auryn using separate classes. The builder takes a list of configuration objects and applies each of them to the injector., (*5)

use Northwoods\Container\Config\ContainerConfig;
use Northwoods\Container\InjectorBuilder;

$builder = new InjectorBuilder([
    new ContainerConfig(),
]);

If you prefer to have the injector instantiate the configuration classes, use the LazyInjectorBuilder:, (*6)

use Northwoods\Container\Config\ContainerConfig;
use Northwoods\Container\LazyInjectorBuilder;

$builder = new LazyInjectorBuilder([
    ContainerConfig::class,
]);

The builder can then be used to create an Injector instance:, (*7)

$injector = $builder->build();
$container = $injector->make(ContainerInterface::class);

Note: An existing instance of Auryn can also be provided to the build() method., (*8)

Zend Service Manager Compatibility

This package is compatible with Zend Expressive Container Config:, (*9)

use Northwoods\Container\Zend\Config;
use Northwoods\Container\Zend\ContainerFactory;

$factory = new ContainerFactory();

$container = $factory(new Config(
    require 'path/to/services.php',
));

Note: All injections configured this way will be shared!, (*10)

An existing Injector can also be passed into ContainerFactory:, (*11)

$factory = new ContainerFactory($injector);

This can be combined with InjectorBuilder or LazyInjectorBuilder to apply configuration such as define() calls., (*12)

Identifiers

PSR-11 does not require the container identifier to be a class name, while Auryn does. The only exception to this rule in Auryn is that a class alias can be anything. These container "service names" must resolve to a class and will need to be aliased., (*13)

For example a package may require a config entry in the container that is meant to resolve to an array. This can be achieved by creating a delegate that creates an instance of ArrayObject:, (*14)

use ArrayObject;
use Auryn\Injector;
use Northwoods\Container\InjectorContainer;

// Share a global "config" array as an object
$injector->share('config')->delegate('config', function () {
    return new ArrayObject(require 'path/to/config.php');
});

// Create the container
$container = new InjectorContainer($injector);

Now whenever $container->get('config') is called the ArrayObject will be returned., (*15)

Examples

Additional examples are available in the examples/ directory., (*16)

License

MIT, (*17)

The Versions

06/07 2018

dev-switch-to-phpstan

dev-switch-to-phpstan

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

container psr-11 auyrn

06/07 2018

dev-fix/lazy-construction

dev-fix/lazy-construction

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

container psr-11 auyrn

09/05 2018

3.1.0

3.1.0.0

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

container psr-11 auyrn

09/05 2018

dev-feature/zend-factory-injector

dev-feature/zend-factory-injector

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

container psr-11 auyrn

13/04 2018

3.0.0

3.0.0.0

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

container psr-11 auyrn

12/04 2018

dev-feature/zend-container-test

dev-feature/zend-container-test

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

container psr-11 auyrn

19/12 2017

2.1.0

2.1.0.0

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

19/12 2017

2.0.0

2.0.0.0

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

19/12 2017

1.2.1

1.2.1.0

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

22/07 2017

1.2.0

1.2.0.0

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

06/06 2017

1.1.0

1.1.0.0

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

05/06 2017

1.0.2

1.0.2.0

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

04/06 2017

1.0.1

1.0.1.0

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires

04/06 2017

1.0.0

1.0.0.0

Container wrapper for Auryn dependency injector

  Sources   Download

MIT

The Requires

 

The Development Requires