Technically\DependencyResolver is a simple yet powerful tool to instantiate classes
autowiring their dependencies by resolving them from a PSR-11 container
or recursively instantiating them with DependencyResolver itself.
- Based on PSR-11
- Supports modern PHP 8 features β union types,
nullandfalsetype hints, and others. - Recursive dependencies autowiring
- Semver
- Tests
Use Composer package manager to add Technically\DependencyResolver to your project:
composer require technically/dependency-resolver
<?phpfinalclass MyFancyService {
publicfunction__construct(callable|LoggerInterface$log) {
// initialize
}
}
// Construct a service instance, providing dependencies in-place:$resolver = newDependencyResolver();
$service = $resolver->construct(MyFancyService::class, [
'log' => function (string$priority, string$message) {
error_log("[$priority]: $message");
}]
);
// Resolve service instance from container, falling back to `construct()` otherwise.$resolver = newDependencyResolver($container);
$service = $resolver->resolve(MyFancyService::class);
All notable changes to this project will be documented in the CHANGELOG file.
- Implemented by πΎ Ivan Voskoboinyk
- Heavily inspired by Dawid Kraczkowski's work in igniphp/container