aiblog/app/Constants/ApiCode.php
2024-11-17 11:30:01 +08:00

44 lines
No EOL
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Constants;
class ApiCode
{
public const SUCCESS = 200;
public const CREATED = 201;
public const ACCEPTED = 202;
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 METHOD_NOT_ALLOWED = 405;
public const UNPROCESSABLE_ENTITY = 422;
public const TOO_MANY_REQUESTS = 429;
public const SERVER_ERROR = 500;
public const SERVICE_UNAVAILABLE = 503;
public static function getMessage(int $code): string
{
return match ($code) {
self::SUCCESS => 'Success',
self::CREATED => 'Created',
self::ACCEPTED => 'Accepted',
self::NO_CONTENT => 'No Content',
self::BAD_REQUEST => 'Bad Request',
self::UNAUTHORIZED => 'Unauthorized',
self::FORBIDDEN => 'Forbidden',
self::NOT_FOUND => 'Not Found',
self::METHOD_NOT_ALLOWED => 'Method Not Allowed',
self::UNPROCESSABLE_ENTITY => 'Unprocessable Entity',
self::TOO_MANY_REQUESTS => 'Too Many Requests',
self::SERVER_ERROR => 'Server Error',
self::SERVICE_UNAVAILABLE => 'Service Unavailable',
default => 'Unknown Error',
};
}
}