11
2- Phug Formatter
3- ========
2+ Phug Dependency Injection
3+ =========================
44
55What is Phug Dependency Injection?
6- -----------------
6+ ----------------------------------
77
88This project allow to provide helpers functions and values,
99to require them and to dump all required dependencies as
@@ -20,3 +20,31 @@ composer require phug/dependency-injection
2020
2121Usage
2222-----
23+
24+ ``` php
25+ use Phug\DependencyInjection;
26+
27+ $dependencies = new DependencyInjection();
28+ $dependencies->register('limit', 42);
29+ $dependencies->provider('clock', static function () {
30+ return new Clock();
31+ });
32+
33+ $dependencies->provider('expiration', ['clock', 'limit', static function (ClockInterface $clock, $limit) {
34+ return static function ($margin) use ($clock, $limit) {
35+ $delta = $limit - $margin;
36+
37+ return $clock->now()->modify("$delta days");
38+ };
39+ }]);
40+
41+ $expiration = $dependencies->call('expiration'); // return new DateTimeImmutable('now + 42 days')
42+ $expiration = $dependencies->call('expiration', 20); // return new DateTimeImmutable('now + 22 days')
43+ ```
44+
45+ Security contact information
46+ ----------------------------
47+
48+ To report a security vulnerability, please use the
49+ [ Tidelift security contact] ( https://tidelift.com/security ) .
50+ Tidelift will coordinate the fix and disclosure.
0 commit comments