Skip to content

Instantly share code, notes, and snippets.

@l3l0
Created August 31, 2012 14:26
Show Gist options
  • Save l3l0/3553485 to your computer and use it in GitHub Desktop.
Save l3l0/3553485 to your computer and use it in GitHub Desktop.
namespace L3l0\AcmeBundle;
use Symfony\Component\HttpKernel\Controlle\ControllerResolverInterface;
use Symfony\Component\HttpFoundation\Request;
class ControllerChecker
{
private $resolver;
private $request;
public function __construct(ControllerResolverInterface $resolver, Request $request)
{
$this->resolver = $resolver;
$this->request = $request;
}
public function checkController($controller, array $attributes = array(), array $query = array())
{
$attributes['_controller'] = $controller;
$subRequest = $this->request->duplicate($query, null, $attributes);
try {
if (false === $controller = $this->resolver->getController($subRequest)) {
return false;
}
} catch (\Exception $e) {
return false;
}
return true;
}
}
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="l3l0.controller_checker" class="L3l0\AcmeBundle\ControllerChecker" scope="request">
<argument type="service" id="controller_resolver" />
<argument type="service" id="request" />
</service>
</services>
</container>
$this->get('l3l0.controller_checker')->checkController('l3l0AcmeBundle:Address/List:index');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment