Skip to content
Newer
Older
100644 892 lines (804 sloc) 22.9 KB
0218245 @fabpot [RequestHandler] added the Request Handler component
fabpot authored Feb 17, 2010
1 <?php
2
3 /*
c1e357d @pborreli Fixed @package and @subpackage phpdoc tags
pborreli authored Apr 6, 2010
4 * This file is part of the Symfony package.
0218245 @fabpot [RequestHandler] added the Request Handler component
fabpot authored Feb 17, 2010
5 *
8c423ed @fabpot replaced symfony-project.org by symfony.com
fabpot authored Mar 6, 2011
6 * (c) Fabien Potencier <fabien@symfony.com>
0218245 @fabpot [RequestHandler] added the Request Handler component
fabpot authored Feb 17, 2010
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
64fb94c @blue-eyes normalized license messages in PHP files
blue-eyes authored Jan 15, 2011
12 namespace Symfony\Component\HttpFoundation;
13
0218245 @fabpot [RequestHandler] added the Request Handler component
fabpot authored Feb 17, 2010
14 /**
b3a6c6f @fabpot [RequestHandler] removed fluent interface for Response, fixed some PH…
fabpot authored May 3, 2010
15 * Response represents an HTTP response.
0218245 @fabpot [RequestHandler] added the Request Handler component
fabpot authored Feb 17, 2010
16 *
8c423ed @fabpot replaced symfony-project.org by symfony.com
fabpot authored Mar 6, 2011
17 * @author Fabien Potencier <fabien@symfony.com>
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
18 *
19 * @api
0218245 @fabpot [RequestHandler] added the Request Handler component
fabpot authored Feb 17, 2010
20 */
d498de8 @fabpot [RequestHandler] removed RequestInterface and ResponseInterface, adde…
fabpot authored Apr 24, 2010
21 class Response
0218245 @fabpot [RequestHandler] added the Request Handler component
fabpot authored Feb 17, 2010
22 {
c605d7f @fabpot [HttpFoundation] added some phpdoc
fabpot authored Jul 10, 2010
23 /**
99a5097 @weaverryan [HttpFoundation] Correcting the PHPDoc for the public $headers proper…
weaverryan authored Jan 9, 2011
24 * @var \Symfony\Component\HttpFoundation\ResponseHeaderBag
c605d7f @fabpot [HttpFoundation] added some phpdoc
fabpot authored Jul 10, 2010
25 */
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
26 public $headers;
27
28 protected $content;
29 protected $version;
30 protected $statusCode;
31 protected $statusText;
bf20238 @fabpot fixed a bug in Response content-type auto-detection
fabpot authored Feb 21, 2011
32 protected $charset;
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
33
34 static public $statusTexts = array(
35 100 => 'Continue',
36 101 => 'Switching Protocols',
37 200 => 'OK',
38 201 => 'Created',
39 202 => 'Accepted',
40 203 => 'Non-Authoritative Information',
41 204 => 'No Content',
42 205 => 'Reset Content',
43 206 => 'Partial Content',
44 300 => 'Multiple Choices',
45 301 => 'Moved Permanently',
46 302 => 'Found',
47 303 => 'See Other',
48 304 => 'Not Modified',
49 305 => 'Use Proxy',
50 307 => 'Temporary Redirect',
51 400 => 'Bad Request',
52 401 => 'Unauthorized',
53 402 => 'Payment Required',
54 403 => 'Forbidden',
55 404 => 'Not Found',
56 405 => 'Method Not Allowed',
57 406 => 'Not Acceptable',
58 407 => 'Proxy Authentication Required',
59 408 => 'Request Timeout',
60 409 => 'Conflict',
61 410 => 'Gone',
62 411 => 'Length Required',
63 412 => 'Precondition Failed',
64 413 => 'Request Entity Too Large',
65 414 => 'Request-URI Too Long',
66 415 => 'Unsupported Media Type',
67 416 => 'Requested Range Not Satisfiable',
68 417 => 'Expectation Failed',
afbf6bf @Seldaek Added missing HTTP status code 418
Seldaek authored Jan 18, 2011
69 418 => 'I\'m a teapot',
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
70 500 => 'Internal Server Error',
71 501 => 'Not Implemented',
72 502 => 'Bad Gateway',
73 503 => 'Service Unavailable',
74 504 => 'Gateway Timeout',
75 505 => 'HTTP Version Not Supported',
76 );
77
78 /**
79 * Constructor.
80 *
81 * @param string $content The response content
82 * @param integer $status The response status code
83 * @param array $headers An array of response headers
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
84 *
85 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
86 */
87 public function __construct($content = '', $status = 200, $headers = array())
88 {
e7e5304 @fabpot forced all responses to have a Date header (RFC2616 - 14.18)
fabpot authored May 16, 2011
89 $this->headers = new ResponseHeaderBag($headers);
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
90 $this->setContent($content);
91 $this->setStatusCode($status);
92 $this->setProtocolVersion('1.0');
e7e5304 @fabpot forced all responses to have a Date header (RFC2616 - 14.18)
fabpot authored May 16, 2011
93 if (!$this->headers->has('Date')) {
94 $this->setDate(new \DateTime(null, new \DateTimeZone('UTC')));
95 }
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
96 }
97
98 /**
7661e9a @fabpot [HttpKernel] changed the semantic of Response::__toString() to someth…
fabpot authored Jun 23, 2010
99 * Returns the response content as it will be sent (with the headers).
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
100 *
101 * @return string The response content
102 */
103 public function __toString()
104 {
0e4d057 @fabpot moved some RFC-tweaking logic in Response to a public method to make …
fabpot authored Jul 11, 2011
105 $this->prepare();
7661e9a @fabpot [HttpKernel] changed the semantic of Response::__toString() to someth…
fabpot authored Jun 23, 2010
106
e81b88c @fabpot [HttpFoundation] added HeaderBag::__toString()
fabpot authored May 15, 2011
107 return
108 sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
109 $this->headers."\r\n".
110 $this->getContent();
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
111 }
112
113 /**
114 * Clones the current Response instance.
115 */
116 public function __clone()
117 {
118 $this->headers = clone $this->headers;
119 }
120
121 /**
0e4d057 @fabpot moved some RFC-tweaking logic in Response to a public method to make …
fabpot authored Jul 11, 2011
122 * Prepares the Response before it is sent to the client.
123 *
124 * This method tweaks the Response to ensure that it is
125 * compliant with RFC 2616.
126 */
127 public function prepare()
128 {
129 if ($this->isInformational() || in_array($this->statusCode, array(204, 304))) {
130 $this->setContent('');
131 }
132
133 // Fix Content-Type
134 $charset = $this->charset ?: 'UTF-8';
135 if (!$this->headers->has('Content-Type')) {
136 $this->headers->set('Content-Type', 'text/html; charset='.$charset);
fe62401 @kriswallsmith optimized string starts with checks
kriswallsmith authored Jan 11, 2012
137 } elseif (0 === strpos($this->headers->get('Content-Type'), 'text/') && false === strpos($this->headers->get('Content-Type'), 'charset')) {
0e4d057 @fabpot moved some RFC-tweaking logic in Response to a public method to make …
fabpot authored Jul 11, 2011
138 // add the charset
139 $this->headers->set('Content-Type', $this->headers->get('Content-Type').'; charset='.$charset);
140 }
141
142 // Fix Content-Length
143 if ($this->headers->has('Transfer-Encoding')) {
144 $this->headers->remove('Content-Length');
145 }
146 }
147
148 /**
97162cf @fabpot refactored cookie management
fabpot authored Jun 23, 2010
149 * Sends HTTP headers.
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
150 */
151 public function sendHeaders()
152 {
bb5075d @fabpot [HttpFoundation] prevented Response headers to be sent twice
fabpot authored Jul 7, 2011
153 // headers have already been sent by the developer
154 if (headers_sent()) {
155 return;
156 }
157
0e4d057 @fabpot moved some RFC-tweaking logic in Response to a public method to make …
fabpot authored Jul 11, 2011
158 $this->prepare();
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
159
160 // status
161 header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText));
162
163 // headers
97162cf @fabpot refactored cookie management
fabpot authored Jun 23, 2010
164 foreach ($this->headers->all() as $name => $values) {
165 foreach ($values as $value) {
96359fb @djama call header() with replace=false, to provide the possibility of sendi…
djama authored Jun 10, 2011
166 header($name.': '.$value, false);
97162cf @fabpot refactored cookie management
fabpot authored Jun 23, 2010
167 }
0218245 @fabpot [RequestHandler] added the Request Handler component
fabpot authored Feb 17, 2010
168 }
98b52b6 @schmittjoh better support for cookie handling, use native PHP function to set co…
schmittjoh authored Jan 15, 2011
169
170 // cookies
171 foreach ($this->headers->getCookies() as $cookie) {
66c4bc7 @fabpot [HttpFoundation] renamed Cookie::getExpire() to getExpiresTime() to b…
fabpot authored Apr 13, 2011
172 setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
98b52b6 @schmittjoh better support for cookie handling, use native PHP function to set co…
schmittjoh authored Jan 15, 2011
173 }
0218245 @fabpot [RequestHandler] added the Request Handler component
fabpot authored Feb 17, 2010
174 }
175
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
176 /**
177 * Sends content for the current web response.
178 */
179 public function sendContent()
180 {
181 echo $this->content;
182 }
183
184 /**
185 * Sends HTTP headers and content.
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
186 *
187 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
188 */
189 public function send()
190 {
191 $this->sendHeaders();
192 $this->sendContent();
a12ea12 @fabpot fixed CS
fabpot authored Jun 13, 2011
193
7e89a6a @lmcd Added an optimisation for PHP-FPM (FastCGI Process Manager).
lmcd authored Jun 9, 2011
194 if (function_exists('fastcgi_finish_request')) {
195 fastcgi_finish_request();
196 }
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
197 }
198
199 /**
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
200 * Sets the response content.
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
201 *
7af003b @Seldaek [HttpFoundation] Allow stringable objects and numbers in response bod…
Seldaek authored Jun 21, 2011
202 * Valid types are strings, numbers, and objects that implement a __toString() method.
203 *
204 * @param mixed $content
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
205 *
206 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
207 */
208 public function setContent($content)
209 {
84e87c6 @fabpot [HttpFoundation] fixed a bug in previous merge
fabpot authored Jun 22, 2011
210 if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable(array($content, '__toString'))) {
7af003b @Seldaek [HttpFoundation] Allow stringable objects and numbers in response bod…
Seldaek authored Jun 21, 2011
211 throw new \UnexpectedValueException('The Response content must be a string or object implementing __toString(), "'.gettype($content).'" given.');
8126fb7 @Seldaek [HttpFoundation] Ensure response body is string, fixes #1378
Seldaek authored Jun 21, 2011
212 }
37521b6 @fabpot [HttpFoundation] forced Response content to be string
fabpot authored Jun 22, 2011
213
214 $this->content = (string) $content;
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
215 }
216
217 /**
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
218 * Gets the current response content.
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
219 *
220 * @return string Content
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
221 *
222 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
223 */
224 public function getContent()
225 {
226 return $this->content;
227 }
228
229 /**
230 * Sets the HTTP protocol version (1.0 or 1.1).
231 *
232 * @param string $version The HTTP protocol version
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
233 *
234 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
235 */
236 public function setProtocolVersion($version)
237 {
238 $this->version = $version;
239 }
240
241 /**
242 * Gets the HTTP protocol version.
243 *
244 * @return string The HTTP protocol version
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
245 *
246 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
247 */
248 public function getProtocolVersion()
249 {
250 return $this->version;
251 }
252
253 /**
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
254 * Sets the response status code.
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
255 *
256 * @param integer $code HTTP status code
257 * @param string $text HTTP status text
258 *
259 * @throws \InvalidArgumentException When the HTTP status code is not valid
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
260 *
261 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
262 */
263 public function setStatusCode($code, $text = null)
264 {
265 $this->statusCode = (int) $code;
0d56ca5 @DuoSRX [HttpFoundation] Replace a duplicated test with a method in Response
DuoSRX authored Mar 5, 2011
266 if ($this->isInvalid()) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
267 throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code));
268 }
269
270 $this->statusText = false === $text ? '' : (null === $text ? self::$statusTexts[$this->statusCode] : $text);
271 }
272
273 /**
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
274 * Retrieves the status code for the current web response.
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
275 *
276 * @return string Status code
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
277 *
278 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
279 */
280 public function getStatusCode()
281 {
282 return $this->statusCode;
283 }
284
285 /**
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
286 * Sets the response charset.
4f46235 @Seldaek [HttpFoundation] Send proper charset along with the default text/html…
Seldaek authored Dec 15, 2010
287 *
288 * @param string $charset Character set
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
289 *
290 * @api
4f46235 @Seldaek [HttpFoundation] Send proper charset along with the default text/html…
Seldaek authored Dec 15, 2010
291 */
292 public function setCharset($charset)
293 {
294 $this->charset = $charset;
295 }
296
297 /**
298 * Retrieves the response charset.
299 *
300 * @return string Character set
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
301 *
302 * @api
4f46235 @Seldaek [HttpFoundation] Send proper charset along with the default text/html…
Seldaek authored Dec 15, 2010
303 */
304 public function getCharset()
305 {
306 return $this->charset;
307 }
308
309 /**
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
310 * Returns true if the response is worth caching under any circumstance.
311 *
312 * Responses marked "private" with an explicit Cache-Control directive are
313 * considered uncacheable.
314 *
315 * Responses with neither a freshness lifetime (Expires, max-age) nor cache
316 * validator (Last-Modified, ETag) are considered uncacheable.
317 *
318 * @return Boolean true if the response is worth caching, false otherwise
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
319 *
320 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
321 */
322 public function isCacheable()
323 {
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
324 if (!in_array($this->statusCode, array(200, 203, 300, 301, 302, 404, 410))) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
325 return false;
326 }
327
b6923dd @fabpot changed Cache-Control default value behavior
fabpot authored Nov 10, 2010
328 if ($this->headers->hasCacheControlDirective('no-store') || $this->headers->getCacheControlDirective('private')) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
329 return false;
330 }
331
332 return $this->isValidateable() || $this->isFresh();
333 }
334
335 /**
336 * Returns true if the response is "fresh".
337 *
338 * Fresh responses may be served from cache without any interaction with the
339 * origin. A response is considered fresh when it includes a Cache-Control/max-age
340 * indicator or Expiration header and the calculated age is less than the freshness lifetime.
341 *
342 * @return Boolean true if the response is fresh, false otherwise
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
343 *
344 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
345 */
346 public function isFresh()
347 {
348 return $this->getTtl() > 0;
349 }
350
351 /**
352 * Returns true if the response includes headers that can be used to validate
353 * the response with the origin server using a conditional GET request.
354 *
355 * @return Boolean true if the response is validateable, false otherwise
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
356 *
357 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
358 */
359 public function isValidateable()
360 {
361 return $this->headers->has('Last-Modified') || $this->headers->has('ETag');
362 }
363
364 /**
f6ddeeb @fabpot [HttpFoundation] added Response::setPublic() and changed setPrivate()…
fabpot authored Nov 12, 2010
365 * Marks the response as "private".
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
366 *
367 * It makes the response ineligible for serving other clients.
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
368 *
369 * @api
f6ddeeb @fabpot [HttpFoundation] added Response::setPublic() and changed setPrivate()…
fabpot authored Nov 12, 2010
370 */
371 public function setPrivate()
372 {
b6923dd @fabpot changed Cache-Control default value behavior
fabpot authored Nov 10, 2010
373 $this->headers->removeCacheControlDirective('public');
374 $this->headers->addCacheControlDirective('private');
f6ddeeb @fabpot [HttpFoundation] added Response::setPublic() and changed setPrivate()…
fabpot authored Nov 12, 2010
375 }
376
377 /**
378 * Marks the response as "public".
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
379 *
f6ddeeb @fabpot [HttpFoundation] added Response::setPublic() and changed setPrivate()…
fabpot authored Nov 12, 2010
380 * It makes the response eligible for serving other clients.
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
381 *
382 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
383 */
f6ddeeb @fabpot [HttpFoundation] added Response::setPublic() and changed setPrivate()…
fabpot authored Nov 12, 2010
384 public function setPublic()
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
385 {
b6923dd @fabpot changed Cache-Control default value behavior
fabpot authored Nov 10, 2010
386 $this->headers->addCacheControlDirective('public');
387 $this->headers->removeCacheControlDirective('private');
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
388 }
389
390 /**
391 * Returns true if the response must be revalidated by caches.
392 *
393 * This method indicates that the response must not be served stale by a
394 * cache in any circumstance without first revalidating with the origin.
86cc6a1 @pborreli [Component] Fixed some spelling typos
pborreli authored Oct 16, 2010
395 * When present, the TTL of the response should not be overridden to be
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
396 * greater than the value provided by the origin.
397 *
398 * @return Boolean true if the response must be revalidated by a cache, false otherwise
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
399 *
400 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
401 */
402 public function mustRevalidate()
403 {
b6923dd @fabpot changed Cache-Control default value behavior
fabpot authored Nov 10, 2010
404 return $this->headers->hasCacheControlDirective('must-revalidate') || $this->headers->has('must-proxy-revalidate');
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
405 }
406
407 /**
408 * Returns the Date header as a DateTime instance.
409 *
410 * @return \DateTime A \DateTime instance
411 *
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
412 * @throws \RuntimeException When the header is not parseable
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
413 *
414 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
415 */
416 public function getDate()
417 {
e7e5304 @fabpot forced all responses to have a Date header (RFC2616 - 14.18)
fabpot authored May 16, 2011
418 return $this->headers->getDate('Date');
419 }
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
420
e7e5304 @fabpot forced all responses to have a Date header (RFC2616 - 14.18)
fabpot authored May 16, 2011
421 /**
422 * Sets the Date header.
423 *
424 * @param \DateTime $date A \DateTime instance
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
425 *
426 * @api
e7e5304 @fabpot forced all responses to have a Date header (RFC2616 - 14.18)
fabpot authored May 16, 2011
427 */
428 public function setDate(\DateTime $date)
429 {
430 $date->setTimezone(new \DateTimeZone('UTC'));
431 $this->headers->set('Date', $date->format('D, d M Y H:i:s').' GMT');
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
432 }
433
434 /**
435 * Returns the age of the response.
436 *
437 * @return integer The age of the response in seconds
438 */
439 public function getAge()
440 {
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
441 if ($age = $this->headers->get('Age')) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
442 return $age;
443 }
444
445 return max(time() - $this->getDate()->format('U'), 0);
446 }
447
448 /**
449 * Marks the response stale by setting the Age header to be equal to the maximum age of the response.
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
450 *
451 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
452 */
453 public function expire()
454 {
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
455 if ($this->isFresh()) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
456 $this->headers->set('Age', $this->getMaxAge());
457 }
458 }
459
460 /**
461 * Returns the value of the Expires header as a DateTime instance.
462 *
463 * @return \DateTime A DateTime instance
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
464 *
465 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
466 */
467 public function getExpires()
468 {
469 return $this->headers->getDate('Expires');
470 }
471
472 /**
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
473 * Sets the Expires HTTP header with a DateTime instance.
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
474 *
944d91c @fabpot made some method name changes to have a better coherence throughout t…
fabpot authored Nov 23, 2010
475 * If passed a null value, it removes the header.
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
476 *
477 * @param \DateTime $date A \DateTime instance
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
478 *
479 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
480 */
481 public function setExpires(\DateTime $date = null)
482 {
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
483 if (null === $date) {
944d91c @fabpot made some method name changes to have a better coherence throughout t…
fabpot authored Nov 23, 2010
484 $this->headers->remove('Expires');
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
485 } else {
c448429 @fabpot [HttpFoundation] fixed date format for HTTP headers (format must be R…
fabpot authored Oct 27, 2010
486 $date = clone $date;
487 $date->setTimezone(new \DateTimeZone('UTC'));
488 $this->headers->set('Expires', $date->format('D, d M Y H:i:s').' GMT');
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
489 }
490 }
491
492 /**
493 * Sets the number of seconds after the time specified in the response's Date
494 * header when the the response should no longer be considered fresh.
495 *
496 * First, it checks for a s-maxage directive, then a max-age directive, and then it falls
497 * back on an expires header. It returns null when no maximum age can be established.
498 *
499 * @return integer|null Number of seconds
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
500 *
501 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
502 */
503 public function getMaxAge()
504 {
b6923dd @fabpot changed Cache-Control default value behavior
fabpot authored Nov 10, 2010
505 if ($age = $this->headers->getCacheControlDirective('s-maxage')) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
506 return $age;
507 }
508
b6923dd @fabpot changed Cache-Control default value behavior
fabpot authored Nov 10, 2010
509 if ($age = $this->headers->getCacheControlDirective('max-age')) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
510 return $age;
511 }
512
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
513 if (null !== $this->getExpires()) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
514 return $this->getExpires()->format('U') - $this->getDate()->format('U');
515 }
516
517 return null;
518 }
519
520 /**
521 * Sets the number of seconds after which the response should no longer be considered fresh.
522 *
523 * This methods sets the Cache-Control max-age directive.
524 *
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
525 * @param integer $value Number of seconds
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
526 *
527 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
528 */
529 public function setMaxAge($value)
530 {
b6923dd @fabpot changed Cache-Control default value behavior
fabpot authored Nov 10, 2010
531 $this->headers->addCacheControlDirective('max-age', $value);
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
532 }
533
534 /**
535 * Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
536 *
537 * This methods sets the Cache-Control s-maxage directive.
538 *
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
539 * @param integer $value Number of seconds
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
540 *
541 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
542 */
543 public function setSharedMaxAge($value)
544 {
053d83f @hhamon [HttpFoundation] force Response to be "public" if setSharedMaxAge() i…
hhamon authored Apr 13, 2011
545 $this->setPublic();
b6923dd @fabpot changed Cache-Control default value behavior
fabpot authored Nov 10, 2010
546 $this->headers->addCacheControlDirective('s-maxage', $value);
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
547 }
548
549 /**
550 * Returns the response's time-to-live in seconds.
551 *
552 * It returns null when no freshness information is present in the response.
553 *
554 * When the responses TTL is <= 0, the response may not be served from cache without first
555 * revalidating with the origin.
556 *
557 * @return integer The TTL in seconds
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
558 *
559 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
560 */
561 public function getTtl()
562 {
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
563 if ($maxAge = $this->getMaxAge()) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
564 return $maxAge - $this->getAge();
565 }
566
567 return null;
568 }
569
570 /**
571 * Sets the response's time-to-live for shared caches.
572 *
573 * This method adjusts the Cache-Control/s-maxage directive.
574 *
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
575 * @param integer $seconds Number of seconds
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
576 *
577 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
578 */
579 public function setTtl($seconds)
580 {
581 $this->setSharedMaxAge($this->getAge() + $seconds);
582 }
583
584 /**
585 * Sets the response's time-to-live for private/client caches.
586 *
587 * This method adjusts the Cache-Control/max-age directive.
588 *
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
589 * @param integer $seconds Number of seconds
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
590 *
591 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
592 */
593 public function setClientTtl($seconds)
594 {
595 $this->setMaxAge($this->getAge() + $seconds);
596 }
597
598 /**
599 * Returns the Last-Modified HTTP header as a DateTime instance.
600 *
601 * @return \DateTime A DateTime instance
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
602 *
603 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
604 */
605 public function getLastModified()
606 {
19090d3 @DuoSRX [HttpFoundation] Fixed a typo in response->setLastModified()
DuoSRX authored Mar 6, 2011
607 return $this->headers->getDate('Last-Modified');
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
608 }
609
610 /**
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
611 * Sets the Last-Modified HTTP header with a DateTime instance.
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
612 *
944d91c @fabpot made some method name changes to have a better coherence throughout t…
fabpot authored Nov 23, 2010
613 * If passed a null value, it removes the header.
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
614 *
615 * @param \DateTime $date A \DateTime instance
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
616 *
617 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
618 */
619 public function setLastModified(\DateTime $date = null)
620 {
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
621 if (null === $date) {
944d91c @fabpot made some method name changes to have a better coherence throughout t…
fabpot authored Nov 23, 2010
622 $this->headers->remove('Last-Modified');
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
623 } else {
c448429 @fabpot [HttpFoundation] fixed date format for HTTP headers (format must be R…
fabpot authored Oct 27, 2010
624 $date = clone $date;
625 $date->setTimezone(new \DateTimeZone('UTC'));
626 $this->headers->set('Last-Modified', $date->format('D, d M Y H:i:s').' GMT');
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
627 }
628 }
629
630 /**
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
631 * Returns the literal value of the ETag HTTP header.
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
632 *
633 * @return string The ETag HTTP header
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
634 *
635 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
636 */
637 public function getEtag()
606e44e @fabpot [RequestHandler] added a bunch of HTTP cache related methods to the R…
fabpot authored May 3, 2010
638 {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
639 return $this->headers->get('ETag');
640 }
641
f669674 @fabpot [HttpFoundation] added a missing phpdoc
fabpot authored Nov 12, 2010
642 /**
643 * Sets the ETag value.
644 *
645 * @param string $etag The ETag unique identifier
646 * @param Boolean $weak Whether you want a weak ETag or not
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
647 *
648 * @api
f669674 @fabpot [HttpFoundation] added a missing phpdoc
fabpot authored Nov 12, 2010
649 */
005051c @fabpot [HttpKernel] added support for weak etags and added a method to set a…
fabpot authored May 19, 2010
650 public function setEtag($etag = null, $weak = false)
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
651 {
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
652 if (null === $etag) {
944d91c @fabpot made some method name changes to have a better coherence throughout t…
fabpot authored Nov 23, 2010
653 $this->headers->remove('Etag');
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
654 } else {
005051c @fabpot [HttpKernel] added support for weak etags and added a method to set a…
fabpot authored May 19, 2010
655 if (0 !== strpos($etag, '"')) {
656 $etag = '"'.$etag.'"';
657 }
658
659 $this->headers->set('ETag', (true === $weak ? 'W/' : '').$etag);
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
660 }
661 }
662
663 /**
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
664 * Sets the response's cache headers (validation and/or expiration).
942104a @fabpot [HttpFoundation] added a setCache() method to ease setting the HTTP c…
fabpot authored Nov 12, 2010
665 *
7257571 @fabpot [HttpFoundation] added missing code for last commit
fabpot authored Nov 12, 2010
666 * Available options are: etag, last_modified, max_age, s_maxage, private, and public.
942104a @fabpot [HttpFoundation] added a setCache() method to ease setting the HTTP c…
fabpot authored Nov 12, 2010
667 *
668 * @param array $options An array of cache options
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
669 *
670 * @api
942104a @fabpot [HttpFoundation] added a setCache() method to ease setting the HTTP c…
fabpot authored Nov 12, 2010
671 */
672 public function setCache(array $options)
673 {
b1448ec @fabpot [HttpFoundation] fixed typo
fabpot authored Jan 30, 2011
674 if ($diff = array_diff(array_keys($options), array('etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public'))) {
733ac9d @fabpot [HttpFoundation] fixed exception message (closes #3123)
fabpot authored Jan 16, 2012
675 throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff))));
942104a @fabpot [HttpFoundation] added a setCache() method to ease setting the HTTP c…
fabpot authored Nov 12, 2010
676 }
677
678 if (isset($options['etag'])) {
679 $this->setEtag($options['etag']);
680 }
681
682 if (isset($options['last_modified'])) {
683 $this->setLastModified($options['last_modified']);
684 }
685
7257571 @fabpot [HttpFoundation] added missing code for last commit
fabpot authored Nov 12, 2010
686 if (isset($options['max_age'])) {
687 $this->setMaxAge($options['max_age']);
688 }
689
690 if (isset($options['s_maxage'])) {
691 $this->setSharedMaxAge($options['s_maxage']);
692 }
693
942104a @fabpot [HttpFoundation] added a setCache() method to ease setting the HTTP c…
fabpot authored Nov 12, 2010
694 if (isset($options['public'])) {
695 if ($options['public']) {
696 $this->setPublic();
697 } else {
698 $this->setPrivate();
699 }
700 }
701
702 if (isset($options['private'])) {
703 if ($options['private']) {
704 $this->setPrivate();
705 } else {
706 $this->setPublic();
707 }
708 }
709 }
710
711 /**
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
712 * Modifies the response so that it conforms to the rules defined for a 304 status code.
713 *
714 * This sets the status, removes the body, and discards any headers
715 * that MUST NOT be included in 304 responses.
716 *
717 * @see http://tools.ietf.org/html/rfc2616#section-10.3.5
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
718 *
719 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
720 */
721 public function setNotModified()
722 {
723 $this->setStatusCode(304);
724 $this->setContent(null);
725
726 // remove headers that MUST NOT be included with 304 Not Modified responses
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
727 foreach (array('Allow', 'Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Last-Modified') as $header) {
944d91c @fabpot made some method name changes to have a better coherence throughout t…
fabpot authored Nov 23, 2010
728 $this->headers->remove($header);
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
729 }
730 }
731
732 /**
733 * Returns true if the response includes a Vary header.
734 *
735 * @return true if the response includes a Vary header, false otherwise
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
736 *
737 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
738 */
739 public function hasVary()
740 {
741 return (Boolean) $this->headers->get('Vary');
742 }
743
744 /**
745 * Returns an array of header names given in the Vary header.
746 *
747 * @return array An array of Vary names
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
748 *
749 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
750 */
751 public function getVary()
752 {
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
753 if (!$vary = $this->headers->get('Vary')) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
754 return array();
755 }
756
dd9b77e @fabpot [HttpFoundation] added Response::setVary()
fabpot authored Oct 30, 2010
757 return is_array($vary) ? $vary : preg_split('/[\s,]+/', $vary);
758 }
759
760 /**
761 * Sets the Vary header.
762 *
763 * @param string|array $headers
764 * @param Boolean $replace Whether to replace the actual value of not (true by default)
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
765 *
766 * @api
dd9b77e @fabpot [HttpFoundation] added Response::setVary()
fabpot authored Oct 30, 2010
767 */
768 public function setVary($headers, $replace = true)
769 {
770 $this->headers->set('Vary', $headers, $replace);
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
771 }
772
773 /**
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
774 * Determines if the Response validators (ETag, Last-Modified) match
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
775 * a conditional value specified in the Request.
776 *
777 * If the Response is not modified, it sets the status code to 304 and
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
778 * removes the actual content by calling the setNotModified() method.
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
779 *
780 * @param Request $request A Request instance
781 *
daee68a @Tobion fixed typos and unified PHPDoc in the Response class
Tobion authored Jan 5, 2012
782 * @return Boolean true if the Response validators match the Request, false otherwise
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
783 *
784 * @api
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
785 */
786 public function isNotModified(Request $request)
787 {
788 $lastModified = $request->headers->get('If-Modified-Since');
789 $notModified = false;
005051c @fabpot [HttpKernel] added support for weak etags and added a method to set a…
fabpot authored May 19, 2010
790 if ($etags = $request->getEtags()) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
791 $notModified = (in_array($this->getEtag(), $etags) || in_array('*', $etags)) && (!$lastModified || $this->headers->get('Last-Modified') == $lastModified);
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
792 } elseif ($lastModified) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
793 $notModified = $lastModified == $this->headers->get('Last-Modified');
794 }
795
2684de0 @Seldaek Folded all curly brackets of control structures to conform to PEAR/ZF CS
Seldaek authored May 7, 2010
796 if ($notModified) {
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
797 $this->setNotModified();
798 }
799
800 return $notModified;
801 }
802
803 // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
804 /**
805 * @api
806 */
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
807 public function isInvalid()
808 {
809 return $this->statusCode < 100 || $this->statusCode >= 600;
810 }
811
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
812 /**
813 * @api
814 */
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
815 public function isInformational()
816 {
817 return $this->statusCode >= 100 && $this->statusCode < 200;
818 }
819
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
820 /**
821 * @api
822 */
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
823 public function isSuccessful()
824 {
825 return $this->statusCode >= 200 && $this->statusCode < 300;
826 }
827
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
828 /**
829 * @api
830 */
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
831 public function isRedirection()
832 {
833 return $this->statusCode >= 300 && $this->statusCode < 400;
834 }
835
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
836 /**
837 * @api
838 */
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
839 public function isClientError()
840 {
841 return $this->statusCode >= 400 && $this->statusCode < 500;
842 }
843
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
844 /**
845 * @api
846 */
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
847 public function isServerError()
848 {
849 return $this->statusCode >= 500 && $this->statusCode < 600;
850 }
851
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
852 /**
853 * @api
854 */
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
855 public function isOk()
856 {
857 return 200 === $this->statusCode;
858 }
859
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
860 /**
861 * @api
862 */
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
863 public function isForbidden()
864 {
865 return 403 === $this->statusCode;
866 }
867
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
868 /**
869 * @api
870 */
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
871 public function isNotFound()
872 {
873 return 404 === $this->statusCode;
874 }
875
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
876 /**
877 * @api
878 */
ef9dc7c @julesbou [HttpFoundation] merge Response::isRedirected() with Response::isRedi…
julesbou authored May 29, 2011
879 public function isRedirect($location = null)
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
880 {
ef9dc7c @julesbou [HttpFoundation] merge Response::isRedirected() with Response::isRedi…
julesbou authored May 29, 2011
881 return in_array($this->statusCode, array(201, 301, 302, 303, 307)) && (null === $location ?: $location == $this->headers->get('Location'));
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
882 }
883
7dcbcbe @fabpot [HttpFoundation] tagged public @api
fabpot authored Jul 20, 2011
884 /**
885 * @api
886 */
83c6d33 @fabpot changed coding standards: indendation is now 4 spaces
fabpot authored May 6, 2010
887 public function isEmpty()
888 {
889 return in_array($this->statusCode, array(201, 204, 304));
890 }
0218245 @fabpot [RequestHandler] added the Request Handler component
fabpot authored Feb 17, 2010
891 }
Something went wrong with that request. Please try again.