PHP code example of phug / dependency-injection

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

    

phug / dependency-injection example snippets


use Phug\DependencyInjection;

$dependencies = new DependencyInjection();
$dependencies->register('limit', 42);
$dependencies->provider('clock', static function () {
    return new Clock();
});

$dependencies->provider('expiration', ['clock', 'limit', static function (ClockInterface $clock, $limit) {
    return static function ($margin) use ($clock, $limit) {
        $delta = $limit - $margin;

        return $clock->now()->modify("$delta days");
    };
}]);

$expiration = $dependencies->call('expiration'); // return new DateTimeImmutable('now + 42 days')
$expiration = $dependencies->call('expiration', 20); // return new DateTimeImmutable('now + 22 days')