Skip to content

Commit

Permalink
IRequest, IResponse: added typehints, unification (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 29, 2024
1 parent 0d82d44 commit 4960652
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
12 changes: 4 additions & 8 deletions src/Http/IRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,19 @@ function getUrl(): UrlScript;
/**
* Returns variable provided to the script via URL query ($_GET).
* If no key is passed, returns the entire array.
* @return mixed
*/
function getQuery(?string $key = null);
function getQuery(?string $key = null): mixed;

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

/**
* Returns uploaded file.
* @return FileUpload|array|null
*/
function getFile(string $key);
function getFile(string $key): ?FileUpload;

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

/**
* Returns variable provided to the script via HTTP cookies.
* @return mixed
*/
function getCookie(string $key);
function getCookie(string $key): mixed;

/**
* Returns variables provided to the script via HTTP cookies.
Expand Down
30 changes: 15 additions & 15 deletions src/Http/IResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,8 @@ interface IResponse

/**
* Sets HTTP response code.
* @return static
*/
function setCode(int $code, ?string $reason = null);
function setCode(int $code, ?string $reason = null): static;

/**
* Returns HTTP response code.
Expand All @@ -348,21 +347,18 @@ 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): static;

/**
* Adds HTTP header.
* @return static
*/
function addHeader(string $name, string $value);
function addHeader(string $name, string $value): static;

/**
* Sends a Content-type HTTP header.
* @return static
*/
function setContentType(string $type, ?string $charset = null);
function setContentType(string $type, ?string $charset = null): static;

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

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

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

/**
* Sends a cookie.
* @return static
*/
function setCookie(
string $name,
string $value,
?int $expire,
?string $path = null,
?string $domain = null,
?bool $secure = null,
?bool $httpOnly = null,
);
bool $secure = false,
bool $httpOnly = true,
string $sameSite = self::SameSiteLax,
): static;

/**
* 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 = false,
);
}
8 changes: 4 additions & 4 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public function setCookie(
?string $path = null,
?string $domain = null,
?bool $secure = null,
?bool $httpOnly = null,
?string $sameSite = null,
bool $httpOnly = true,
string $sameSite = self::SameSiteLax,
): static
{
self::checkHeaders();
Expand All @@ -243,8 +243,8 @@ public function setCookie(
'path' => $path ?? ($domain ? '/' : $this->cookiePath),
'domain' => $domain ?? ($path ? '' : $this->cookieDomain),
'secure' => $secure ?? $this->cookieSecure,
'httponly' => $httpOnly ?? true,
'samesite' => $sameSite ?? self::SameSiteLax,
'httponly' => $httpOnly,
'samesite' => $sameSite,
]);
return $this;
}
Expand Down

0 comments on commit 4960652

Please sign in to comment.