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: class RedirectResponse extends Nette\Object implements Nette\Application\IResponse
20: {
21:     /** @var string */
22:     private $url;
23: 
24:     /** @var int */
25:     private $code;
26: 
27: 
28:     /**
29:      * @param  string  URI
30:      * @param  int     HTTP code 3xx
31:      */
32:     public function __construct($url, $code = Http\IResponse::S302_FOUND)
33:     {
34:         $this->url = (string) $url;
35:         $this->code = (int) $code;
36:     }
37: 
38: 
39:     /**
40:      * @return string
41:      */
42:     public function getUrl()
43:     {
44:         return $this->url;
45:     }
46: 
47: 
48:     /**
49:      * @return int
50:      */
51:     public function getCode()
52:     {
53:         return $this->code;
54:     }
55: 
56: 
57:     /**
58:      * Sends response to output.
59:      * @return void
60:      */
61:     public function send(Http\IRequest $httpRequest, Http\IResponse $httpResponse)
62:     {
63:         $httpResponse->redirect($this->url, $this->code);
64:     }
65: 
66: }
67: