Elephox 依赖注入库。


README

此模块由 Elephox 使用以提供依赖注入容器。它还具有解决函数和回调参数的机制。

示例

<?php

use Elephox\DI\ServiceCollectionOld;

$container = new ServiceCollectionOld();
$container->addSingleton(stdClass::class, stdClass::class, fn () => new stdClass());

$foo = function (stdClass $object) {
    return $object;
}

$instance = $container->resolver()->call($foo);
// $instance is an instance of stdClass
// multiple calls to $container->resolver()->callback($foo) will return the same instance, since it was added as a singleton