From 275efd05663405939d17f7d1a1bbc611df4697c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Fabr=C3=A9gat?= Date: Mon, 8 Oct 2018 15:35:59 +0200 Subject: [PATCH 1/4] new response EmptyResponse --- src/EmptyResponse.php | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/EmptyResponse.php diff --git a/src/EmptyResponse.php b/src/EmptyResponse.php new file mode 100644 index 0000000..84260b7 --- /dev/null +++ b/src/EmptyResponse.php @@ -0,0 +1,47 @@ + +// Date: 08/10/2018 +// Project: Psr7Responses +// +declare(strict_types=1); +namespace CodeInc\Psr7Responses; +use GuzzleHttp\Psr7\Response; + + +/** + * Class EmptyResponse + * + * @package CodeInc\Psr7Responses + * @author Joan Fabrégat + */ +class EmptyResponse extends Response +{ + /** + * EmptyResponse constructor. + * + * @param int $code + * @param string $reasonPhrase + * @param array $headers + * @param string $version + */ + public function __construct(int $code = 404, string $reasonPhrase = '', + array $headers = [], string $version = '1.1') + { + parent::__construct($code, $headers, '', $version, $reasonPhrase); + } +} \ No newline at end of file From 8a7b3ad9ec5ab51eecda61a5e1a5c4c274467b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Fabr=C3=A9gat?= Date: Mon, 8 Oct 2018 15:36:15 +0200 Subject: [PATCH 2/4] bug fixes --- src/ForbiddenResponse.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ForbiddenResponse.php b/src/ForbiddenResponse.php index 7378694..d3eac1a 100644 --- a/src/ForbiddenResponse.php +++ b/src/ForbiddenResponse.php @@ -28,22 +28,25 @@ * * @package CodeInc\Psr7Responses * @author Joan Fabrégat + * @license MIT + * @link https://github.com/CodeIncHQ/Psr7Responses + * @version 2 */ class ForbiddenResponse extends HtmlResponse { /** * ForbiddenResponse constructor. * - * @param string|null $html - * @param null|string $charset + * @param string $html + * @param int $code + * @param string $reasonPhrase + * @param string $charset * @param array $headers - * @param null $body * @param string $version - * @param null|string $reason */ - public function __construct(string $html = null, string $charset = 'utf-8', array $headers = [], - $body = null, string $version = '1.1', ?string $reason = null) + public function __construct(string $html = '', int $code = 403, string $reasonPhrase = '', + string $charset = 'utf-8', array $headers = [], string $version = '1.1') { - parent::__construct($html ?? '', $charset, 403, $headers, $version, $reason); + parent::__construct($html, $code, $reasonPhrase, $charset, $headers, $version); } } \ No newline at end of file From 3c497a6a18bcba5a771f9b12a7b751d9dd607ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Fabr=C3=A9gat?= Date: Mon, 8 Oct 2018 15:36:21 +0200 Subject: [PATCH 3/4] code improvement --- src/NotFoundResponse.php | 4 ++-- src/RedirectResponse.php | 11 +++++++---- src/UnauthorizedResponse.php | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/NotFoundResponse.php b/src/NotFoundResponse.php index e7e7412..b20f3f0 100644 --- a/src/NotFoundResponse.php +++ b/src/NotFoundResponse.php @@ -37,14 +37,14 @@ class NotFoundResponse extends HtmlResponse /** * NotFoundResponse constructor. * - * @param string|null $html + * @param string $html * @param int $code * @param string $reasonPhrase * @param string $charset * @param array $headers * @param string $version */ - public function __construct(string $html = null, int $code = 404, string $reasonPhrase = '', + public function __construct(string $html = '', int $code = 404, string $reasonPhrase = '', string $charset = 'utf-8', array $headers = [], string $version = '1.1') { parent::__construct( diff --git a/src/RedirectResponse.php b/src/RedirectResponse.php index 7f032a1..e973085 100644 --- a/src/RedirectResponse.php +++ b/src/RedirectResponse.php @@ -21,7 +21,6 @@ // declare(strict_types = 1); namespace CodeInc\Psr7Responses; -use GuzzleHttp\Psr7\Response; /** @@ -33,7 +32,7 @@ * @link https://github.com/CodeIncHQ/Psr7Responses * @version 2 */ -class RedirectResponse extends Response +class RedirectResponse extends EmptyResponse { /** * @var string @@ -53,8 +52,12 @@ public function __construct(string $url, int $code = 302, string $reasonPhrase = array $headers = [], string $version = '1.1') { $this->url = $url; - $headers["Location"] = $url; - parent::__construct($code, $headers, $version, $reasonPhrase); + parent::__construct( + $code, + $reasonPhrase, + $headers + ['Location' => $url], + $version + ); } /** diff --git a/src/UnauthorizedResponse.php b/src/UnauthorizedResponse.php index 8bd8798..84b1a5d 100644 --- a/src/UnauthorizedResponse.php +++ b/src/UnauthorizedResponse.php @@ -36,7 +36,7 @@ class UnauthorizedResponse extends HtmlResponse /** * UnauthorizedResponse constructor. * - * @param string|null $html + * @param string $html * @param int $code * @param string $reasonPhrase * @param string $charset From a9333cb08777785e69aa313568d9e66be9b3fbe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Fabr=C3=A9gat?= Date: Mon, 8 Oct 2018 15:36:29 +0200 Subject: [PATCH 4/4] v2.0.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 38ed6ae..324f092 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "codeinc/psr7-responses", - "version": "2.0.0", + "version": "2.0.1", "description": "A collection of PSR-7 responses", "homepage": "https://github.com/CodeIncHQ/Psr7Responses", "type": "library",