This repository has been archived by the owner on Feb 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev for optimised compatibility with PSR-17
- Loading branch information
Joan Fabrégat
committed
Oct 8, 2018
1 parent
bd7eaa7
commit 5d66240
Showing
15 changed files
with
216 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,53 +3,36 @@ | |
// +---------------------------------------------------------------------+ | ||
// | CODE INC. SOURCE CODE | | ||
// +---------------------------------------------------------------------+ | ||
// | Copyright (c) 2017 - Code Inc. SAS - All Rights Reserved. | | ||
// | Copyright (c) 2018 - Code Inc. SAS - All Rights Reserved. | | ||
// | Visit https://www.codeinc.fr for more information about licensing. | | ||
// +---------------------------------------------------------------------+ | ||
// | NOTICE: All information contained herein is, and remains the | | ||
// | property of Code Inc. SAS. The intellectual and technical concepts | | ||
// | contained herein are proprietary to Code Inc. SAS are protected by | | ||
// | trade secret or copyright law. Dissemination of this information or | | ||
// | reproduction of this material is strictly forbidden unless prior | | ||
// | reproduction of this material is strictly forbidden unless prior | | ||
// | written permission is obtained from Code Inc. SAS. | | ||
// +---------------------------------------------------------------------+ | ||
// | ||
// Author: Joan Fabrégat <[email protected]> | ||
// Date: 04/03/2018 | ||
// Time: 11:55 | ||
// Date: 08/10/2018 | ||
// Project: Psr7Responses | ||
// | ||
declare(strict_types = 1); | ||
declare(strict_types=1); | ||
namespace CodeInc\Psr7Responses; | ||
use CodeInc\Psr7Responses\Tests\DebugResponseTest; | ||
|
||
|
||
/** | ||
* Class DebugResponse | ||
* Interface CharsetResponseInterface | ||
* | ||
* @see DebugResponseTest | ||
* @package CodeInc\Psr7Responses | ||
* @author Joan Fabrégat <[email protected]> | ||
* @license MIT <https://github.com/CodeIncHQ/Psr7Responses/blob/master/LICENSE> | ||
* @link https://github.com/CodeIncHQ/Psr7Responses | ||
*/ | ||
class DebugResponse extends HtmlResponse | ||
interface CharsetResponseInterface | ||
{ | ||
/** | ||
* DebugResponse constructor. | ||
* | ||
* @param $debugInfos | ||
* @param null|string $charset | ||
* @param int $status | ||
* @param array $headers | ||
* @param string $version | ||
* @param null|string $reason | ||
*/ | ||
public function __construct($debugInfos, ?string $charset = null, int $status = 200, array $headers = [], | ||
string $version = '1.1', ?string $reason = null) | ||
{ | ||
ob_start(); | ||
var_dump($debugInfos); | ||
parent::__construct(ob_get_clean(), $charset, $status, $headers, $version, $reason); | ||
} | ||
/** | ||
* Returns the response's charset. | ||
* | ||
* @return string | ||
*/ | ||
public function getCharset():string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,9 @@ | |
* @uses ErrorResponseTest | ||
* @package CodeInc\Psr7Responses | ||
* @author Joan Fabrégat <[email protected]> | ||
* @license MIT <https://github.com/CodeIncHQ/Psr7Responses/blob/master/LICENSE> | ||
* @link https://github.com/CodeIncHQ/Psr7Responses | ||
* @version 2 | ||
*/ | ||
class ErrorResponse extends HtmlResponse | ||
{ | ||
|
@@ -39,23 +42,29 @@ class ErrorResponse extends HtmlResponse | |
*/ | ||
private $error; | ||
|
||
/** | ||
* ErrorResponse constructor. | ||
* | ||
* @param \Throwable $error | ||
* @param null|string $charset | ||
* @param int $status | ||
* @param array $headers | ||
* @param string $version | ||
* @param null|string $reason | ||
*/ | ||
public function __construct(\Throwable $error, ?string $charset = null, | ||
int $status = 500, array $headers = [], string $version = '1.1', | ||
?string $reason = null) | ||
/** | ||
* ErrorResponse constructor. | ||
* | ||
* @param \Throwable $error | ||
* @param int $code | ||
* @param string $reasonPhrase | ||
* @param string $charset | ||
* @param array $headers | ||
* @param string $version | ||
* @throws \ReflectionException | ||
*/ | ||
public function __construct(\Throwable $error, int $code = 200, string $reasonPhrase = '', | ||
string $charset = 'utf-8', array $headers = [], string $version = '1.1') | ||
{ | ||
$this->error = $error; | ||
parent::__construct((new HtmlErrorRenderer($error))->get(), | ||
$charset, $status, $headers, $version, $reason); | ||
parent::__construct( | ||
(new HtmlErrorRenderer($error))->get(), | ||
$code, | ||
$reasonPhrase, | ||
$charset, | ||
$headers, | ||
$version | ||
); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,27 +32,27 @@ | |
* @see FileResponseTest | ||
* @package CodeInc\Psr7Responses | ||
* @author Joan Fabrégat <[email protected]> | ||
* @license MIT <https://github.com/CodeIncHQ/Psr7Responses/blob/master/LICENSE> | ||
* @link https://github.com/CodeIncHQ/Psr7Responses | ||
* @version 2 | ||
*/ | ||
class FileResponse extends StreamResponse | ||
{ | ||
public const DEFAULT_MIME_TYPE = 'application/octet-stream'; | ||
|
||
/** | ||
* FileResponse constructor. | ||
* | ||
* @param string|resource|StreamInterface $file | ||
* @param null|string $fileName | ||
* @param string $fileName | ||
* @param int $code | ||
* @param string $reasonPhrase | ||
* @param null|string $contentType | ||
* @param bool $asAttachment | ||
* @param int $status | ||
* @param array $headers | ||
* @param string $version | ||
* @param null|string $reason | ||
* @throws \CodeInc\MediaTypes\Exceptions\MediaTypesException | ||
*/ | ||
public function __construct($file, string $fileName, ?string $contentType = null, | ||
bool $asAttachment = true, int $status = 200, array $headers = [], | ||
string $version = '1.1', ?string $reason = null) | ||
public function __construct($file, string $fileName, int $code = 200, string $reasonPhrase = '', | ||
?string $contentType = null, bool $asAttachment = true, array $headers = [], string $version = '1.1') | ||
{ | ||
if (is_string($file)) { | ||
if (!is_file($file)) { | ||
|
@@ -75,14 +75,14 @@ public function __construct($file, string $fileName, ?string $contentType = null | |
|
||
parent::__construct( | ||
$stream, | ||
$contentType ?? MediaTypes::getFilenameMediaType($fileName, self::DEFAULT_MIME_TYPE), | ||
$code, | ||
$reasonPhrase, | ||
$contentType ?? MediaTypes::getFilenameMediaType($fileName, 'application/octet-stream'), | ||
null, | ||
$fileName, | ||
$asAttachment, | ||
$status, | ||
$headers, | ||
$version, | ||
$reason | ||
$version | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,38 +31,37 @@ | |
* @author Joan Fabrégat <[email protected]> | ||
* @license MIT <https://github.com/CodeIncHQ/Psr7Responses/blob/master/LICENSE> | ||
* @link https://github.com/CodeIncHQ/Psr7Responses | ||
* @version 2 | ||
*/ | ||
class HtmlResponse extends Response | ||
class HtmlResponse extends Response implements CharsetResponseInterface | ||
{ | ||
public const DEFAULT_CHARSET = "utf-8"; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $html; | ||
|
||
/** | ||
* @var null|string | ||
* @var string | ||
*/ | ||
private $charset; | ||
|
||
/** | ||
* HtmlResponse constructor. | ||
* | ||
* @param string $html | ||
* @param null|string $charset | ||
* @param int $status | ||
* @param array $headers | ||
* @param string $version | ||
* @param null|string $reason | ||
*/ | ||
public function __construct(string $html, ?string $charset = null, int $status = 200, array $headers = [], | ||
string $version = '1.1', ?string $reason = null) | ||
/** | ||
* HtmlResponse constructor. | ||
* | ||
* @param string $html | ||
* @param int $code | ||
* @param string $reasonPhrase | ||
* @param string $charset | ||
* @param array $headers | ||
* @param string $version | ||
*/ | ||
public function __construct(string $html, int $code = 200, string $reasonPhrase = '', | ||
string $charset = 'utf-8', array $headers = [], string $version = '1.1') | ||
{ | ||
$headers["Content-Type"] = "text/html; charset=".($charset ?? self::DEFAULT_CHARSET); | ||
$headers['Content-Type'] = sprintf('text/html; charset=%s', $charset); | ||
$this->html = $html; | ||
$this->charset = $charset; | ||
parent::__construct($status, $headers, $html, $version, $reason); | ||
parent::__construct($code, $headers, $html, $version, $reasonPhrase); | ||
} | ||
|
||
/** | ||
|
@@ -76,9 +75,10 @@ public function getHtml():string | |
} | ||
|
||
/** | ||
* @return null|string | ||
* @inheritdoc | ||
* @return string | ||
*/ | ||
public function getCharset():?string | ||
public function getCharset():string | ||
{ | ||
return $this->charset; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
* @author Joan Fabrégat <[email protected]> | ||
* @license MIT <https://github.com/CodeIncHQ/Psr7Responses/blob/master/LICENSE> | ||
* @link https://github.com/CodeIncHQ/Psr7Responses | ||
* @version 2 | ||
*/ | ||
class HttpProxyResponse extends Response | ||
{ | ||
|
@@ -59,31 +60,13 @@ class HttpProxyResponse extends Response | |
* ProxyResponse constructor. | ||
* | ||
* @param string $remoteUrl | ||
* @param int $status | ||
* @param int $code | ||
* @param string $reasonPhrase | ||
* @param array $headers | ||
* @param string $version | ||
* @param null|string $reason | ||
* @throws ResponseException | ||
*/ | ||
public function __construct(string $remoteUrl, int $status = 200, array $headers = [], | ||
string $version = '1.1', ?string $reason = null) | ||
{ | ||
$this->setRemoteUrl($remoteUrl); | ||
|
||
parent::__construct( | ||
$status, | ||
$this->importHttpHeader($headers), | ||
$this->getStream(), | ||
$version, | ||
$reason | ||
); | ||
} | ||
|
||
/** | ||
* @param string $remoteUrl | ||
* @throws ResponseException | ||
*/ | ||
private function setRemoteUrl(string $remoteUrl):void | ||
public function __construct(string $remoteUrl, int $code = 200, string $reasonPhrase = '', | ||
array $headers = [], string $version = '1.1') | ||
{ | ||
if (!filter_var($remoteUrl, FILTER_VALIDATE_URL)) { | ||
throw new ResponseException( | ||
|
@@ -92,6 +75,14 @@ private function setRemoteUrl(string $remoteUrl):void | |
); | ||
} | ||
$this->remoteUrl = $remoteUrl; | ||
|
||
parent::__construct( | ||
$code, | ||
$this->importHttpHeader($headers), | ||
$this->getStream(), | ||
$version, | ||
$reasonPhrase | ||
); | ||
} | ||
|
||
/** | ||
|
Oops, something went wrong.