Skip to content

Commit 61eee83

Browse files
committed
unification of Response and IResponse params (BC break)
1 parent d10d1a2 commit 61eee83

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/Http/IResponse.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
/**
1414
* HTTP response interface.
15-
* @method self deleteHeader(string $name)
1615
*/
1716
interface IResponse
1817
{
@@ -167,6 +166,11 @@ function setHeader(string $name, string $value): static;
167166
*/
168167
function addHeader(string $name, string $value): static;
169168

169+
/**
170+
* Deletes a previously sent HTTP header.
171+
*/
172+
function deleteHeader(string $name): static;
173+
170174
/**
171175
* Sends a Content-type HTTP header.
172176
*/
@@ -180,7 +184,7 @@ function redirect(string $url, int $code = self::S302_FOUND): void;
180184
/**
181185
* Sets the time (like '20 minutes') before a page cached on a browser expires, null means "must-revalidate".
182186
*/
183-
function setExpiration(?string $expire): static;
187+
function setExpiration(?string $expires): static;
184188

185189
/**
186190
* Checks if headers have been sent.
@@ -193,7 +197,7 @@ function isSent(): bool;
193197
function getHeader(string $header): ?string;
194198

195199
/**
196-
* Returns a associative array of headers to sent.
200+
* Returns an associative array of headers to sent.
197201
*/
198202
function getHeaders(): array;
199203

@@ -203,11 +207,12 @@ function getHeaders(): array;
203207
function setCookie(
204208
string $name,
205209
string $value,
206-
?int $expire,
210+
string|int|null $expires,
207211
?string $path = null,
208212
?string $domain = null,
209213
bool $secure = false,
210214
bool $httpOnly = true,
215+
string $sameSite = self::SAME_SITE_LAX,
211216
): static;
212217

213218
/**

src/Http/Response.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,18 @@ public function redirect(string $url, int $code = self::S302_FOUND): void
167167
* The parameter is either a time interval (as text) or `null`, which disables caching.
168168
* @throws Nette\InvalidStateException if HTTP headers have been sent
169169
*/
170-
public function setExpiration(?string $time): static
170+
public function setExpiration(?string $expires): static
171171
{
172172
$this->setHeader('Pragma', null);
173-
if (!$time) { // no cache
173+
if (!$expires) { // no cache
174174
$this->setHeader('Cache-Control', 's-maxage=0, max-age=0, must-revalidate');
175175
$this->setHeader('Expires', 'Mon, 23 Jan 1978 10:00:00 GMT');
176176
return $this;
177177
}
178178

179-
$time = DateTime::from($time);
180-
$this->setHeader('Cache-Control', 'max-age=' . ($time->format('U') - time()));
181-
$this->setHeader('Expires', Helpers::formatDate($time));
179+
$expires = DateTime::from($expires);
180+
$this->setHeader('Cache-Control', 'max-age=' . ($expires->format('U') - time()));
181+
$this->setHeader('Expires', Helpers::formatDate($expires));
182182
return $this;
183183
}
184184

@@ -246,7 +246,7 @@ public function __destruct()
246246
public function setCookie(
247247
string $name,
248248
string $value,
249-
string|int|\DateTimeInterface|null $time,
249+
string|int|null $expires,
250250
?string $path = null,
251251
?string $domain = null,
252252
?bool $secure = null,
@@ -255,7 +255,7 @@ public function setCookie(
255255
): static {
256256
self::checkHeaders();
257257
setcookie($name, $value, [
258-
'expires' => $time ? (int) DateTime::from($time)->format('U') : 0,
258+
'expires' => $expires ? (int) DateTime::from($expires)->format('U') : 0,
259259
'path' => $path ?? ($domain ? '/' : $this->cookiePath),
260260
'domain' => $domain ?? ($path ? '' : $this->cookieDomain),
261261
'secure' => $secure ?? $this->cookieSecure,

0 commit comments

Comments
 (0)