mqwerty / dependency-injection
Simple PSR-11 DI container with autowiring
v1.2.0
2020-07-24 09:23 UTC
Requires
- php: ^7.4
- psr/container: ^1.0
Requires (Dev)
- phan/phan: ^3.0
- phpmd/phpmd: ^2.8
- phpunit/phpunit: ^9.2
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-10-21 04:44:19 UTC
README
Simple PSR-11 DI container with autowiring
<?php use Monolog\Handler\StreamHandler; use Monolog\Logger; use Psr\Log\LoggerInterface; class Foo { public function __construct(LoggerInterface $logger) { } } $config = [ 'logLevel' => 'info', 'shared' => [LoggerInterface::class], LoggerInterface::class => fn($c) => (new Logger('log'))->pushHandler( new StreamHandler(STDERR, $c->get('logLevel')) ), ]; $container = new Mqwerty\DI\Container($config); $container->get(Foo::class);