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