clienterroraction.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 $widgetOpts;
  38. public $scoped;
  39. public $title;
  40. public $minimal;
  41. public static $status = [
  42. 400 => 'Bad Request',
  43. 401 => 'Unauthorized',
  44. 402 => 'Payment Required',
  45. 403 => 'Forbidden',
  46. 404 => 'Not Found',
  47. 405 => 'Method Not Allowed',
  48. 406 => 'Not Acceptable',
  49. 407 => 'Proxy Authentication Required',
  50. 408 => 'Request Timeout',
  51. 409 => 'Conflict',
  52. 410 => 'Gone',
  53. 411 => 'Length Required',
  54. 412 => 'Precondition Failed',
  55. 413 => 'Request Entity Too Large',
  56. 414 => 'Request-URI Too Long',
  57. 415 => 'Unsupported Media Type',
  58. 416 => 'Requested Range Not Satisfiable',
  59. 417 => 'Expectation Failed'
  60. ];
  61. public function __construct($message = 'Error', $code = 400)
  62. {
  63. parent::__construct($message, $code);
  64. $this->default = 400;
  65. if (!$this->code || $this->code < 400 || $this->code > 499) {
  66. $this->code = $this->default;
  67. }
  68. if (!$this->message) {
  69. $this->message = "Client Error $this->code";
  70. }
  71. }
  72. /**
  73. * To specify additional HTTP headers for the action
  74. *
  75. * @return void
  76. */
  77. public function extraHeaders()
  78. {
  79. http_response_code($this->code);
  80. }
  81. /**
  82. * Page title.
  83. *
  84. * @return page title
  85. */
  86. public function title()
  87. {
  88. return @self::$status[$this->code];
  89. }
  90. }