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