]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/clienterroraction.php
move HTTP error code strings to class variables
[quix0rs-gnu-social.git] / lib / clienterroraction.php
1 <?php
2
3 /**
4  * Client error action.
5  *
6  * PHP version 5
7  *
8  * @category Action
9  * @package  StatusNet
10  * @author   Evan Prodromou <evan@status.net>
11  * @author   Zach Copley <zach@status.net>
12  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13  * @link     http://status.net/
14  *
15  * StatusNet - the distributed open-source microblogging tool
16  * Copyright (C) 2008, 2009, StatusNet, Inc.
17  *
18  * This program is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Affero General Public License as published by
20  * the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU Affero General Public License for more details.
27  *
28  * You should have received a copy of the GNU Affero General Public License
29  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30  */
31
32 if (!defined('STATUSNET') && !defined('LACONICA')) {
33     exit(1);
34 }
35
36 require_once INSTALLDIR.'/lib/error.php';
37
38 /**
39  * Class for displaying HTTP client errors
40  *
41  * @category Action
42  * @package  StatusNet
43  * @author   Zach Copley <zach@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45  * @link     http://status.net/
46  */
47 class ClientErrorAction extends ErrorAction
48 {
49     static $status = array(400 => 'Bad Request',
50                            401 => 'Unauthorized',
51                            402 => 'Payment Required',
52                            403 => 'Forbidden',
53                            404 => 'Not Found',
54                            405 => 'Method Not Allowed',
55                            406 => 'Not Acceptable',
56                            407 => 'Proxy Authentication Required',
57                            408 => 'Request Timeout',
58                            409 => 'Conflict',
59                            410 => 'Gone',
60                            411 => 'Length Required',
61                            412 => 'Precondition Failed',
62                            413 => 'Request Entity Too Large',
63                            414 => 'Request-URI Too Long',
64                            415 => 'Unsupported Media Type',
65                            416 => 'Requested Range Not Satisfiable',
66                            417 => 'Expectation Failed');
67
68     function __construct($message='Error', $code=400)
69     {
70         parent::__construct($message, $code);
71         $this->default = 400;
72     }
73
74     // XXX: Should these error actions even be invokable via URI?
75
76     function handle($args)
77     {
78         parent::handle($args);
79
80         $this->code = $this->trimmed('code');
81
82         if (!$this->code || $code < 400 || $code > 499) {
83             $this->code = $this->default;
84         }
85
86         $this->message = $this->trimmed('message');
87
88         if (!$this->message) {
89             $this->message = "Client Error $this->code";
90         }
91
92         $this->showPage();
93     }
94 }