public function __invoke(Request $request, Response $response, PayloadInterface $payload = null) : Response { $file = $this->getTemplateFile(); $html = $this->render($file, $payload->getOutput()); $response->getBody()->write($html); return $response; }
/** * Builds a Response for PayloadStatus::SUCCESS. */ protected function success() { $this->response = $this->response->withStatus(200); $this->htmlBody($this->payload->getOutput()); }
/** * Error * * @return mixed * * @access protected */ protected function error() { $this->response = $this->response->withStatus(500); $this->render($this->errorViewScript, ['error' => $this->payload->getOutput()]); }
/** * * Builds a Response for PayloadStatus::UPDATED. * */ protected function updated() { $this->response = $this->response->withStatus(303); $this->jsonBody($this->payload->getOutput()); }
/** * Returns the Responder * @return string */ protected function htmlBody($data) { // // $slug = 'error'; if (isset($data)) { // $slug = $this->request->getAttribute('page'); $slugFromPayload = $this->payload->getOutput(); // $slug = $slugFromPayload['slug']; if (isset($slugFromPayload['slug'])) { $slug = $slugFromPayload['slug']; } else { $slug = 'index'; } // $this->request = $this->request->withAttribute('page', 'error.php'); //setup views // $this->loadTemplate(); // $template = $this->twig->loadTemplate($view); // $body = $template->render($data); // $this->response = $this->response->withHeader('Content-Type', 'text/html'); // $this->response->getBody()->write($body); } // set thir probaly fro config file // Aura.view setup $view_factory = new ViewFactory(); // a $view = $view_factory->newInstance(); // // layout $layout_registry = $view->getLayoutRegistry(); $layout_registry->set('layout', $this->layout); // views $view_registry = $view->getViewRegistry(); $slug = $this->request->getAttribute('page'); $partial_view = $this->staticpages . $slug . '.php'; // check if the partial file exists, if not set status 404 if (!file_exists($partial_view)) { $this->response = $this->response->withStatus(404); $partial_view = $this->staticpages . 'error' . '.php'; } // set the registy $view_registry->set('_content', $partial_view); // demo data $dataset = ['data' => $data, 'partial' => 'partial', 'debug' => $this->payload->getStatus()]; // assign data to the view $view->setData($dataset); /* * check for ajax request and set views accordingly */ if ($this->is_pjax()) { // pjax request, set the view only // $this->renderView(); $view->setView('_content'); } else { // regular http request, set view and layout $view->setLayout('layout'); $view->setView('_content'); } $output = $view->__invoke(); // retun response $this->response = $this->response->withHeader('Content-Type', 'text/html'); $this->response->getBody()->write($output); }