ellipse / container
Minimal Psr-11 container implementation handling service provider interop
Installs: 451
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/ellipse/container
Requires
- php: >=7.0
- container-interop/service-provider: ^0.4.0
- ellipse/type-errors: ^1.0
Requires (Dev)
- eloquent/phony-kahlan: ^1.0
- kahlan/kahlan: ^4.0
Provides
README
Minimal Psr-11 container implementation handling service provider interop.
Require php >= 7.0
Installation composer require ellipse/container
Run tests ./vendor/bin/kahlan
Getting started
The Ellipse\Container
class constructor takes an array of Interop\Container\ServiceProviderInterface
implementations. This is the only way of registering service providers and service definitions into the container.
An Ellipse\Container\Exceptions\ServiceProviderTypeException
is thrown when any element of the array passed to the Container
class constructor is not an implementation of ServiceProviderInterface
.
<?php namespace App; use Interop\Container\ServiceProviderInterface; class ServiceProviderA implements ServiceProviderInterface { public function getFactories() { return [ 'id' => function ($container) { return 'abc'; }, ] } public function getExtensions() { return [ // ] } }
<?php namespace App; use Interop\Container\ServiceProviderInterface; class ServiceProviderB implements ServiceProviderInterface { public function getFactories() { return [ // ] } public function getExtensions() { return [ 'id' => function ($container, string $previous) { return $previous . 'def'; }, ] } }
<?php namespace App; use Ellipse\Container; // Get a container with a list of service providers. $container = new Container([ new ServiceProviderA, new ServiceProviderB, ]); // Return true. $container->has('id'); // Return 'abcdef'. $container->get('id');