Beispiel #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;
     }
 }
Beispiel #2
0
 /**
  * Возвращает информацию о контексте вызова виджета.
  * @param string $widgetUri путь виджета
  * @throws RuntimeException если контекст не существует
  * @return array
  */
 protected function resolveWidgetContext(&$widgetUri)
 {
     if (strpos($widgetUri, self::WIDGET_URI_SEPARATOR) !== 0) {
         if (!$this->currentContext) {
             throw new RuntimeException($this->translate('Context for executing widget "{widget}" is unknown.', ['widget' => $widgetUri]));
         }
         $widgetUri = self::WIDGET_URI_SEPARATOR . $widgetUri;
         return [$this->currentContext->getComponent(), clone $this->currentContext->getCallStack(), $this->currentContext->getBaseUrl()];
     }
     return [$this->getInitialComponent(), $this->createCallStack(), ''];
 }