EDIT: , . !
, PHP-DI, .
PHP-DI factory, , ( , Ocramius Proxy Manager).
PHP-DI DI\object() . , , . , , . . :
$builder = new DI\ContainerBuilder();
$builder->addDefinitions([
TestClass::class => DI\object()->constructor('param')
]);
$container = $builder->build();
$container TestClass.
, ( , . ), Ocramius Proxy Manager, ->lazy():
$builder = new DI\ContainerBuilder();
$builder->addDefinitions([
TestClass::class => DI\object()->constructor('param')->lazy()
]);
$container = $builder->build();
() -, .. . Ocramius Proxy Manager - , , .
PHP-DI factory . , , , . , DI\object() , . DI\object(), , DI\factory(), .
PHP-DI , , , :
TestClass::class => DI\factory(function() {
return new TestClass('param');
})->scope(DI\Scope::PROTOTYPE);
, ->scope(). , PROTOTYPE ( ) SINGLETON ( ). SINGLETON, , , .
- factory, .
- , ,
- , , . , : a) ; ) , , ) - . (, , ).