Ejemplo n.º 1
0
 public function render(ViewModelInterface $model, $onlyEntity = false)
 {
     $m = NULL;
     if (!preg_match("'.+\\.([a-z0-9]+)\\.xml\$'i", $model->getResource(), $m)) {
         throw new \RuntimeException(sprintf('Unable to determine output format of view "%s"', $model->getResource()));
     }
     $typeName = $this->factory->createView($this, $model->getResource());
     $view = new $typeName($this->factory, $this);
     $response = new HttpResponse();
     $format = strtolower($m[1]);
     $out = $view->render(new OutputBuffer(), $model, ['@format' => $format, '@response' => $response]);
     if ($onlyEntity) {
         return (string) $out;
     }
     if (!$response->hasHeader('Content-Type')) {
         $type = new MediaType(Filesystem::guessMimeTypeFromFilename($format));
         if ($type->isText()) {
             $response->setHeader('Content-Type', $type . '; charset="utf-8"');
         } else {
             $response->setHeader('Content-Type', $type);
         }
         if ($type->is('*/xml')) {
             $out = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $out;
         }
     }
     return $response->setEntity(ltrim($out));
 }
Ejemplo n.º 2
0
 /**
  * Get the parent view of this view or NULL if no parent view exists.
  * 
  * @return CompiledTemplate
  */
 protected final function getParent()
 {
     if ($this->parent === false) {
         if (NULL === ($file = $this->getExtended())) {
             $this->parent = NULL;
         } else {
             $typeName = $this->factory->createView($this->renderer, $this->resolveResource($file));
             $this->parent = new $typeName($this->factory, $this->renderer);
             $this->parent->inherit($this->context, $this->exp);
         }
     }
     return $this->parent;
 }