Skip to content

πŸ” Dependency-resolver utility based on PSR-11 container to be used for auto-wiring. 🐘 PHP8-ready πŸŽ‰

License

Notifications You must be signed in to change notification settings

technically-php/dependency-resolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

40 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Technically Dependency Resolver

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.

Status

Features

  • Based on PSR-11
  • PHP 8.0 ready (supports union type hints; see examples below)
  • PHP 7.1+ compatible
  • Recursive dependencies autowiring
  • Semver
  • Tests

Installation

Use Composer package manager to add Technically\DependencyResolver to your project:

composer require technically/dependency-resolver

Example

<?php

final class MyFancyService 
{
    public function __construct(callable|LoggerInterface $log) 
    {
        // initialize
    }
}

// Construct service instance, providing dependencies in-place:
$resolver = new DependencyResolver();
$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 = new DependencyResolver($container);
$service = $resolver->resolve(MyFancyService::class);

Changelog

All notable changes to this project will be documented in the CHANGELOG file.

Credits

About

πŸ” Dependency-resolver utility based on PSR-11 container to be used for auto-wiring. 🐘 PHP8-ready πŸŽ‰

Topics

Resources

License

Stars

Watchers

Forks