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.

38 lines
1.3 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage exception
  7. * @since 2012-11-11
  8. */
  9. class ErrorHTTPException extends GeneralException
  10. {
  11. protected $http_headers;
  12. public function __construct($message = "", $code = 0, Exception $previous = null)
  13. {
  14. $this->http_headers = array(
  15. 400 => 'HTTP/1.0 400 Bad Request',
  16. 402 => 'HTTP/1.0 402 Payment Required',
  17. 403 => 'HTTP/1.0 403 Forbidden',
  18. 404 => 'HTTP/1.0 404 Not Found',
  19. 410 => 'HTTP/1.0 410 Gone',
  20. 500 => 'HTTP/1.0 500 Internal Server Error',
  21. 501 => 'HTTP/1.0 501 Not Implemented',
  22. 503 => 'HTTP/1.0 503 Service Unavailable',
  23. );
  24. if ($code === 200) {
  25. throw new GeneralException('Can\'t send 200 via ErrorHTTPException', 0, $this);
  26. } elseif (!array_key_exists($code, $this->http_headers)) {
  27. throw new GeneralException('Incorrect HTTP code ' . $code . '.', 0, $this);
  28. }
  29. parent::__construct($message, $code, $previous);
  30. }
  31. public function getHTTPHeader()
  32. {
  33. return $this->http_headers[$this->code];
  34. }
  35. }