PHP code example of felipecwb / container

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

    

felipecwb / container example snippets



use Felipecwb\Container;

$container = new Container();
$container->set('config', [
    'environment' => 'dev',
    'database'    => 'sqlite::memory:'
]);

$container->get('config'); // Array

$container->set('db', function ($c) {
    // Container instance as first argument on closures
    $config = $c->get('config');

    return new PDO(
        $config['database'],
        null,
        null,
        array(PDO::ATTR_PERSISTENT => true)
    );
});

//lazy load
$container->getDb(); //PDO