get() method without having to write * the custom locator. * * Naturally, you can also pass in closures for further behavior tweaks. */ class CallableLocator implements HandlerLocator { /** * @var callable */ private $callable; /** * @param callable $callable */ public function __construct(callable $callable) { $this->callable = $callable; } /** * {@inheritdoc} */ public function getHandlerForCommand($commandName) { $callable = $this->callable; $handler = $callable($commandName); // Odds are the callable threw an exception but it always pays to check if ($handler === null) { throw MissingHandlerException::forCommand($commandName); } return $handler; } }