apinephp / container
A minimalistic PSR-11 Dependency Container
2.0.0
2019-12-13 09:19 UTC
Requires
- php: >=7.4
- apinephp/resolver: ^2
- psr/container: ^1.0
Requires (Dev)
- phpunit/phpunit: ^7
- psr/http-message: ^1.0
- vimeo/psalm: ^3.0
README
A minimalistic PSR-11 DI and IoC Container
Installation
Installation is made with composer
composer require apinephp/container
The package requires PHP 7.4 or newer.
Usage Example
<?php
use Apine\Container\Container;
$container = new Container();
$container->register('service', function () {
return 'A service';
});
$container->get('service'); // 'A service'
DI with services
Instantiate new services using the createInstance
function. It produces a Closure
that will create an instance of the class applying dependency resolution and injection against the services in the container.
<?php
use Apine\Container\Container;
use function Apine\Container\createInstance;
$container = new Container();
$container->register('service', createInstance(StubClass::class));
$service = $container->get('service'); // Returns an instance of StubClass