PHP code example of technically / dependency-resolver

1. Go to this page and download the library: Download technically/dependency-resolver library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

technically / dependency-resolver example snippets




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);