PHP code example of mqwerty / dependency-injection
1. Go to this page and download the library: Download mqwerty/dependency-injection 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/ */
mqwerty / dependency-injection example snippets
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
class Foo
{
public function __construct(LoggerInterface $logger)
{
}
}
$config = [
'logLevel' => 'info',
'shared' => [LoggerInterface::class],
LoggerInterface::class => fn($c) => (new Logger('log'))->pushHandler(
new StreamHandler(STDERR, $c->get('logLevel'))
),
];
$container = new Mqwerty\DI\Container($config);
$container->get(Foo::class);