clienterroraction.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Client error action.
  18. *
  19. * @category Action
  20. * @package GNUsocial
  21. * @author Evan Prodromou <evan@status.net>
  22. * @author Zach Copley <zach@status.net>
  23. * @copyright 2008-2010 StatusNet, Inc.
  24. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  25. */
  26. defined('GNUSOCIAL') || die();
  27. /**
  28. * Class for displaying HTTP client errors
  29. *
  30. * @category Action
  31. * @package GNUsocial
  32. * @author Zach Copley <zach@status.net>
  33. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  34. */
  35. class ClientErrorAction extends ErrorAction
  36. {
  37. public static $status = [
  38. 400 => 'Bad Request',
  39. 401 => 'Unauthorized',
  40. 402 => 'Payment Required',
  41. 403 => 'Forbidden',
  42. 404 => 'Not Found',
  43. 405 => 'Method Not Allowed',
  44. 406 => 'Not Acceptable',
  45. 407 => 'Proxy Authentication Required',
  46. 408 => 'Request Timeout',
  47. 409 => 'Conflict',
  48. 410 => 'Gone',
  49. 411 => 'Length Required',
  50. 412 => 'Precondition Failed',
  51. 413 => 'Request Entity Too Large',
  52. 414 => 'Request-URI Too Long',
  53. 415 => 'Unsupported Media Type',
  54. 416 => 'Requested Range Not Satisfiable',
  55. 417 => 'Expectation Failed'
  56. ];
  57. public function __construct($message = 'Error', $code = 400)
  58. {
  59. parent::__construct($message, $code);
  60. $this->default = 400;
  61. if (!$this->code || $this->code < 400 || $this->code > 499) {
  62. $this->code = $this->default;
  63. }
  64. if (!$this->message) {
  65. $this->message = "Client Error $this->code";
  66. }
  67. }
  68. /**
  69. * To specify additional HTTP headers for the action
  70. *
  71. * @return void
  72. */
  73. public function extraHeaders()
  74. {
  75. http_response_code($this->code);
  76. }
  77. /**
  78. * Page title.
  79. *
  80. * @return page title
  81. */
  82. public function title()
  83. {
  84. return @self::$status[$this->code];
  85. }
  86. }