1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004 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: * @property-read string $url
25: * @property-read int $code
26: */
27: class RedirectResponse extends Nette\Object implements Nette\Application\IResponse
28: {
29: /** @var string */
30: private $url;
31:
32: /** @var int */
33: private $code;
34:
35:
36:
37: /**
38: * @param string URI
39: * @param int HTTP code 3xx
40: */
41: public function __construct($url, $code = Http\IResponse::S302_FOUND)
42: {
43: $this->url = (string) $url;
44: $this->code = (int) $code;
45: }
46:
47:
48:
49: /**
50: * @return string
51: */
52: final public function getUrl()
53: {
54: return $this->url;
55: }
56:
57:
58:
59: /**
60: * @return int
61: */
62: final public function getCode()
63: {
64: return $this->code;
65: }
66:
67:
68:
69: /**
70: * Sends response to output.
71: * @return void
72: */
73: public function send(Http\IRequest $httpRequest, Http\IResponse $httpResponse)
74: {
75: $httpResponse->redirect($this->url, $this->code);
76: }
77:
78: }
79: