* @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:----IVMlNVP5y8U8arjFoUxhLBP1Hh1W/kFjl7yDdPlQG2n+BIaYDmRo8nf8TiT5qmWtgyXB5ouqawzhMv8TqQo3hNV3zZmVlOuUFCDXQ/E/+QZXwQK8E7WmzmWXJsexQSmUmqDDbQhq/cnwyHzv7RG9U1/uxYMuw9sJ7eC1TiTvyqMnTjfJVL58L8kZWpssNNEn7+237pY2RV42CFRCqbOu7xvhD9kJ7yJQLQXcL5cBhLLuuFG1P1PE4/gBEG7wjRZE/ZI8d/8dDTYubXe0zpEUBVjYNR9lTbND2J4bLlCsVkXsXDoyqUxHJQnK4u6dTc4wQIfV/rUC3YSWZwDayg06Kdp82KOnWD/1Ahximow1O4L790BZeH1cO9TqQ+bSiyWmin81sVdEjnTXatFNlcAtgEstAMxgQp+c01rSo26nsquI1hGS5Nom5WG+xgNrNawXwbDktk3KY6H8sopUh+okuNjZp8OQm6mtg/6+aHwxLBiBcJDRoKaF4UyJhegoVqhjzXaPHTF8gZfKnobapYoQZ4bWA618eaRAte6CTQjK/JARrcgdtgXxLGTwxgiLy67viVDtCjLV4gCokl/D+kl4amsbIlFbjGTqBMIC87EWuF03oAHy3XF7p+8UrmOhVGlHulK6XCDl1oVwRMy5rh53V80HqzxcL5axRx44YM9Z1BU=----ATTACHMENT:----NTQ0NzE2MjkzNzUxMzE0NiA4MTMyMjA0MDU2NjE1MTA4IDU3ODA5MTI1NDM4NDU4NTc=