function decorate(k_Response $response) { if ($response->status() >= 300 && $response->status() < 400) { return new k_HtmlResponse($this->render($response, true)); } if ($response instanceof k_HtmlResponse) { $html = $response->toContentType('text/html'); if (strpos($html, '</body>') === false) { $body = $html . $this->render($response, false); } else { $body = str_replace('</body>', $this->render($response, false) . '</body>', $html); } $out = new k_HtmlResponse($body); $out->setStatus($response->status()); $out->setCharset($response->charset()); foreach ($response->headers() as $key => $value) { $out->setHeader($key, $value); } return $out; } return $response; }
protected function dispatchRoot($root_class_name) { try { $class_name = $root_class_name; while (true) { try { $root = $this->components()->create($class_name, $this->context()); $response = $root->dispatch(); if (!$response instanceof k_Response) { $response = new k_HtmlResponse($response); } $response->setCharset($this->charsetStrategy()->responseCharset()); return $response; } catch (k_MetaResponse $ex) { $class_name = $ex->componentName(); } } } catch (k_Response $ex) { return $ex; } }