EXTMVC:
[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 protected $additionalHeaderData = array();
42
43 /**
44 * The HTTP status code
45 *
46 * @var integer
47 */
48 protected $statusCode = 200;
49
50 /**
51 * The HTTP status message
52 *
53 * @var string
54 */
55 protected $statusMessage = 'OK';
56
57 /**
58 * The standardized and other important HTTP Status messages
59 *
60 * @var array
61 */
62 protected $statusMessages = array(
63 100 => 'Continue',
64 101 => 'Switching Protocols',
65 102 => 'Processing', # RFC 2518
66 200 => 'OK',
67 201 => 'Created',
68 202 => 'Accepted',
69 203 => 'Non-Authoritative Information',
70 204 => 'No Content',
71 205 => 'Reset Content',
72 206 => 'Partial Content',
73 207 => 'Multi-Status',
74 300 => 'Multiple Choices',
75 301 => 'Moved Permanently',
76 302 => 'Found',
77 303 => 'See Other',
78 304 => 'Not Modified',
79 305 => 'Use Proxy',
80 307 => 'Temporary Redirect',
81 400 => 'Bad Request',
82 401 => 'Unauthorized',
83 402 => 'Payment Required',
84 403 => 'Forbidden',
85 404 => 'Not Found',
86 405 => 'Method Not Allowed',
87 406 => 'Not Acceptable',
88 407 => 'Proxy Authentication Required',
89 408 => 'Request Timeout',
90 409 => 'Conflict',
91 410 => 'Gone',
92 411 => 'Length Required',
93 412 => 'Precondition Failed',
94 413 => 'Request Entity Too Large',
95 414 => 'Request-URI Too Long',
96 415 => 'Unsupported Media Type',
97 416 => 'Requested Range Not Satisfiable',
98 417 => 'Expectation Failed',
99 500 => 'Internal Server Error',
100 501 => 'Not Implemented',
101 502 => 'Bad Gateway',
102 503 => 'Service Unavailable',
103 504 => 'Gateway Timeout',
104 505 => 'HTTP Version Not Supported',
105 507 => 'Insufficient Storage',
106 509 => 'Bandwidth Limit Exceeded',
107 );
108
109 /**
110 * Sets the HTTP status code and (optionally) a customized message.
111 *
112 * @param integer $code The status code
113 * @param string $message If specified, this message is sent instead of the standard message
114 * @return void
115 * @throws InvalidArgumentException if the specified status code is not valid
116 */
117 public function setStatus($code, $message = NULL) {
118 if (!is_int($code)) throw new InvalidArgumentException('The HTTP status code must be of type integer, ' . gettype($code) . ' given.', 1220526013);
119 if ($message === NULL && !isset($this->statusMessages[$code])) throw new InvalidArgumentException('No message found for HTTP status code "' . $code . '".', 1220526014);
120
121 $this->statusCode = $code;
122 $this->statusMessage = ($message === NULL) ? $this->statusMessages[$code] : $message;
123 }
124
125 /**
126 * Returns status code and status message.
127 *
128 * @return string The status code and status message, eg. "404 Not Found"
129 */
130 public function getStatus() {
131 return $this->statusCode . ' ' . $this->statusMessage;
132 }
133
134 /**
135 * Adds an additional header data (something like
136 * '<script src="myext/Resources/JavaScript/my.js" type="text/javascript"></script>'
137 * )
138 *
139 * @param string $additionalHeaderData The value additonal header
140 * @return void
141 */
142 public function addAdditionalHeaderData($additionalHeaderData) {
143 if (!is_string($additionalHeaderData)) throw new InvalidArgumentException('The additiona header data must be of type String, ' . gettype($additionalHeaderData) . ' given.', 1237370877);
144 $this->additionalHeaderData[] = $additionalHeaderData;
145 }
146
147 /**
148 * Returns the additional header data
149 *
150 * @return array The additional header data
151 */
152 public function getAdditionalHeaderData() {
153 return $this->additionalHeaderData;
154 }
155
156 }
157 ?>