mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 23:00:28 -04:00
Rename function
This commit is contained in:
parent
70ae877dd8
commit
a4910b8d67
5 changed files with 13 additions and 9 deletions
|
@ -4,10 +4,11 @@ use function Safe\preg_match;
|
||||||
|
|
||||||
class HttpInput{
|
class HttpInput{
|
||||||
/**
|
/**
|
||||||
|
* Check that the request's HTTP method is in a list of allowed HTTP methods.
|
||||||
* @param ?array<HttpMethod> $allowedHttpMethods An array containing a list of allowed HTTP methods, or null if any valid HTTP method is allowed.
|
* @param ?array<HttpMethod> $allowedHttpMethods An array containing a list of allowed HTTP methods, or null if any valid HTTP method is allowed.
|
||||||
* @param bool $throwException If true, in case of errors throw an exception; if false, in case of errors output HTTP 405 and exit the script immediately.
|
* @param bool $throwException If the request HTTP method isn't allowed, then throw an exception; otherwise, output HTTP 405 and exit the script immediately.
|
||||||
* @throws Exceptions\InvalidHttpMethodException If the HTTP method is not recognized.
|
* @throws Exceptions\InvalidHttpMethodException If the HTTP method is not recognized and `$throwException` is `true`.
|
||||||
* @throws Exceptions\HttpMethodNotAllowedException If the HTTP method is not in the list of allowed methods.
|
* @throws Exceptions\HttpMethodNotAllowedException If the HTTP method is not in the list of allowed methods and `$throwException` is `true`.
|
||||||
*/
|
*/
|
||||||
public static function ValidateRequestMethod(?array $allowedHttpMethods = null, bool $throwException = false): HttpMethod{
|
public static function ValidateRequestMethod(?array $allowedHttpMethods = null, bool $throwException = false): HttpMethod{
|
||||||
try{
|
try{
|
||||||
|
@ -46,7 +47,10 @@ class HttpInput{
|
||||||
return $requestMethod;
|
return $requestMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function GetMaxPostSize(): int{ // bytes
|
/**
|
||||||
|
* @return int The maximum size for an HTTP POST request, in bytes
|
||||||
|
*/
|
||||||
|
public static function GetMaxPostSize(): int{
|
||||||
$post_max_size = ini_get('post_max_size');
|
$post_max_size = ini_get('post_max_size');
|
||||||
$unit = substr($post_max_size, -1);
|
$unit = substr($post_max_size, -1);
|
||||||
$size = (int) substr($post_max_size, 0, -1);
|
$size = (int) substr($post_max_size, 0, -1);
|
||||||
|
@ -69,7 +73,7 @@ class HttpInput{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function RequestType(): HttpRequestType{
|
public static function GetRequestType(): HttpRequestType{
|
||||||
return preg_match('/\btext\/html\b/ius', $_SERVER['HTTP_ACCEPT'] ?? '') ? HttpRequestType::Web : HttpRequestType::Rest;
|
return preg_match('/\btext\/html\b/ius', $_SERVER['HTTP_ACCEPT'] ?? '') ? HttpRequestType::Web : HttpRequestType::Rest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ try{
|
||||||
// We may use GET if we're called from an unsubscribe link in an email
|
// We may use GET if we're called from an unsubscribe link in an email
|
||||||
HttpInput::ValidateRequestMethod([HttpMethod::Get, HttpMethod::Delete]);
|
HttpInput::ValidateRequestMethod([HttpMethod::Get, HttpMethod::Delete]);
|
||||||
|
|
||||||
$requestType = HttpInput::RequestType();
|
$requestType = HttpInput::GetRequestType();
|
||||||
|
|
||||||
$subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid'));
|
$subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid'));
|
||||||
$subscription->Delete();
|
$subscription->Delete();
|
||||||
|
|
|
@ -7,7 +7,7 @@ try{
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
$requestType = HttpInput::RequestType();
|
$requestType = HttpInput::GetRequestType();
|
||||||
|
|
||||||
$subscription = new NewsletterSubscription();
|
$subscription = new NewsletterSubscription();
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ try{
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
$requestType = HttpInput::RequestType();
|
$requestType = HttpInput::GetRequestType();
|
||||||
|
|
||||||
$vote = new PollVote();
|
$vote = new PollVote();
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ try{
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
$requestType = HttpInput::RequestType();
|
$requestType = HttpInput::GetRequestType();
|
||||||
|
|
||||||
$session = new Session();
|
$session = new Session();
|
||||||
$email = HttpInput::Str(POST, 'email');
|
$email = HttpInput::Str(POST, 'email');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue