diff --git a/Message/Http/Header.php b/Message/Http/Header.php index 54d44150e..e2d6dd9bc 100644 --- a/Message/Http/Header.php +++ b/Message/Http/Header.php @@ -39,15 +39,7 @@ final class Header extends HeaderAbstract private array $header = []; /** - * Set header. - * - * @param string $key Header key (case insensitive) - * @param string $header Header value - * @param bool $overwrite Overwrite if already existing - * - * @return bool - * - * @since 1.0.0 + * {@inheritdoc} */ public function set(string $key, string $header, bool $overwrite = false) : bool { @@ -209,13 +201,7 @@ final class Header extends HeaderAbstract } /** - * Get header by name. - * - * @param string $key Header key - * - * @return array - * - * @since 1.0.0 + * {@inheritdoc} */ public function get(string $key = null) : array { @@ -223,13 +209,7 @@ final class Header extends HeaderAbstract } /** - * Check if header is defined. - * - * @param string $key Header key - * - * @return bool - * - * @since 1.0.0 + * {@inheritdoc} */ public function has(string $key) : bool { diff --git a/Message/Http/Request.php b/Message/Http/Request.php index 35dfb8c6f..34097c631 100644 --- a/Message/Http/Request.php +++ b/Message/Http/Request.php @@ -33,6 +33,29 @@ use phpOMS\Uri\UriInterface; */ final class Request extends RequestAbstract { + /** + * Uri. + * + * @var UriInterface + * @since 1.0.0 + */ + protected UriInterface $uri; + + /** + * Request method. + * + * @var null|string + * @since 1.0.0 + */ + protected ?string $method = null; + + /** + * Request type. + * + * @var null|string + * @since 1.0.0 + */ + protected ?string $type = null; /** * Browser type. @@ -58,6 +81,22 @@ final class Request extends RequestAbstract */ private ?array $info = null; + /** + * Request hash. + * + * @var array + * @since 1.0.0 + */ + protected array $hash = []; + + /** + * Uploaded files. + * + * @var array + * @since 1.0.0 + */ + protected array $files = []; + /** * Constructor. * @@ -154,6 +193,45 @@ final class Request extends RequestAbstract } } + /** + * Get request uri. + * + * @return UriInterface + * + * @since 1.0.0 + */ + public function getUri() : UriInterface + { + return $this->uri; + } + + + /** + * Get request hash. + * + * @return array + * + * @since 1.0.0 + */ + public function getHash() : array + { + return $this->hash; + } + + /** + * Set request method. + * + * @param string $method Request method + * + * @return void + * + * @since 1.0.0 + */ + public function setMethod(string $method) : void + { + $this->method = $method; + } + /** * Get request language * @@ -198,6 +276,8 @@ final class Request extends RequestAbstract * * @return void * + * @todo: consider making this function static. + * * @since 1.0.0 */ private function cleanupGlobals() : void @@ -242,11 +322,17 @@ final class Request extends RequestAbstract } /** - * {@inheritdoc} + * Set request uri. + * + * @param UriInterface $uri Uri + * + * @return void + * + * @since 1.0.0 */ public function setUri(UriInterface $uri) : void { - parent::setUri($uri); + $this->uri = $uri; $this->data += $uri->getQueryArray(); } @@ -406,6 +492,8 @@ final class Request extends RequestAbstract * * @throws \OutOfRangeException This exception is thrown if the port is out of range * + * @todo: consider making this static + * * @since 1.0.0 */ public function isHttps(int $port = 443) : bool @@ -430,7 +518,11 @@ final class Request extends RequestAbstract } /** - * {@inheritdoc} + * Get route verb. + * + * @return int + * + * @since 1.0.0 */ public function getRouteVerb() : int { @@ -449,7 +541,11 @@ final class Request extends RequestAbstract } /** - * {@inheritdoc} + * Get request method. + * + * @return string + * + * @since 1.0.0 */ public function getMethod() : string { diff --git a/Message/Http/Response.php b/Message/Http/Response.php index ff0bcb882..6d015d9e1 100644 --- a/Message/Http/Response.php +++ b/Message/Http/Response.php @@ -32,14 +32,6 @@ use phpOMS\Views\View; */ final class Response extends ResponseAbstract implements RenderableInterface { - /** - * Response status. - * - * @var int - * @since 1.0.0 - */ - protected int $status = RequestStatusCode::R_200; - /** * Constructor. * diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index 93458bbf8..cc364824c 100644 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -26,30 +26,6 @@ use phpOMS\Uri\UriInterface; */ abstract class RequestAbstract implements MessageInterface { - /** - * Uri. - * - * @var UriInterface - * @since 1.0.0 - */ - protected UriInterface $uri; - - /** - * Request method. - * - * @var null|string - * @since 1.0.0 - */ - protected ?string $method = null; - - /** - * Request type. - * - * @var null|string - * @since 1.0.0 - */ - protected ?string $type = null; - /** * Request data. * @@ -58,22 +34,6 @@ abstract class RequestAbstract implements MessageInterface */ protected array $data = []; - /** - * Request hash. - * - * @var array - * @since 1.0.0 - */ - protected array $hash = []; - - /** - * Uploaded files. - * - * @var array - * @since 1.0.0 - */ - protected array $files = []; - /** * Request lock. * @@ -90,67 +50,6 @@ abstract class RequestAbstract implements MessageInterface */ protected HeaderAbstract $header; - /** - * Get request uri. - * - * @return UriInterface - * - * @since 1.0.0 - */ - public function getUri() : UriInterface - { - return $this->uri; - } - - /** - * Set request uri. - * - * @param UriInterface $uri Uri - * - * @return void - * - * @since 1.0.0 - */ - public function setUri(UriInterface $uri) : void - { - $this->uri = $uri; - } - - /** - * Get request hash. - * - * @return array - * - * @since 1.0.0 - */ - public function getHash() : array - { - return $this->hash; - } - - /** - * Get request method. - * - * @return string - * - * @since 1.0.0 - */ - abstract public function getMethod() : string; - - /** - * Set request method. - * - * @param string $method Request method - * - * @return void - * - * @since 1.0.0 - */ - public function setMethod(string $method) : void - { - $this->method = $method; - } - /** * Get data. * @@ -309,7 +208,9 @@ abstract class RequestAbstract implements MessageInterface } /** - * {@inheritdoc} + * Get the origin request source (IPv4/IPv6) + * + * @return string */ abstract public function getOrigin() : string; @@ -321,15 +222,6 @@ abstract class RequestAbstract implements MessageInterface return $this->uri->__toString(); } - /** - * Get route verb. - * - * @return int - * - * @since 1.0.0 - */ - abstract public function getRouteVerb() : int; - /** * Get files. * diff --git a/tests/Message/Http/ResponseTest.php b/tests/Message/Http/ResponseTest.php index 95d56917f..7825d263c 100644 --- a/tests/Message/Http/ResponseTest.php +++ b/tests/Message/Http/ResponseTest.php @@ -80,6 +80,21 @@ class ResponseTest extends \PHPUnit\Framework\TestCase self::assertEquals(\json_encode($data), $response->render()); } + public function testMinimizedRender() : void + { + $response = new Response(); + + $response->set('view', new class() extends \phpOMS\Views\View { + public function render(...$data) : string + { + return " view_string with
text
that has \n whitespaces and \n\nnew lines\n "; + } + }); + + $response->getHeader()->set('Content-Type', MimeType::M_HTML . '; charset=utf-8', true); + self::assertEquals('view_string with
text
that has whitespaces and new lines', $response->render(true)); + } + public function testInvalidResponseData() : void { $response = new Response(); diff --git a/tests/Message/RequestSourceTest.php b/tests/Message/RequestSourceTest.php deleted file mode 100644 index 99c91f356..000000000 --- a/tests/Message/RequestSourceTest.php +++ /dev/null @@ -1,34 +0,0 @@ -