* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class StatusCodeException extends RuntimeException { protected $statusCode; public function __construct($message, $statusCode, \Throwable $previous = null) { parent::__construct($message, 0, $previous); if (isset(Http::$codes[$statusCode])) { $this->statusCode = $statusCode; } else { throw new InvalidArgumentException('Invalid http status code'); } } public function getStatusCode() { return $this->statusCode; } public function isInformational() { return $this->statusCode >= 100 && $this->statusCode < 200; } public function isSuccessful() { return $this->statusCode >= 200 && $this->statusCode < 300; } public function isRedirection() { return $this->statusCode >= 300 && $this->statusCode < 400; } public function isClientError() { return $this->statusCode >= 400 && $this->statusCode < 500; } public function isServerError() { return $this->statusCode >= 500 && $this->statusCode < 600; } public static function throwOnRedirection(ResponseInterface $response) { $statusCode = $response->getStatusCode(); $location = $response->getHeader('Location'); switch ($statusCode) { case 301: throw new MovedPermanentlyException($location); case 302: throw new FoundException($location); case 303: throw new SeeOtherException($location); case 304: throw new NotModifiedException($location); case 307: throw new TemporaryRedirectException($location); } if ($statusCode >= 300 && $statusCode < 400) { throw new RedirectionException($statusCode); } } public static function throwOnError(ResponseInterface $response) { $code = $response->getStatusCode(); if ($code >= 400 && $code < 500) { self::throwOnClientError($response); } elseif ($code >= 500 && $code < 600) { self::throwOnServerError($response); } } public static function throwOnClientError(ResponseInterface $response) { $statusCode = $response->getStatusCode(); $message = $response->getReasonPhrase(); switch ($statusCode) { case 400: throw new BadRequestException($message); case 401: $parts = explode(' ', $response->getHeader('WWW-Authenticate'), 2); $type = isset($parts[0]) ? $parts[0] : null; $data = isset($parts[1]) ? $parts[1] : null; $params = []; if (!empty($data)) { $params = Authentication::decodeParameters($data); } throw new UnauthorizedException($message, $type, $params); case 403: throw new ForbiddenException($message); case 404: throw new NotFoundException($message); case 405: $allow = $response->getHeader('Allow'); $allow = explode(',', $allow); $allow = array_map('trim', $allow); $allow = array_filter($allow); throw new MethodNotAllowedException($message, $allow); case 406: throw new NotAcceptableException($message); case 409: throw new ConflictException($message); case 410: throw new GoneException($message); case 412: throw new PreconditionFailedException($message); case 415: throw new UnsupportedMediaTypeException($message); } if ($statusCode >= 400 && $statusCode < 500) { throw new ClientErrorException($message, $statusCode); } } public static function throwOnServerError(ResponseInterface $response) { $statusCode = $response->getStatusCode(); $message = $response->getReasonPhrase(); switch ($statusCode) { case 500: throw new InternalServerErrorException($message); case 501: throw new NotImplementedException($message); case 503: throw new ServiceUnavailableException($message); } if ($statusCode >= 500 && $statusCode < 600) { throw new ServerErrorException($message, $statusCode); } } } __halt_compiler();----SIGNATURE:----XEy7d8ZqJuT1ouC/zuRWmK2lh5n+zLX/4xgUAebBExRtwRSgsvukqlaJAEty0bZVDh7jkpqRtGljs0VKynJM6OlIJOTsk22PpLJ3EeXMlgxSxelXEMXmOT89UKYYGIJs9C9HqPbxvv22OyTg8KPAPdN9xVvoaLlP4A93LEXM6c9hR1HumSS8+0NE8eqEvuPDO7OuDZIh4Se47wCArvZpn+9NuTakLR5y96c9EfXL6nP1PfZzbqnM3xPDSfWrrk9jMHaqZX29jkw+7YSiXnlBw8wOv6+aaHu24W2KHa7xddPNM1LLbJyMo6tScCOXaovGQUfUa7iVcw5FhcnkvxDIpvqNs8zUg/Cf0FCGg0zhMp3/UBywmJIamIxJOk1GJWh5C88FfWNcoLv7kwR/SkKdGEIk+2lbee5/LER95BhYVHcz8IuKGK72lb4EDvqCbn1FgvZ8MEFblXaOmAnJBUmBE1X0QDWSNrub3RoujDufYaLvPO9vDzdFbMW5mWx6zTokbjC4//Ic9vzhtOYqHG03JrV1qG49IgmIAeUpYHakb7TVrE7kkywmTOEqy7GfphfstXY5Sn2xq7OPpzg4TgpMB6E+wlRD1QM3gcvJje2l//pzt28vopIZ5i1cs4NltfnZJlXi6Q2AgEl2kieeVgmOiAetI46gkqoakhfRghL4VLo=----ATTACHMENT:----OTE2NTk0MDExNjk0MzUyNSAxMjQzNjYzMDEzNDcxNjk0IDQ5NjU4MzQ1NTAwMTQ3NDc=