]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/clienterroraction.php
Type-hint is array here.
[quix0rs-gnu-social.git] / lib / clienterroraction.php
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
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR . '/lib/error.php';
36
37 /**
38  * Class for displaying HTTP client errors
39  *
40  * @category Action
41  * @package  StatusNet
42  * @author   Zach Copley <zach@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
44  * @link     http://status.net/
45  */
46 class ClientErrorAction extends ErrorAction
47 {
48     static $status = array(400 => 'Bad Request',
49                            401 => 'Unauthorized',
50                            402 => 'Payment Required',
51                            403 => 'Forbidden',
52                            404 => 'Not Found',
53                            405 => 'Method Not Allowed',
54                            406 => 'Not Acceptable',
55                            407 => 'Proxy Authentication Required',
56                            408 => 'Request Timeout',
57                            409 => 'Conflict',
58                            410 => 'Gone',
59                            411 => 'Length Required',
60                            412 => 'Precondition Failed',
61                            413 => 'Request Entity Too Large',
62                            414 => 'Request-URI Too Long',
63                            415 => 'Unsupported Media Type',
64                            416 => 'Requested Range Not Satisfiable',
65                            417 => 'Expectation Failed');
66
67     function __construct($message='Error', $code=400)
68     {
69         parent::__construct($message, $code);
70         $this->default = 400;
71     }
72
73     // XXX: Should these error actions even be invokable via URI?
74
75     protected function handle()
76     {
77         parent::handle();
78
79         $this->code = $this->trimmed('code');
80
81         if (!$this->code || $code < 400 || $code > 499) {
82             $this->code = $this->default;
83         }
84
85         $this->message = $this->trimmed('message');
86
87         if (!$this->message) {
88             $this->message = "Client Error $this->code";
89         }
90
91         $this->showPage();
92     }
93
94     /**
95      *  To specify additional HTTP headers for the action
96      *
97      *  @return void
98      */
99     function extraHeaders()
100     {
101         $status_string = @self::$status[$this->code];
102         header('HTTP/1.1 '.$this->code.' '.$status_string);
103     }
104
105     /**
106      * Page title.
107      *
108      * @return page title
109      */
110
111     function title()
112     {
113         return @self::$status[$this->code];
114     }
115 }