for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/**
* GpsLab component.
*
* @author Peter Gribanov <[email protected]>
* @copyright Copyright (c) 2011, Peter Gribanov
* @license http://opensource.org/licenses/MIT
*/
namespace GpsLab\Component\Command\Handler\Locator;
use GpsLab\Component\Command\Command;
use GpsLab\Component\Command\Handler\CommandSubscriber;
class DirectBindingCommandHandlerLocator implements CommandHandlerLocator
{
* @var callable[]
private $handlers = [];
* Bind command handler to concrete command by class name.
* @param string $command_name
* @param callable $handler
public function registerHandler(string $command_name, callable $handler): void
$this->handlers[$command_name] = $handler;
}
* @param CommandSubscriber $subscriber
public function registerSubscriber(CommandSubscriber $subscriber): void
foreach ($subscriber::getSubscribedCommands() as $command_name => $method) {
$handler = [$subscriber, $method];
if (is_callable($handler)) {
$this->registerHandler($command_name, $handler);
* @param Command $command
* @return callable|null
public function findHandler(Command $command): ?callable
return $this->handlers[get_class($command)] ?? null;