-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Open
Description
Description
I could not find a way in the documentation to index the same service class with multiple names using default_index_method
This would be usefull whan you have to use complex strategy pattern
Example
class StrategyFooAction implements ActionInterface
{
public static function getProviderName(): string
{
return 'Strategy/Foo/Action';
}
public static function action(): mixed
{
...
}
}
class StrategyBarAction implements ActionInterface
{
public static function getProviderName(): string
{
return 'Strategy/Bar/Action';
}
public static function action(): mixed
{
...
}
}
If "Foo/Action" and "Bar/Action" must do the same thing it would useful to define:
class StrategyFooBarAction implements ActionInterface
{
public static function getProviderName(): array
{
return [
'Strategy/Foo/Action',
'Strategy/Bar/Action',
];
}
public static function action(): mixed
{
...
}
}
And when I require the service:
$actionService = $serviceLocator->get('Strategy/'.$case.'/Action');
$actionService->action($data);
I could get StrategyFooBarAction if $case are or Foo or Bar, but not for other cases.