Skip to content

Commit 4960652

Browse files
committed
IRequest, IResponse: added typehints, unification (BC break)
1 parent 0d82d44 commit 4960652

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

src/Http/IRequest.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,19 @@ function getUrl(): UrlScript;
5858
/**
5959
* Returns variable provided to the script via URL query ($_GET).
6060
* If no key is passed, returns the entire array.
61-
* @return mixed
6261
*/
63-
function getQuery(?string $key = null);
62+
function getQuery(?string $key = null): mixed;
6463

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

7270
/**
7371
* Returns uploaded file.
74-
* @return FileUpload|array|null
7572
*/
76-
function getFile(string $key);
73+
function getFile(string $key): ?FileUpload;
7774

7875
/**
7976
* Returns uploaded files.
@@ -82,9 +79,8 @@ function getFiles(): array;
8279

8380
/**
8481
* Returns variable provided to the script via HTTP cookies.
85-
* @return mixed
8682
*/
87-
function getCookie(string $key);
83+
function getCookie(string $key): mixed;
8884

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

src/Http/IResponse.php

+15-15
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
?int $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

+4-4
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ public function setCookie(
233233
?string $path = null,
234234
?string $domain = null,
235235
?bool $secure = null,
236-
?bool $httpOnly = null,
237-
?string $sameSite = null,
236+
bool $httpOnly = true,
237+
string $sameSite = self::SameSiteLax,
238238
): static
239239
{
240240
self::checkHeaders();
@@ -243,8 +243,8 @@ public function setCookie(
243243
'path' => $path ?? ($domain ? '/' : $this->cookiePath),
244244
'domain' => $domain ?? ($path ? '' : $this->cookieDomain),
245245
'secure' => $secure ?? $this->cookieSecure,
246-
'httponly' => $httpOnly ?? true,
247-
'samesite' => $sameSite ?? self::SameSiteLax,
246+
'httponly' => $httpOnly,
247+
'samesite' => $sameSite,
248248
]);
249249
return $this;
250250
}

0 commit comments

Comments
 (0)