From a4910b8d67ebfea3119cf4119997983bb1c5f394 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Mon, 13 May 2024 10:57:16 -0500 Subject: [PATCH] Rename function --- lib/HttpInput.php | 14 +++++++++----- www/newsletter/subscriptions/delete.php | 2 +- www/newsletter/subscriptions/post.php | 2 +- www/polls/votes/post.php | 2 +- www/sessions/post.php | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/HttpInput.php b/lib/HttpInput.php index c701f1ed..cd35e42b 100644 --- a/lib/HttpInput.php +++ b/lib/HttpInput.php @@ -4,10 +4,11 @@ use function Safe\preg_match; class HttpInput{ /** + * Check that the request's HTTP method is in a list of allowed HTTP methods. * @param ?array $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. - * @throws Exceptions\InvalidHttpMethodException If the HTTP method is not recognized. - * @throws Exceptions\HttpMethodNotAllowedException If the HTTP method is not in the list of allowed methods. + * @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 and `$throwException` is `true`. + * @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{ try{ @@ -46,7 +47,10 @@ class HttpInput{ 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'); $unit = substr($post_max_size, -1); $size = (int) substr($post_max_size, 0, -1); @@ -69,7 +73,7 @@ class HttpInput{ 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; } diff --git a/www/newsletter/subscriptions/delete.php b/www/newsletter/subscriptions/delete.php index 60f266f7..dca5d47d 100644 --- a/www/newsletter/subscriptions/delete.php +++ b/www/newsletter/subscriptions/delete.php @@ -3,7 +3,7 @@ try{ // We may use GET if we're called from an unsubscribe link in an email HttpInput::ValidateRequestMethod([HttpMethod::Get, HttpMethod::Delete]); - $requestType = HttpInput::RequestType(); + $requestType = HttpInput::GetRequestType(); $subscription = NewsletterSubscription::Get(HttpInput::Str(GET, 'uuid')); $subscription->Delete(); diff --git a/www/newsletter/subscriptions/post.php b/www/newsletter/subscriptions/post.php index 3beae6b9..c290831c 100644 --- a/www/newsletter/subscriptions/post.php +++ b/www/newsletter/subscriptions/post.php @@ -7,7 +7,7 @@ try{ session_start(); - $requestType = HttpInput::RequestType(); + $requestType = HttpInput::GetRequestType(); $subscription = new NewsletterSubscription(); diff --git a/www/polls/votes/post.php b/www/polls/votes/post.php index 9d5c345f..502a6186 100644 --- a/www/polls/votes/post.php +++ b/www/polls/votes/post.php @@ -6,7 +6,7 @@ try{ session_start(); - $requestType = HttpInput::RequestType(); + $requestType = HttpInput::GetRequestType(); $vote = new PollVote(); diff --git a/www/sessions/post.php b/www/sessions/post.php index 28523f79..82690deb 100644 --- a/www/sessions/post.php +++ b/www/sessions/post.php @@ -6,7 +6,7 @@ try{ session_start(); - $requestType = HttpInput::RequestType(); + $requestType = HttpInput::GetRequestType(); $session = new Session(); $email = HttpInput::Str(POST, 'email');