summaryrefslogtreecommitdiff
path: root/src/Http
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-08 12:48:08 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-09 12:11:12 +0200
commit222c9fed7d4ca2b3b44c05907fbb7080c1efd342 (patch)
tree62b1bfa9233000985331b9dea703d51dc24515a2 /src/Http
parent2d6bca1357faff28bc1f86a56b432cc463ff7574 (diff)
parent8257864829ffdfb410f05e0dd0a9c781f48b741a (diff)
Merge remote-tracking branch 'MyIgel/templating'
Diffstat (limited to 'src/Http')
-rw-r--r--src/Http/Response.php41
-rw-r--r--src/Http/SessionServiceProvider.php1
-rw-r--r--src/Http/UrlGeneratorServiceProvider.php1
3 files changed, 43 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);
+ }
}
diff --git a/src/Http/SessionServiceProvider.php b/src/Http/SessionServiceProvider.php
index 55e3f48b..59121a3b 100644
--- a/src/Http/SessionServiceProvider.php
+++ b/src/Http/SessionServiceProvider.php
@@ -17,6 +17,7 @@ class SessionServiceProvider extends ServiceProvider
$this->app->bind(SessionStorageInterface::class, 'session.storage');
$session = $this->app->make(Session::class);
+ $this->app->instance(Session::class, $session);
$this->app->instance('session', $session);
/** @var Request $request */
diff --git a/src/Http/UrlGeneratorServiceProvider.php b/src/Http/UrlGeneratorServiceProvider.php
index 37304076..9b9988aa 100644
--- a/src/Http/UrlGeneratorServiceProvider.php
+++ b/src/Http/UrlGeneratorServiceProvider.php
@@ -9,6 +9,7 @@ class UrlGeneratorServiceProvider extends ServiceProvider
public function register()
{
$urlGenerator = $this->app->make(UrlGenerator::class);
+ $this->app->instance(UrlGenerator::class, $urlGenerator);
$this->app->instance('http.urlGenerator', $urlGenerator);
}
}