corpus/http

HTTP 状态码和异常

v1.2.0 2024-09-10 16:28 UTC

This package is auto-updated.

Last update: 2024-09-10 17:35:02 UTC


README

Latest Stable Version License ci.yml

HTTP 状态码和异常

需求

  • php: ^7.3 | ^8.0

安装

使用以下命令安装最新版本

composer require 'corpus/http'

文档

类: Corpus\Http\Exceptions\AbstractHttpException

所有 HTTP 异常类扩展的基本异常类

方法: AbstractHttpException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

方法: AbstractHttpException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

类: Corpus\Http\Exceptions\ClientError\AbstractClientErrorException

表示 4xx 类的异常的基本类

方法: AbstractClientErrorException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

方法: AbstractClientErrorException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

类: Corpus\Http\Exceptions\ClientError\BadRequestException

方法: BadRequestException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

方法: BadRequestException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

类: Corpus\Http\Exceptions\ClientError\ForbiddenException

方法: ForbiddenException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

方法: ForbiddenException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

类: Corpus\Http\Exceptions\ClientError\NotFoundException

方法: NotFoundException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

方法: NotFoundException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

类: Corpus\Http\Exceptions\ClientError\TooManyRequestsException

方法: TooManyRequestsException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

方法: TooManyRequestsException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

类: Corpus\Http\Exceptions\ClientError\UnauthorizedException

方法: UnauthorizedException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

方法: UnauthorizedException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

类: Corpus\Http\Exceptions\Redirection\AbstractLocationRedirectionHttpException

包含 "Location" 标头的 3xx 异常的基本类

方法: AbstractLocationRedirectionHttpException->__construct

function __construct(string $location [, string $message = '' [, ?\Throwable $previous = null]])

AbstractRedirectionHttpException 构造函数。

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • \Throwable | null $previous - [可选] 用于异常链的先前可抛出。

未记录的方法: AbstractLocationRedirectionHttpException->getLocation()

方法: AbstractLocationRedirectionHttpException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

类: Corpus\Http\Exceptions\Redirection\AbstractRedirectionHttpException

表示 3xx 类的异常的基本类

方法: AbstractRedirectionHttpException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

方法: AbstractRedirectionHttpException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

类: Corpus\Http\Exceptions\Redirection\FoundException

方法: FoundException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

方法: FoundException->__construct

function __construct(string $location [, string $message = '' [, ?\Throwable $previous = null]])

AbstractRedirectionHttpException 构造函数。

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • \Throwable | null $previous - [可选] 用于异常链的先前可抛出。

未记录的方法: FoundException->getLocation()

类: Corpus\Http\Exceptions\Redirection\SeeOtherException

方法: SeeOtherException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

方法: SeeOtherException->__construct

function __construct(string $location [, string $message = '' [, ?\Throwable $previous = null]])

AbstractRedirectionHttpException 构造函数。

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • \Throwable | null $previous - [可选] 用于异常链的先前可抛出。

未记录的方法: SeeOtherException->getLocation()

类: Corpus\Http\Exceptions\ServerError\AbstractServerErrorException

表示 5xx 类的异常的基本类

方法: AbstractServerErrorException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

方法: AbstractServerErrorException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

类: Corpus\Http\Exceptions\ServerError\InternalServerErrorException

方法: InternalServerErrorException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

方法: InternalServerErrorException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

类: Corpus\Http\Exceptions\Success\AbstractSuccessException

表示 2xx 类的异常的基本类

方法: AbstractSuccessException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

方法: AbstractSuccessException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

类: Corpus\Http\Exceptions\Success\NoContentException

方法: NoContentException->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码

方法: NoContentException->__construct

function __construct([ $message = '' [, ?\Throwable $previous = null]])

构造 *HttpException。

使用 HTTP 状态码作为基本异常代码。

参数
  • string $message

类: Corpus\Http\Status

<?php
namespace Corpus\Http;

class Status {
	public const StatusContinue = 100;
	public const SwitchingProtocols = 101;
	public const Processing = 102;
	public const EarlyHints = 103;
	public const OK = 200;
	public const Created = 201;
	public const Accepted = 202;
	public const NonAuthoritativeInfo = 203;
	public const NoContent = 204;
	public const ResetContent = 205;
	public const PartialContent = 206;
	public const MultiStatus = 207;
	public const AlreadyReported = 208;
	public const IMUsed = 226;
	public const MultipleChoices = 300;
	public const MovedPermanently = 301;
	public const Found = 302;
	public const SeeOther = 303;
	public const NotModified = 304;
	public const UseProxy = 305;
	public const TemporaryRedirect = 307;
	public const PermanentRedirect = 308;
	public const BadRequest = 400;
	public const Unauthorized = 401;
	public const PaymentRequired = 402;
	public const Forbidden = 403;
	public const NotFound = 404;
	public const MethodNotAllowed = 405;
	public const NotAcceptable = 406;
	public const ProxyAuthRequired = 407;
	public const RequestTimeout = 408;
	public const Conflict = 409;
	public const Gone = 410;
	public const LengthRequired = 411;
	public const PreconditionFailed = 412;
	public const RequestEntityTooLarge = 413;
	public const RequestURITooLong = 414;
	public const UnsupportedMediaType = 415;
	public const RequestedRangeNotSatisfiable = 416;
	public const ExpectationFailed = 417;
	public const Teapot = 418;
	public const MisdirectedRequest = 421;
	public const UnprocessableEntity = 422;
	public const Locked = 423;
	public const FailedDependency = 424;
	public const TooEarly = 425;
	public const UpgradeRequired = 426;
	public const PreconditionRequired = 428;
	public const TooManyRequests = 429;
	public const RequestHeaderFieldsTooLarge = 431;
	public const UnavailableForLegalReasons = 451;
	public const InternalServerError = 500;
	public const NotImplemented = 501;
	public const BadGateway = 502;
	public const ServiceUnavailable = 503;
	public const GatewayTimeout = 504;
	public const HTTPVersionNotSupported = 505;
	public const VariantAlsoNegotiates = 506;
	public const InsufficientStorage = 507;
	public const LoopDetected = 508;
	public const NotExtended = 510;
	public const NetworkAuthenticationRequired = 511;
	/**
	 * @var array<int,string>
	 */
	public static $statusText = [self::StatusContinue => 'Continue', self::SwitchingProtocols => 'Switching Protocols', self::Processing => 'Processing', self::EarlyHints => 'Early Hints', self::OK => 'OK', self::Created => 'Created', self::Accepted => 'Accepted', self::NonAuthoritativeInfo => 'Non-Authoritative Information', self::NoContent => 'No Content', self::ResetContent => 'Reset Content', self::PartialContent => 'Partial Content', self::MultiStatus => 'Multi-Status', self::AlreadyReported => 'Already Reported', self::IMUsed => 'IM Used', self::MultipleChoices => 'Multiple Choices', self::MovedPermanently => 'Moved Permanently', self::Found => 'Found', self::SeeOther => 'See Other', self::NotModified => 'Not Modified', self::UseProxy => 'Use Proxy', self::TemporaryRedirect => 'Temporary Redirect', self::PermanentRedirect => 'Permanent Redirect', self::BadRequest => 'Bad Request', self::Unauthorized => 'Unauthorized', self::PaymentRequired => 'Payment Required', self::Forbidden => 'Forbidden', self::NotFound => 'Not Found', self::MethodNotAllowed => 'Method Not Allowed', self::NotAcceptable => 'Not Acceptable', self::ProxyAuthRequired => 'Proxy Authentication Required', self::RequestTimeout => 'Request Timeout', self::Conflict => 'Conflict', self::Gone => 'Gone', self::LengthRequired => 'Length Required', self::PreconditionFailed => 'Precondition Failed', self::RequestEntityTooLarge => 'Request Entity Too Large', self::RequestURITooLong => 'Request URI Too Long', self::UnsupportedMediaType => 'Unsupported Media Type', self::RequestedRangeNotSatisfiable => 'Requested Range Not Satisfiable', self::ExpectationFailed => 'Expectation Failed', self::Teapot => 'I\'m a teapot', self::MisdirectedRequest => 'Misdirected Request', self::UnprocessableEntity => 'Unprocessable Entity', self::Locked => 'Locked', self::FailedDependency => 'Failed Dependency', self::TooEarly => 'Too Early', self::UpgradeRequired => 'Upgrade Required', self::PreconditionRequired => 'Precondition Required', self::TooManyRequests => 'Too Many Requests', self::RequestHeaderFieldsTooLarge => 'Request Header Fields Too Large', self::UnavailableForLegalReasons => 'Unavailable For Legal Reasons', self::InternalServerError => 'Internal Server Error', self::NotImplemented => 'Not Implemented', self::BadGateway => 'Bad Gateway', self::ServiceUnavailable => 'Service Unavailable', self::GatewayTimeout => 'Gateway Timeout', self::HTTPVersionNotSupported => 'HTTP Version Not Supported', self::VariantAlsoNegotiates => 'Variant Also Negotiates', self::InsufficientStorage => 'Insufficient Storage', self::LoopDetected => 'Loop Detected', self::NotExtended => 'Not Extended', self::NetworkAuthenticationRequired => 'Network Authentication Required'];
}

方法: Status::statusText

function statusText(int $code) : ?string

返回 HTTP 状态码的文本。

类: Corpus\Http\StatusAwareInterface

方法: StatusAwareInterface->getHttpStatusCode

function getHttpStatusCode() : int

获取异常表示的 HTTP 状态码