protected guessTemplateName ( array $controller, |
||
$controller | array | An array storing the controller object and action method |
$request | A Request instance | |
return | template reference |
protected function guessTemplateName($controller, Request $request)
{
if (!preg_match('/Controller\\\(.+)Controller$/', get_class($controller[0]), $matchController)) {
throw new \InvalidArgumentException(sprintf('The "%s" class does not look like a controller class (it must be in a "Controller" sub-namespace and the class name must end with "Controller")', get_class($controller[0])));
}
if (!preg_match('/^(.+)Action$/', $controller[1], $matchAction)) {
throw new \InvalidArgumentException(sprintf('The "%s" method does not look like an action method (it does not end with Action)', $controller[1]));
}
$bundle = $this->getBundleForClass(get_class($controller[0]));
return new TemplateReference($bundle->getName(), $matchController[1], $matchAction[1], $request->getRequestFormat(), 'twig');
}
protected function guessTemplateName($controller, Request $request, $engine = 'twig') { $controllerClass = get_class($controller[0]); $userClass = ClassUtils::getUserClass($controllerClass); if ($controllerClass === $userClass) { return parent::guessTemplateName($controller, $request, $engine); } if (!preg_match('/Controller\\\\(.+)Controller$/', $userClass, $matchController)) { throw new \InvalidArgumentException(sprintf('The "%s" class does not look like a controller class (it must be in a "Controller" sub-namespace and the class name must end with "Controller")', $userClass)); } if (!preg_match('/^(.+)Action$/', $controller[1], $matchAction)) { throw new \InvalidArgumentException(sprintf('The "%s" method does not look like an action method (it does not end with Action)', $controller[1])); } $bundle = $this->getBundleForClass($userClass); return new TemplateReference($bundle->getName(), $matchController[1], $matchAction[1], $request->getRequestFormat(), $engine); }