/**
  * Guesses the template name to render and its variables and adds them to
  * the request object.
  *
  * @param FilterControllerEvent $event A FilterControllerEvent instance
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     if (!is_array($controller = $event->getController())) {
         return;
     }
     $request = $event->getRequest();
     if (!($configuration = $request->attributes->get('_template'))) {
         return;
     }
     if (!$configuration->getTemplate()) {
         $configuration->setTemplate($this->guesser->guessTemplateName($controller, $request, $configuration->getEngine()));
     }
     $request->attributes->set('_template', $configuration->getTemplate());
     $request->attributes->set('_template_vars', $configuration->getVars());
     // all controller method arguments
     if (!$configuration->getVars()) {
         $r = new \ReflectionObject($controller[0]);
         $vars = array_map(function ($param) {
             return $param->getName();
         }, $r->getMethod($controller[1])->getParameters());
         $request->attributes->set('_template_default_vars', $vars);
     }
 }
 /**
  * @test
  *
  * @covers Sergiors\Silex\Templating\TemplateGuesser::guessTemplateName
  *
  * @uses Sergiors\Silex\Templating\Fixture\Controller\IndexController
  * @uses Sergiors\Silex\Templating\TemplateReference
  */
 public function guessTemplateName()
 {
     $template = new TemplateGuesser();
     $reference = $template->guessTemplateName([new IndexController(), 'indexAction'], new Request());
     $this->assertEquals('Index/index.html.twig', (string) $reference);
 }