A lightweight PSR-11 service container.
A trivial extension of Symfony Pimple container.
💿
composer require dakujem/sleeve
Sleeve...
- is dead simple
- is PSR-11 compatible
- extends Pimple (pimple/pimple), a simple Dependency Injection Container by Symfony
- only adds a couple of convenience methods (accessors) on top of the original
- works well with Slim v4 and other micro frameworks and stacks
Added on top of Pimple:
- methods
get
,set
,has
,unset
- magic accessors
__get
,__set
,__isset
,__unset
Examples:
$dic = new Dakujem\Sleeve;
// the following are equivalent
$service = $dic->get('service'); // getter
$service = $dic['service']; // array accessor
$service = $dic->service; // magic accessor
// it works for setting services as well
$factory = function(Container $dic) {
return new Acme\MyService($dic->get('dependency'));
};
$dic->set('service', $factory); // setter
$dic['service'] = $factory; // array accessor
$dic->service = $factory; // magic accessor
Sleeve supports (through Pimple):
- singleton services (global)
- factory services (factories)
- parameters (with protection too)
- extensions (service providers)
📖 For full documentation, read the Pimple container usage documentation. It's quite short, in fact.
composer test
Tested for PHP versions 7.1 onwards.