2017 © Pedro Peláez
 

library container-overridden

Psr-11 container decorator allowing to override container entries at runtime

image

ellipse/container-overridden

Psr-11 container decorator allowing to override container entries at runtime

  • Friday, February 23, 2018
  • by pmall
  • Repository
  • 1 Watchers
  • 0 Stars
  • 150 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Overridden container

This package provides a Psr-11 container decorator allowing to override container entries at runtime., (*1)

Require php >= 7.0, (*2)

Installation composer require ellipse/container-overridden, (*3)

Run tests ./vendor/bin/kahlan, (*4)

Decorating a container

This package provides a Ellipse\Container\OverriddenContainer class which can be used to decorate any Psr-11 container. It takes an associative array of alias => values pairs as second parameter. Once decorated, the container ->has() method will return true when the given alias is a key of this array and the ->get() method will return its associated value. When the alias is not a key of the array, the original container ->has() and ->get() methods are used., (*5)

It is especially useful when used with ellipse/container-reflection., (*6)

<?php

namespace App;

class SomeClass
{
    public function __construct(SomeOtherClass $class)
    {
        //
    }
}
<?php

namespace App;

use Psr\Http\Message\ServerRequestInterface;

class SomeOtherClass
{
    public function __construct(ServerRequestInterface $request)
    {
        //
    }
}
<?php

use Psr\Http\Message\ServerRequestInterface;

use Some\Psr7ServerRequestFactory;
use Some\Psr11Container;

use Ellipse\Container\ReflectionContainer;
use Ellipse\Container\OverriddenContainer;

use App\SomeClass;

// Get a Psr-7 request from somewhere.
$request = Psr7ServerRequestFactory::fromGlobals();

// Get an instance of some Psr-11 container.
$container = new Psr11Container;

// Decorate the container.
$container = new ReflectionContainer(
    new OverriddenContainer($container, [
        ServerRequestInterface::class => $request,
    ])
);

// Returns an instance of SomeClass with the overridden Psr-7 instance injected in it's
// SomeOtherClass dependency.
$container->get(SomeClass::class);

The Versions

23/02 2018

dev-master

9999999-dev https://github.com/ellipsephp/container-overridden

Psr-11 container decorator allowing to override container entries at runtime

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar pmall

container decorator dependency-injection psr-11

23/02 2018

1.0.1

1.0.1.0 https://github.com/ellipsephp/container-overridden

Psr-11 container decorator allowing to override container entries at runtime

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar pmall

container decorator dependency-injection psr-11

06/12 2017

1.0.0

1.0.0.0 https://github.com/ellipsephp/container-overridden

Psr-11 container decorator allowing to override container entries at runtime

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar pmall

container decorator dependency-injection psr-11