PHP code example of yuloh / container

1. Go to this page and download the library: Download yuloh/container 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/ */

    

yuloh / container example snippets


$container->set('db', function ($container) {
    $db = new Database();
    $logger = $container->get(Psr\Log\LoggerInterface::class);
    $db->setLogger($logger);
    return $db;
});

if ($container->has('db')) {
    $db = $container->get('db');
}
 php
use Yuloh\Container\Container;

$container = new Container();

$container->set(Psr\Log\LoggerInterface::class, function () {
    $logger = new Monolog\Logger();
    $logger->pushHandler(new StreamHandler('error.log'));
    return $logger;
});