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.

39 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. 401 => 'HTTP/1.0 400 Access allowed only for registered users',
  17. 402 => 'HTTP/1.0 402 Payment Required',
  18. 403 => 'HTTP/1.0 403 Forbidden',
  19. 404 => 'HTTP/1.0 404 Not Found',
  20. 410 => 'HTTP/1.0 410 Gone',
  21. 500 => 'HTTP/1.0 500 Internal Server Error',
  22. 501 => 'HTTP/1.0 501 Not Implemented',
  23. 503 => 'HTTP/1.0 503 Service Unavailable',
  24. );
  25. if ($code === 200) {
  26. throw new GeneralException('Can\'t send 200 via ErrorHTTPException', 0, $this);
  27. } elseif (!array_key_exists($code, $this->http_headers)) {
  28. throw new GeneralException('Incorrect HTTP code ' . $code . '.', 0, $this);
  29. }
  30. parent::__construct($message, $code, $previous);
  31. }
  32. public function getHTTPHeader()
  33. {
  34. return $this->http_headers[$this->code];
  35. }
  36. }