PHP code example of lepre / di

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

    

lepre / di example snippets


use Lepre\DI\Container;

$container = new Container();

// register a service:
$container->set('my service', function () {
    return new MyService();
});

// register a service with dependencies:
$container->set('other service', function (Container $container) {
    return new OtherService(
        $container->get('my service')
    );
});