CallableLocator
in package
implements
HandlerLocator
This locator loads Handlers from a provided callable.
At first glance, this might seem fairly useless but it's actually very useful to encapsulate DI containers without having to write a custom adapter for each one.
Let's say you have a Symfony container or similar that works via a 'get' method. You can pass in an array style callable such as:
$locator = new CallableLocator([$container, 'get'])
This is easy to set up and will now automatically pipe the command name straight through to the $container->get() method without having to write the custom locator.
Naturally, you can also pass in closures for further behavior tweaks.
Interfaces, Classes and Traits
- HandlerLocator
- Service locator for handler objects
Table of Contents
- $callable : callable
- __construct() : mixed
- getHandlerForCommand() : object
- Retrieves the handler for a specified command
Properties
$callable
private
callable
$callable
Methods
__construct()
public
__construct(callable $callable) : mixed
Parameters
- $callable : callable
Return values
mixed —getHandlerForCommand()
Retrieves the handler for a specified command
public
getHandlerForCommand(mixed $commandName) : object
Parameters
- $commandName : mixed