PHP code example of runner / container

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

    

runner / container example snippets


use Runner\Container\Container;

$container = new Container();

$container->bind('stack', SplStack::class);

$container->make('stack');

$container->bind(ArrayAccess::class, function () {
    return new ArrayObject();
});


$container->bind(ArrayAccess::class, function () {
    return new ArrayObject();
});

$container->make(ArrayAccess::class);


$container->bind(
    'db', 
    function () {
        return new PDO();
    }, 
    true
);

$container->bind();

$pdo = new PDO();

$container->instance('db', $pdo);

$container->bind(CacheInterface::class, function () {
    return new FileCache();
});

$container->bind('cache', CacheInterface::class, true);

$container->make('cache');

$container->bind(CacheInterface::class, function () {
    return new FileCache();
});

$container->bind('redis_cache', function () {
    return new RedisCache();
});

$container->bindContext(
    PageController::class,
    CacheInterface::class,
    function (Container $container) {
        return $container->make('redis_cache');
    }
);

$controller = $container->make(PageController::class);