-
-
Notifications
You must be signed in to change notification settings - Fork 327
Closed
Labels
Milestone
Description
It would be really nice if I could define specific parameters in my factory.
Take the following example where I want to build an array of delegates for a handler
class SomeHandlerFactory
{
public function create(SomeHandler $handler, array $delegates)
{
$handler->doSomethingCool();
array_map([$handler, 'pushDelegate'], $delegates);
return $handler;
}
}I would like to define the array of delegates to isolate accessing the container directly to my config.php
// config.php
return [
'SomeHandler' => factory(['SomeHandlerFactory', 'create'])->param('delegates', get('handlerDelegates')),
'handlerDelegates' => function (ContainerInterface $container) {
$delegates = [];
if (Config::get('someSetting')) {
array_push($delegates, $container->get('DelegateA'));
}
if (Config::get('awesomeMode')) {
array_push($delegates, $container->get('ImpeachTheOffice'));
}
return $delegates;
}
];