|
|
@ -3,6 +3,7 @@
|
|
|
|
namespace Engelsystem\Http;
|
|
|
|
namespace Engelsystem\Http;
|
|
|
|
|
|
|
|
|
|
|
|
use Engelsystem\Renderer\Renderer;
|
|
|
|
use Engelsystem\Renderer\Renderer;
|
|
|
|
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
|
|
|
|
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
|
|
|
|
|
|
|
|
|
|
|
@ -11,21 +12,21 @@ class Response extends SymfonyResponse implements ResponseInterface
|
|
|
|
use MessageTrait;
|
|
|
|
use MessageTrait;
|
|
|
|
|
|
|
|
|
|
|
|
/** @var Renderer */
|
|
|
|
/** @var Renderer */
|
|
|
|
protected $view;
|
|
|
|
protected $renderer;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param string $content
|
|
|
|
* @param string $content
|
|
|
|
* @param int $status
|
|
|
|
* @param int $status
|
|
|
|
* @param array $headers
|
|
|
|
* @param array $headers
|
|
|
|
* @param Renderer $view
|
|
|
|
* @param Renderer $renderer
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
public function __construct(
|
|
|
|
$content = '',
|
|
|
|
$content = '',
|
|
|
|
int $status = 200,
|
|
|
|
int $status = 200,
|
|
|
|
array $headers = [],
|
|
|
|
array $headers = [],
|
|
|
|
Renderer $view = null
|
|
|
|
Renderer $renderer = null
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
$this->view = $view;
|
|
|
|
$this->renderer = $renderer;
|
|
|
|
parent::__construct($content, $status, $headers);
|
|
|
|
parent::__construct($content, $status, $headers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -47,7 +48,7 @@ class Response extends SymfonyResponse implements ResponseInterface
|
|
|
|
* provided status code; if none is provided, implementations MAY
|
|
|
|
* provided status code; if none is provided, implementations MAY
|
|
|
|
* use the defaults as suggested in the HTTP specification.
|
|
|
|
* use the defaults as suggested in the HTTP specification.
|
|
|
|
* @return static
|
|
|
|
* @return static
|
|
|
|
* @throws \InvalidArgumentException For invalid status code arguments.
|
|
|
|
* @throws InvalidArgumentException For invalid status code arguments.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function withStatus($code, $reasonPhrase = '')
|
|
|
|
public function withStatus($code, $reasonPhrase = '')
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -107,12 +108,12 @@ class Response extends SymfonyResponse implements ResponseInterface
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function withView($view, $data = [], $status = 200, $headers = [])
|
|
|
|
public function withView($view, $data = [], $status = 200, $headers = [])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!$this->view instanceof Renderer) {
|
|
|
|
if (!$this->renderer instanceof Renderer) {
|
|
|
|
throw new \InvalidArgumentException('Renderer not defined');
|
|
|
|
throw new InvalidArgumentException('Renderer not defined');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$new = clone $this;
|
|
|
|
$new = clone $this;
|
|
|
|
$new->setContent($this->view->render($view, $data));
|
|
|
|
$new->setContent($this->renderer->render($view, $data));
|
|
|
|
$new->setStatusCode($status, ($status == $this->getStatusCode() ? $this->statusText : null));
|
|
|
|
$new->setStatusCode($status, ($status == $this->getStatusCode() ? $this->statusText : null));
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($headers as $key => $values) {
|
|
|
|
foreach ($headers as $key => $values) {
|
|
|
@ -144,4 +145,14 @@ class Response extends SymfonyResponse implements ResponseInterface
|
|
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Set the renderer to use
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param Renderer $renderer
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function setRenderer(Renderer $renderer)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->renderer = $renderer;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|