From 010a94432470b98c8779386da0258c6ac778e3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mor=C3=A1vek?= Date: Mon, 3 Dec 2018 23:15:34 +0100 Subject: [PATCH] Response, IResponse: unified API (BC break) --- src/Http/IResponse.php | 10 +++++----- src/Http/Response.php | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Http/IResponse.php b/src/Http/IResponse.php index a542aa17..83a783b1 100644 --- a/src/Http/IResponse.php +++ b/src/Http/IResponse.php @@ -88,7 +88,7 @@ interface IResponse * Sets HTTP response code. * @return static */ - function setCode(int $code); + function setCode(int $code, ?string $reason = null); /** * Returns HTTP response code. @@ -99,7 +99,7 @@ function getCode(): int; * Sends a HTTP header and replaces a previous one. * @return static */ - function setHeader(string $name, string $value); + function setHeader(string $name, ?string $value); /** * Adds HTTP header. @@ -111,7 +111,7 @@ function addHeader(string $name, string $value); * Sends a Content-type HTTP header. * @return static */ - function setContentType(string $type, string $charset = null); + function setContentType(string $type, ?string $charset = null); /** * Redirects to a new URL. @@ -144,10 +144,10 @@ function getHeaders(): array; * @param string|int|\DateTimeInterface $expire time, value 0 means "until the browser is closed" * @return static */ - function setCookie(string $name, string $value, $expire, string $path = null, string $domain = null, bool $secure = null, bool $httpOnly = null); + function setCookie(string $name, string $value, $expire, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null); /** * Deletes a cookie. */ - function deleteCookie(string $name, string $path = null, string $domain = null, bool $secure = null); + function deleteCookie(string $name, ?string $path = null, ?string $domain = null, ?bool $secure = null); } diff --git a/src/Http/Response.php b/src/Http/Response.php index 1d57f438..08c151fa 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -58,7 +58,7 @@ public function __construct() * @throws Nette\InvalidArgumentException if code is invalid * @throws Nette\InvalidStateException if HTTP headers have been sent */ - public function setCode(int $code, string $reason = null) + public function setCode(int $code, ?string $reason = null) { if ($code < 100 || $code > 599) { throw new Nette\InvalidArgumentException("Bad HTTP response '$code'."); @@ -129,7 +129,7 @@ public function addHeader(string $name, string $value) * @return static * @throws Nette\InvalidStateException if HTTP headers have been sent */ - public function setContentType(string $type, string $charset = null) + public function setContentType(string $type, ?string $charset = null) { $this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : '')); return $this; @@ -235,7 +235,7 @@ public function __destruct() * @return static * @throws Nette\InvalidStateException if HTTP headers have been sent */ - public function setCookie(string $name, string $value, $time, string $path = null, string $domain = null, bool $secure = null, bool $httpOnly = null, string $sameSite = null) + public function setCookie(string $name, string $value, $time, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null, ?string $sameSite = null) { self::checkHeaders(); $options = [ @@ -267,7 +267,7 @@ public function setCookie(string $name, string $value, $time, string $path = nul * Deletes a cookie. * @throws Nette\InvalidStateException if HTTP headers have been sent */ - public function deleteCookie(string $name, string $path = null, string $domain = null, bool $secure = null): void + public function deleteCookie(string $name, ?string $path = null, ?string $domain = null, ?bool $secure = null): void { $this->setCookie($name, '', 0, $path, $domain, $secure); }