summaryrefslogtreecommitdiff
path: root/src/Http
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-08-29 13:58:50 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-08-29 23:46:32 +0200
commita2c47304d8230f1937c2a4f019aba89fa74203bc (patch)
tree7c981fc1577f865600a22b655349587f188c7410 /src/Http
parent427315195bdd379a0207fc9b2aaf69a5b5b86c79 (diff)
Added generic error pages
Diffstat (limited to 'src/Http')
-rw-r--r--src/Http/Response.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Http/Response.php b/src/Http/Response.php
index 9db6fa83..d79ab98b 100644
--- a/src/Http/Response.php
+++ b/src/Http/Response.php
@@ -2,6 +2,7 @@
namespace Engelsystem\Http;
+use Engelsystem\Renderer\Renderer;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
@@ -9,6 +10,25 @@ class Response extends SymfonyResponse implements ResponseInterface
{
use MessageTrait;
+ /** @var Renderer */
+ protected $view;
+
+ /**
+ * @param string $content
+ * @param int $status
+ * @param array $headers
+ * @param Renderer $view
+ */
+ public function __construct(
+ $content = '',
+ int $status = 200,
+ array $headers = array(),
+ Renderer $view = null
+ ) {
+ $this->view = $view;
+ parent::__construct($content, $status, $headers);
+ }
+
/**
* Return an instance with the specified status code and, optionally, reason phrase.
*
@@ -72,4 +92,25 @@ class Response extends SymfonyResponse implements ResponseInterface
return $new;
}
+
+ /**
+ * Return an instance with the rendered content.
+ *
+ * THis method retains the immutability of the message and returns
+ * an instance with the updated status and headers
+ *
+ * @param string $view
+ * @param array $data
+ * @param int $status
+ * @param string[]|string[][] $headers
+ * @return Response
+ */
+ public function withView($view, $data = [], $status = 200, $headers = [])
+ {
+ if (!$this->view instanceof Renderer) {
+ throw new \InvalidArgumentException('Renderer not defined');
+ }
+
+ return $this->create($this->view->render($view, $data), $status, $headers);
+ }
}