anhoder / container
This package is abandoned and no longer maintained.
The author suggests using the yarfox/container package instead.
psr-11 container
1.0.3
2022-07-23 10:35 UTC
Requires
- psr/container: ^2.0
- yarfox/utils: ^0.1.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2022-07-24 07:24:35 UTC
README
Another container in PHP.
Requirement
php>=8.0
Install
composer require yarfox/container
Usage
abstract class AA {} class AAI extends AA{} class A { } class B { public function __construct(A $a) { } } class C { public function __construct(B $b, int $a = 123) { } } class D { public function __construct(A $a, AA $b) {} } $container = Container::instance(); $container->registerProducer('a', function () { return new A(); }); $container->resolve('a'); // get A() $container->resolve(A::class); // get A() $container->resolve(C::class); // get C() $container->resolve(D::class); // throw Container Exception: AA is not instantiable! $container->registerInstance(AA::class, $container->resolveClass(AAI::class)); // AA::class => AAI() $container->resolve(D::class); // get D()