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\Query\Handler\Locator;
use GpsLab\Component\Query\Query;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SymfonyContainerQueryHandlerLocator implements QueryHandlerLocator, ContainerAwareInterface
{
use ContainerAwareTrait;
* @var array
private $query_handler_ids = [];
* @param Query $query
* @return callable|null
public function findHandler(Query $query)
return $this->lazyLoad(get_class($query));
}
* @param string $query_name
* @param string $service
* @param string $method
public function registerService($query_name, $service, $method = '__invoke')
$this->query_handler_ids[$query_name] = [$service, $method];
* @param $query_name
* @return callable
private function lazyLoad($query_name)
if ($this->container instanceof ContainerInterface && isset($this->query_handler_ids[$query_name])) {
list($service, $method) = $this->query_handler_ids[$query_name];
$handler = $this->container->get($service);
if (is_callable($handler)) {
return $handler;
} elseif (is_callable([$handler, $method])) {
return [$handler, $method];
return null;