clienterroraction.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Client error action.
  4. *
  5. * PHP version 5
  6. *
  7. * @category Action
  8. * @package StatusNet
  9. * @author Evan Prodromou <evan@status.net>
  10. * @author Zach Copley <zach@status.net>
  11. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  12. * @link http://status.net/
  13. *
  14. * StatusNet - the distributed open-source microblogging tool
  15. * Copyright (C) 2008-2010 StatusNet, Inc.
  16. *
  17. * This program is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * Class for displaying HTTP client errors
  33. *
  34. * @category Action
  35. * @package StatusNet
  36. * @author Zach Copley <zach@status.net>
  37. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  38. * @link http://status.net/
  39. */
  40. class ClientErrorAction extends ErrorAction
  41. {
  42. static $status = array(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. function __construct($message='Error', $code=400)
  61. {
  62. parent::__construct($message, $code);
  63. $this->default = 400;
  64. if (!$this->code || $this->code < 400 || $this->code > 499) {
  65. $this->code = $this->default;
  66. }
  67. if (!$this->message) {
  68. $this->message = "Client Error $this->code";
  69. }
  70. }
  71. /**
  72. * To specify additional HTTP headers for the action
  73. *
  74. * @return void
  75. */
  76. function extraHeaders()
  77. {
  78. $status_string = @self::$status[$this->code];
  79. header('HTTP/1.1 '.$this->code.' '.$status_string);
  80. }
  81. /**
  82. * Page title.
  83. *
  84. * @return page title
  85. */
  86. function title()
  87. {
  88. return @self::$status[$this->code];
  89. }
  90. }