for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* 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\CommandHandler;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SymfonyContainerCommandHandlerLocator implements CommandHandlerLocator, ContainerAwareInterface
{
use ContainerAwareTrait;
* @var string[]
private $command_handler_ids = [];
* @param Command $command
* @return CommandHandler|null
public function findHandler(Command $command)
return $this->lazyLoad(get_class($command));
}
* @param string $command_name
* @param string $service
public function registerService($command_name, $service)
$this->command_handler_ids[$command_name] = $service;
* @param $command_name
* @return CommandHandler
private function lazyLoad($command_name)
if ($this->container instanceof ContainerInterface && isset($this->command_handler_ids[$command_name])) {
$handler = $this->container->get($this->command_handler_ids[$command_name]);
if ($handler instanceof CommandHandler) {
return $handler;
return null;