2017 © Pedro PelĂĄez
 

library picotainer

This package contains a really minimalist dependency injection container compatible with container-interop.

image

mouf/picotainer

This package contains a really minimalist dependency injection container compatible with container-interop.

  • Thursday, March 9, 2017
  • by mouf
  • Repository
  • 20 Watchers
  • 12 Stars
  • 49,337 Installations
  • PHP
  • 13 Dependents
  • 1 Suggesters
  • 4 Forks
  • 1 Open issues
  • 5 Versions
  • 18 % Grown

The README.md

Picotainer

Latest Stable Version Latest Unstable Version License Scrutinizer Code Quality SensioLabsInsight Build Status Coverage Status, (*1)

This package contains a really minimalist dependency injection container (24 lines of code!) compatible with container-interop (supports ContainerInterface and delegate lookup feature). It is also, therefore, compatible with PSR-11, the FIG container standard., (*2)

Picotainer is heavily influenced by the Pimple DI container. Think about it as a Pimple container with even less features, and ContainerInterop compatibility., (*3)

Installation

Before using Picotainer in your project, add it to your composer.json file:, (*4)

$ ./composer.phar require mouf/picotainer ~1.0

Storing entries in the container

Creating a container is a matter of creating a Picotainer instance. The Picotainer class takes 2 parameters:, (*5)

use Mouf\Picotainer\Picotainer;
use Psr\Container\ContainerInterface;

$container = new Picotainer([
    "myInstance"=>function(ContainerInterface $container) {
        return new MyInstance();
    },
    "myOtherInstance"=>function(ContainerInterface $container) {
        return new MyOtherInstance($container->get('myInstance'));
    }
    "myParameter"=>function(ContainerInterface $container) {
        return MY_CONSTANT;
    }
], $rootContainer);

The list of entries is an associative array., (*6)

  • The key is the name of the entry in the container
  • The value is an anonymous function that will return the entry

The entry can be anything (an object, a scalar value, a resource, etc...), (*7)

The anonymous function must accept one parameter: the container on which dependencies will be fetched. The container is the "delegate-lookup container" if it was passed as the second argument of the constructor, or the Picotainer instance itself if no delegate lookup container was passed., (*8)

Fetching entries from the container

Fetching entries from the container is as simple as calling the get method:, (*9)

$myInstance = $container->get('myInstance');

Why the need for this package?

This package is part of a long-term effort to bring interoperability between DI containers. The ultimate goal is to make sure that multiple containers can communicate together by sharing entries (one container might use an entry from another container, etc...), (*10)

The Versions

09/03 2017

1.1.x-dev

1.1.9999999.9999999-dev http://mouf-php.com

This package contains a really minimalist dependency injection container compatible with container-interop.

  Sources   Download

MIT

The Requires

 

The Development Requires

dependency injection di container-interop

09/03 2017

v1.1.0

1.1.0.0 http://mouf-php.com

This package contains a really minimalist dependency injection container compatible with container-interop.

  Sources   Download

MIT

The Requires

 

The Development Requires

dependency injection di container-interop

09/03 2017

1.0.x-dev

1.0.9999999.9999999-dev http://mouf-php.com

This package contains a really minimalist dependency injection container compatible with container-interop.

  Sources   Download

MIT

The Requires

 

The Development Requires

dependency injection di container-interop

15/12 2015

v1.0.1

1.0.1.0 http://mouf-php.com

This package contains a really minimalist dependency injection container compatible with container-interop.

  Sources   Download

MIT

The Requires

 

The Development Requires

dependency injection di container-interop

21/01 2015

v1.0.0

1.0.0.0 http://mouf-php.com

This package contains a really minimalist dependency injection container compatible with container-interop.

  Sources   Download

MIT

The Requires

 

The Development Requires

dependency injection di container-interop