git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

clienterroraction.php 3.07 KB
Newer Older
1 2 3 4 5 6 7
<?php
/**
 * Client error action.
 *
 * PHP version 5
 *
 * @category Action
8
 * @package  StatusNet
9 10
 * @author   Evan Prodromou <evan@status.net>
 * @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 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

31
if (!defined('GNUSOCIAL')) { exit(1); }
32 33 34 35 36

/**
 * Class for displaying HTTP client errors
 *
 * @category Action
37
 * @package  StatusNet
38
 * @author   Zach Copley <zach@status.net>
39
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
40
 * @link     http://status.net/
41 42 43
 */
class ClientErrorAction extends ErrorAction
{
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    static $status = array(400 => 'Bad Request',
                           401 => 'Unauthorized',
                           402 => 'Payment Required',
                           403 => 'Forbidden',
                           404 => 'Not Found',
                           405 => 'Method Not Allowed',
                           406 => 'Not Acceptable',
                           407 => 'Proxy Authentication Required',
                           408 => 'Request Timeout',
                           409 => 'Conflict',
                           410 => 'Gone',
                           411 => 'Length Required',
                           412 => 'Precondition Failed',
                           413 => 'Request Entity Too Large',
                           414 => 'Request-URI Too Long',
                           415 => 'Unsupported Media Type',
                           416 => 'Requested Range Not Satisfiable',
                           417 => 'Expectation Failed');

63 64 65 66 67
    function __construct($message='Error', $code=400)
    {
        parent::__construct($message, $code);
        $this->default = 400;

68
        if (!$this->code || $this->code < 400 || $this->code > 499) {
69 70 71
            $this->code = $this->default;
        }
        if (!$this->message) {
72 73
            $this->message = "Client Error $this->code";
        }
74
    }
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

    /**
     *  To specify additional HTTP headers for the action
     *
     *  @return void
     */
    function extraHeaders()
    {
        $status_string = @self::$status[$this->code];
        header('HTTP/1.1 '.$this->code.' '.$status_string);
    }

    /**
     * Page title.
     *
     * @return page title
     */

    function title()
    {
        return @self::$status[$this->code];
    }
97
}