dakujem / sleeve
Lightweight PSR-11 service container 📦. A trivial extension of Symfony Pimple container.
Installs: 1 888
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- pimple/pimple: ^3.4
Requires (Dev)
- nette/tester: ^2.4
README
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
Usage
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.
Testing
composer test
Tested for PHP versions 7.1 onwards.