PHP code example of trifs / di

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

    

trifs / di example snippets


use trifs\DI;

$container = new Container();

$container->cookie_name = 'SESSION_ID';
$container->session_storage_class = 'SessionStorage';

$container->session_storage = function (Container $container) {
    return new $container->session_storage_class($container->cookie_name);
};

$container->session = function (Container $container) {
    return new Session($c['session_storage']);
};

// get the session object
$session = $container->session;

// the above call is roughly equivalent to the following code:
// $storage = new SessionStorage('SESSION_ID');
// $session = new Session($storage);

use trifs\DI\Container;
use trifs\DI\ServiceProviderInterface;

class FooProvider implements ServiceProviderInterface
{
    public function register(Container $container)
    {
        // register services and parameters
    }
}

$container->register(new FooProvider());

$container->session = $container->factory(function (Container $container) {
    return new Session($container->session_storage);
});