예제 #1
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testSetTemplateTemplateFormat()
 {
     $view = new View();
     $view->setTemplate('foo');
     $this->assertEquals('foo', $view->getTemplate());
     $view->setTemplate($template = new TemplateReference());
     $this->assertEquals($template, $view->getTemplate());
     $view->setTemplate(array());
 }
예제 #2
0
 /**
  * Render the view data with the given template
  *
  * @param View $view
  * @param string $format
  *
  * @return string
  */
 public function renderTemplate(View $view, $format)
 {
     $data = $view->getData();
     if (null === $data) {
         $data = array();
     }
     if (!is_array($data)) {
         throw new \RuntimeException(sprintf('data must be an array if you allow a templating-aware format (%s).', $format));
     }
     if (isset($data['form']) && $data['form'] instanceof FormInterface) {
         $data['form'] = $data['form']->createView();
     }
     $template = $view->getTemplate();
     if ($template instanceof TemplateReference) {
         if (null === $template->get('format')) {
             $template->set('format', $format);
         }
         if (null === $template->get('engine')) {
             $engine = $view->getEngine() ?: $this->defaultEngine;
             $template->set('engine', $engine);
         }
     }
     return $this->getTemplating()->render($template, $data);
 }