1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: */
11:
12: namespace Nette\Application\Responses;
13:
14: use Nette,
15: Nette\Http;
16:
17:
18:
19: /**
20: * Redirects to new URI.
21: *
22: * @author David Grudl
23: */
24: class RedirectResponse extends Nette\Object implements Nette\Application\IResponse
25: {
26: /** @var string */
27: private $url;
28:
29: /** @var int */
30: private $code;
31:
32:
33:
34: /**
35: * @param string URI
36: * @param int HTTP code 3xx
37: */
38: public function __construct($url, $code = Http\IResponse::S302_FOUND)
39: {
40: $this->url = (string) $url;
41: $this->code = (int) $code;
42: }
43:
44:
45:
46: /**
47: * @return string
48: */
49: final public function getUrl()
50: {
51: return $this->url;
52: }
53:
54:
55:
56: /**
57: * @return int
58: */
59: final public function getCode()
60: {
61: return $this->code;
62: }
63:
64:
65:
66: /**
67: * Sends response to output.
68: * @return void
69: */
70: public function send(Http\IRequest $httpRequest, Http\IResponse $httpResponse)
71: {
72: $httpResponse->redirect($this->url, $this->code);
73: }
74:
75: }
76: