Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function __toString()
 {
     if (is_string($this->renderedResult)) {
         return $this->renderedResult;
     }
     $dispatcher = $this->context->getDispatcher();
     $previousContext = $dispatcher->switchCurrentContext($this->context);
     try {
         $result = $this->context->getComponent()->getViewRenderer()->render($this->templateName, $this->variables);
         if ($previousContext) {
             $dispatcher->switchCurrentContext($previousContext);
         }
         return $result;
     } catch (\Exception $e) {
         $exception = new ViewRenderException(sprintf('Cannot render template "%s".', $this->templateName), 0, $e);
         try {
             $result = $dispatcher->reportViewRenderError($exception, $this->context, $this->viewOwner);
             if ($previousContext) {
                 $dispatcher->switchCurrentContext($previousContext);
             }
         } catch (\Exception $e) {
             $result = $e->getMessage();
         }
         return $result;
     }
 }