You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Picotainer is heavily influenced by the Pimple DI container. Think about it
as a Pimple container with even less features, and ContainerInterop compatibility.
Installation
Before using Picotainer in your project, add it to your composer.json file:
$ ./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:
the list of entries, as an array of anonymous functions
The value is an anonymous function that will return the entry
The entry can be anything (an object, a scalar value, a resource, etc...)
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.
Fetching entries from the container
Fetching entries from the container is as simple as calling the get method:
$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...)
About
A minimalist PHP dependency injection container compatible with ContainerInterop