phug/dependency-injection


README

什么是 Phug 依赖注入?

该项目允许提供辅助函数和值,要求它们,并将所有所需的依赖项作为 PHP 数组导出。

安装

通过 Composer 安装

composer require phug/dependency-injection

使用方法

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

安全联系信息

要报告安全漏洞,请使用 Tidelift 安全联系人。 Tidelift 将协调修复和披露。