b8c6b0d63e44825b80d4adb01476eb3b2414724c
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Web / TX_EXTMVC_Web_Response.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * A web specific response implementation
27 *
28 * @package TYPO3
29 * @subpackage extmvc
30 * @version $ID:$
31 * @scope prototype
32 */
33 // SK: Please implement setHeader(), getHeaders() and sendHeaders() as it is in FLOW3 to send custom HTTP headers.
34 class TX_EXTMVC_Web_Response extends TX_EXTMVC_Response {
35
36 /**
37 * Additional header tags
38 *
39 * @var array
40 */
41 // SK: To be discussed: Is additionalHeaderData a better name?
42 protected $additionalHeaderTags = array();
43
44 /**
45 * The HTTP status code
46 *
47 * @var integer
48 */
49 protected $statusCode = 200;
50
51 /**
52 * The HTTP status message
53 *
54 * @var string
55 */
56 protected $statusMessage = 'OK';
57
58 /**
59 * The standardized and other important HTTP Status messages
60 *
61 * @var array
62 */
63 protected $statusMessages = array(
64 100 => 'Continue',
65 101 => 'Switching Protocols',
66 102 => 'Processing', # RFC 2518
67 200 => 'OK',
68 201 => 'Created',
69 202 => 'Accepted',
70 203 => 'Non-Authoritative Information',
71 204 => 'No Content',
72 205 => 'Reset Content',
73 206 => 'Partial Content',
74 207 => 'Multi-Status',
75 300 => 'Multiple Choices',
76 301 => 'Moved Permanently',
77 302 => 'Found',
78 303 => 'See Other',
79 304 => 'Not Modified',
80 305 => 'Use Proxy',
81 307 => 'Temporary Redirect',
82 400 => 'Bad Request',
83 401 => 'Unauthorized',
84 402 => 'Payment Required',
85 403 => 'Forbidden',
86 404 => 'Not Found',
87 405 => 'Method Not Allowed',
88 406 => 'Not Acceptable',
89 407 => 'Proxy Authentication Required',
90 408 => 'Request Timeout',
91 409 => 'Conflict',
92 410 => 'Gone',
93 411 => 'Length Required',
94 412 => 'Precondition Failed',
95 413 => 'Request Entity Too Large',
96 414 => 'Request-URI Too Long',
97 415 => 'Unsupported Media Type',
98 416 => 'Requested Range Not Satisfiable',
99 417 => 'Expectation Failed',
100 500 => 'Internal Server Error',
101 501 => 'Not Implemented',
102 502 => 'Bad Gateway',
103 503 => 'Service Unavailable',
104 504 => 'Gateway Timeout',
105 505 => 'HTTP Version Not Supported',
106 507 => 'Insufficient Storage',
107 509 => 'Bandwidth Limit Exceeded',
108 );
109
110 /**
111 * Sets the HTTP status code and (optionally) a customized message.
112 *
113 * @param integer $code The status code
114 * @param string $message If specified, this message is sent instead of the standard message
115 * @return void
116 * @throws InvalidArgumentException if the specified status code is not valid
117 */
118 public function setStatus($code, $message = NULL) {
119 if (!is_int($code)) throw new InvalidArgumentException('The HTTP status code must be of type integer, ' . gettype($code) . ' given.', 1220526013);
120 if ($message === NULL && !isset($this->statusMessages[$code])) throw new InvalidArgumentException('No message found for HTTP status code "' . $code . '".', 1220526014);
121
122 $this->statusCode = $code;
123 $this->statusMessage = ($message === NULL) ? $this->statusMessages[$code] : $message;
124 }
125
126 /**
127 * Returns status code and status message.
128 *
129 * @return string The status code and status message, eg. "404 Not Found"
130 */
131 public function getStatus() {
132 return $this->statusCode . ' ' . $this->statusMessage;
133 }
134
135 /**
136 * Adds an additional header data (something like
137 * '<script src="myext/Resources/JavaScript/my.js" type="text/javascript"></script>'
138 * )
139 *
140 * @param string $additionalHeaderData The value additonal header
141 * @return void
142 */
143 public function addAdditionalHeaderData($additionalHeaderData) {
144 if (!is_string($additionalHeaderData)) throw new InvalidArgumentException('The additiona header data must be of type String, ' . gettype($additionalHeaderData) . ' given.', 1237370877);
145 $this->additionalHeaderData[] = $additionalHeaderData;
146 }
147
148 /**
149 * Returns the additional header data
150 *
151 * @return array The additional header data
152 */
153 public function getAdditionalHeaderData() {
154 return $this->additionalHeaderData;
155 }
156
157 }
158 ?>