einenlum / dyc
A very simple DIC, supporting autowiring (NOT production ready)
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
pkg:composer/einenlum/dyc
Requires (Dev)
- haydenpierce/class-finder: ^0.4.0
- phpspec/phpspec: ^6.1
Suggests
- haydenpierce/class-finder: To get a list of FQCN to autoload
This package is auto-updated.
Last update: 2025-10-06 20:24:56 UTC
README
A very simple DIC, supporting autowiring. For fun only.
Use
<?php require_once(__DIR__.'/vendor/autoload.php'); $dic = new \Dyc\Dic(); $dic->set(\Foo\Bar::class, function(\Dyc\Dic $dic) { return new \Foo\Bar($dic->get(\Bar\Baz::class)); }); $bar = $dic->get(\Foo\Bar::class);
Autowiring
We recommend using haydenpierce/class-finder, to get a list of all FQCN in your project.
<?php require_once(__DIR__.'/vendor/autoload.php'); $dic = new \Dyc\Dic(); $classes = \HaydenPierce\ClassFinder\ClassFinder::getClassesInNamespace('Foo'); $dic->autowire($classes); $bar = $dic->get(\Foo\Bar::class);
If one service requires an interface or a scalar, you will need to rewrite the whole definition for this one:
<?php require_once(__DIR__.'/vendor/autoload.php'); $dic = new \Dyc\Dic(); $classes = \HaydenPierce\ClassFinder\ClassFinder::getClassesInNamespace('Foo'); $dic->autowire($classes); $dic->set(\Some\Scalar\Dependent\Service::class, function(\Dyc\Dic $dic) { return new \Some\Scalar\Dependent\Service($dic->get(\Foo\Bar::class), 'some api key'); }); $service = $dic->get(\Some\Scalar\Dependent\Service::class);