diff options
author | msquare <msquare@notrademark.de> | 2019-12-08 11:48:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-08 11:48:58 +0100 |
commit | a3a938a1210f1bfb2680c25b2bcf53e47444bdba (patch) | |
tree | fd4c13fd9b714c0d8c60b6d3fe3e2fc88b82b717 /src/Http/Response.php | |
parent | b540ac93856065ce6e145930b6611e0a0946d646 (diff) | |
parent | 064a1750279be244f86cf24f29749b391b11f1dd (diff) |
Merge pull request #685 from MyIgel/schedule-import
Rebuild Schedule import
Diffstat (limited to 'src/Http/Response.php')
-rw-r--r-- | src/Http/Response.php | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/src/Http/Response.php b/src/Http/Response.php index a6b4ab74..43bcb5d8 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -6,27 +6,37 @@ use Engelsystem\Renderer\Renderer; use InvalidArgumentException; use Psr\Http\Message\ResponseInterface; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; +use Symfony\Component\HttpFoundation\Session\SessionInterface; class Response extends SymfonyResponse implements ResponseInterface { use MessageTrait; + /** + * @var SessionInterface + */ + protected $session; + /** @var Renderer */ protected $renderer; /** - * @param string $content - * @param int $status - * @param array $headers - * @param Renderer $renderer + * @param string $content + * @param int $status + * @param array $headers + * @param Renderer $renderer + * @param SessionInterface $session */ public function __construct( $content = '', int $status = 200, array $headers = [], - Renderer $renderer = null + Renderer $renderer = null, + SessionInterface $session = null ) { $this->renderer = $renderer; + $this->session = $session; + parent::__construct($content, $status, $headers); } @@ -155,4 +165,44 @@ class Response extends SymfonyResponse implements ResponseInterface { $this->renderer = $renderer; } + + /** + * Sets a session attribute (which is mutable) + * + * @param string $key + * @param mixed|mixed[] $value + * @return Response + */ + public function with(string $key, $value) + { + if (!$this->session instanceof SessionInterface) { + throw new InvalidArgumentException('Session not defined'); + } + + $data = $this->session->get($key); + if (is_array($data) && is_array($value)) { + $value = array_merge_recursive($data, $value); + } + + $this->session->set($key, $value); + + return $this; + } + + /** + * Sets form data to the mutable session + * + * @param array $input + * @return Response + */ + public function withInput(array $input) + { + if (!$this->session instanceof SessionInterface) { + throw new InvalidArgumentException('Session not defined'); + } + + $this->session->set('form-data', $input); + + return $this; + } } |