dakujem/sleeve

Lightweight PSR-11 service container 📦. A trivial extension of Symfony Pimple container.

1.1 2022-08-31 11:26 UTC

This package is auto-updated.

Last update: 2024-10-29 10:56:25 UTC


README

PHP from Packagist Coverage Status Nature Friendly

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.