/** * Get the value of a scoped variable or fallback to the view model. * * @param string $key The name of the variable to be accessed. * @return mixed The value of the requetsed variable. */ public function get($key) { if (array_key_exists($key, $this->scoped)) { return $this->scoped[$key]; } return $this->model->get($key, NULL); }
/** * Extracts view model data into the current scope and includes the view resource. * * @param ViewModelInterface $__ * @return string * * @throws ResourceNotFoundException When the view resource does not exist. */ private function performInclude(ViewModelInterface $__) { $___ = $this->resolveResourcePath($__->getResource()); if (!is_file($___)) { throw new \OutOfBoundsException(sprintf('View resource not found: "%s"', $___)); } ob_start(); try { extract($__->toArray(), EXTR_SKIP); include $___; return ob_get_clean(); } catch (\Exception $e) { ob_end_clean(); throw $e; } }
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)); }
public function isSupported(ViewModelInterface $model) { return preg_match("'.+\\.[a-z0-9]+\\.xml\$'i", $model->getResource()) ? true : false; }
public function isSupported(ViewModelInterface $model) { return in_array(strtolower(pathinfo($model->getResource(), PATHINFO_EXTENSION)), ['php', 'phtml']); }