Created
August 31, 2012 14:26
-
-
Save l3l0/3553485 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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