PHP code example of chiron / injector
1. Go to this page and download the library: Download chiron/injector 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/ */
chiron / injector example snippets
// A function to call
$fn = function (Foo $a, Bar $b, int $c) { /* ... */ };
// Arbitrary PSR-11 compatible object container
$container = new \some\di\Container([
Foo::class => new Foo(), // will be used as $a
]);
// Prepare the injector
$injector = new Injector($container);
// Use the injector to call the function and resolve dependencies
$result = $injector->invoke($fn, [
'c' => 15, // will be used as $c
new Bar(), // will be used as $b
]);