All Projects → xtreamwayz → pimple-container-interop

xtreamwayz / pimple-container-interop

Licence: other
Superseded by https://github.com/zendframework/zend-pimple-config

Programming Languages

PHP
23972 projects - #3 most used programming language

Pimple-container-interop

Build Status

This container extends the Pimple 3 container. It also adds the delegate lookup feature from container-interop.

Usage

use Xtreamwayz\Pimple\Container;

$container = new Container();

And now you can use all Pimple features, and also have the has and get functions from container-interop.

Delegates

The delegate lookup feature allows several containers to share entries. It can perform dependency lookups in other containers. They can be added with the delegate($container) function.

$container = new Xtreamwayz\Pimple\Container;
$container['hi'] = 'welcome';

$delegate1 = new Acme\Container\DelegateContainer;
$delegate1['foo'] = 'bar';
$container->delegate($delegate1);

$delegate2 = new Xtreamwayz\Pimple\Container;
$delegate2['baz'] = 'qux';
$container->delegate($delegate2);

// Resolve dependency from main $container
$container->has('hi'); // true
$container->get('hi'); // returns 'welcome';

// Resolve dependency from $delegate1
$container->has('foo'); // true
$container->get('foo'); // returns 'bar';

// Resolve dependency from $delegate2
$container->has('baz'); // true
$container->get('baz'); // returns 'qux';

Once the delegate has been registered and a lookup is not resolved in the main container, it tries the has and get methods of each delegate in the order it was registered.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].