phug/dependency-injection

Phug dependency injection engine

2.0.1 2023-09-02 09:29 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 544180e1e866d397f7e470b77f2566f1fa7a6152

phptemplatehtmljadedependency-injectionviewsrenderpresentationdialectphtmlpugphug

This package is auto-updated.

Last update: 2026-06-15 18:44:23 UTC


README

What is Phug Dependency Injection?

This project allow to provide helpers functions and values, to require them and to dump all required dependencies as a PHP array export.

Installation

Install via Composer

composer require phug/dependency-injection

Usage

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')

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.