You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
<?php
|
|
|
|
namespace App\Enums;
|
|
|
|
/**
|
|
* Custom HTTP status codes enum wrapper.
|
|
*/
|
|
class HttpStatus
|
|
{
|
|
public const OK = 200;
|
|
public const CREATED = 201;
|
|
public const NO_CONTENT = 204;
|
|
|
|
public const BAD_REQUEST = 400;
|
|
public const UNAUTHORIZED = 401;
|
|
public const FORBIDDEN = 403;
|
|
public const NOT_FOUND = 404;
|
|
public const UNPROCESSABLE_ENTITY = 422;
|
|
|
|
public const INTERNAL_SERVER_ERROR = 500;
|
|
|
|
/**
|
|
* Optional: Get status code description (for logging or debug).
|
|
*/
|
|
public static function getMessage(int $code): string
|
|
{
|
|
return match ($code) {
|
|
self::OK => 'OK',
|
|
self::CREATED => 'Created',
|
|
self::NO_CONTENT => 'No Content',
|
|
self::BAD_REQUEST => 'Bad Request',
|
|
self::UNAUTHORIZED => 'Unauthorized',
|
|
self::FORBIDDEN => 'Forbidden',
|
|
self::NOT_FOUND => 'Not Found',
|
|
self::UNPROCESSABLE_ENTITY => 'Unprocessable Entity',
|
|
self::INTERNAL_SERVER_ERROR => 'Internal Server Error',
|
|
default => 'Unknown Status',
|
|
};
|
|
}
|
|
}
|
|
|