Skip to content

Commit bedf2d3

Browse files
committed
IRequest, IResponse: added typehints, unification (BC break)
1 parent 67a3c21 commit bedf2d3

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

src/Http/IRequest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,19 @@ function getUrl(): UrlScript;
5959
/**
6060
* Returns variable provided to the script via URL query ($_GET).
6161
* If no key is passed, returns the entire array.
62-
* @return mixed
6362
*/
64-
function getQuery(?string $key = null);
63+
function getQuery(?string $key = null): mixed;
6564

6665
/**
6766
* Returns variable provided to the script via POST method ($_POST).
6867
* If no key is passed, returns the entire array.
69-
* @return mixed
7068
*/
71-
function getPost(?string $key = null);
69+
function getPost(?string $key = null): mixed;
7270

7371
/**
7472
* Returns uploaded file.
75-
* @return FileUpload|array|null
7673
*/
77-
function getFile(string $key);
74+
function getFile(string $key): ?FileUpload;
7875

7976
/**
8077
* Returns uploaded files.
@@ -83,9 +80,8 @@ function getFiles(): array;
8380

8481
/**
8582
* Returns variable provided to the script via HTTP cookies.
86-
* @return mixed
8783
*/
88-
function getCookie(string $key);
84+
function getCookie(string $key): mixed;
8985

9086
/**
9187
* Returns variables provided to the script via HTTP cookies.

src/Http/IResponse.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,8 @@ interface IResponse
337337

338338
/**
339339
* Sets HTTP response code.
340-
* @return static
341340
*/
342-
function setCode(int $code, ?string $reason = null);
341+
function setCode(int $code, ?string $reason = null): static;
343342

344343
/**
345344
* Returns HTTP response code.
@@ -348,21 +347,18 @@ function getCode(): int;
348347

349348
/**
350349
* Sends a HTTP header and replaces a previous one.
351-
* @return static
352350
*/
353-
function setHeader(string $name, string $value);
351+
function setHeader(string $name, string $value): static;
354352

355353
/**
356354
* Adds HTTP header.
357-
* @return static
358355
*/
359-
function addHeader(string $name, string $value);
356+
function addHeader(string $name, string $value): static;
360357

361358
/**
362359
* Sends a Content-type HTTP header.
363-
* @return static
364360
*/
365-
function setContentType(string $type, ?string $charset = null);
361+
function setContentType(string $type, ?string $charset = null): static;
366362

367363
/**
368364
* Redirects to a new URL.
@@ -371,9 +367,8 @@ function redirect(string $url, int $code = self::S302_Found): void;
371367

372368
/**
373369
* Sets the time (like '20 minutes') before a page cached on a browser expires, null means "must-revalidate".
374-
* @return static
375370
*/
376-
function setExpiration(?string $expire);
371+
function setExpiration(?string $expire): static;
377372

378373
/**
379374
* Checks if headers have been sent.
@@ -392,20 +387,25 @@ function getHeaders(): array;
392387

393388
/**
394389
* Sends a cookie.
395-
* @return static
396390
*/
397391
function setCookie(
398392
string $name,
399393
string $value,
400394
string|int|\DateTimeInterface|null $expire,
401395
?string $path = null,
402396
?string $domain = null,
403-
?bool $secure = null,
404-
?bool $httpOnly = null,
405-
);
397+
bool $secure = false,
398+
bool $httpOnly = true,
399+
string $sameSite = self::SameSiteLax,
400+
): static;
406401

407402
/**
408403
* Deletes a cookie.
409404
*/
410-
function deleteCookie(string $name, ?string $path = null, ?string $domain = null, ?bool $secure = null);
405+
function deleteCookie(
406+
string $name,
407+
?string $path = null,
408+
?string $domain = null,
409+
bool $secure = false,
410+
);
411411
}

src/Http/Response.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ public function setCookie(
235235
?string $path = null,
236236
?string $domain = null,
237237
?bool $secure = null,
238-
?bool $httpOnly = null,
239-
?string $sameSite = null,
238+
bool $httpOnly = true,
239+
string $sameSite = self::SameSiteLax,
240240
): static
241241
{
242242
self::checkHeaders();
@@ -245,8 +245,8 @@ public function setCookie(
245245
'path' => $path ?? ($domain ? '/' : $this->cookiePath),
246246
'domain' => $domain ?? ($path ? '' : $this->cookieDomain),
247247
'secure' => $secure ?? $this->cookieSecure,
248-
'httponly' => $httpOnly ?? true,
249-
'samesite' => $sameSite ?? self::SameSiteLax,
248+
'httponly' => $httpOnly,
249+
'samesite' => $sameSite,
250250
]);
251251
return $this;
252252
}

0 commit comments

Comments
 (0)