Source for file RedirectingResponse.php

Documentation is available at RedirectingResponse.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  7. 7:  *
  8. 8:  * This source file is subject to the "Nette license" that is bundled
  9. 9:  * with this package in the file license.txt.
  10. 10:  *
  11. 11:  * For more information please see http://nettephp.com
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    http://nettephp.com/license  Nette license
  15. 15:  * @link       http://nettephp.com
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Application
  18. 18:  */
  19. 19:  
  20. 20:  
  21. 21:  
  22. 22: require_once dirname(__FILE__'/../../Object.php';
  23. 23:  
  24. 24: require_once dirname(__FILE__'/../../Application/IPresenterResponse.php';
  25. 25:  
  26. 26:  
  27. 27:  
  28. 28: /**
  29. 29:  * Redirects to new request.
  30. 30:  *
  31. 31:  * @author     David Grudl
  32. 32:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  33. 33:  * @package    Nette\Application
  34. 34:  */
  35. 35: class RedirectingResponse extends Object implements IPresenterResponse
  36. 36: {
  37. 37:     /** @var string */
  38. 38:     private $uri;
  39. 39:  
  40. 40:     /** @var int */
  41. 41:     private $code;
  42. 42:  
  43. 43:  
  44. 44:  
  45. 45:     /**
  46. 46:      * @param  string  URI
  47. 47:      * @param  int     HTTP code 3xx
  48. 48:      */
  49. 49:     public function __construct($uri$code IHttpResponse::S302_FOUND)
  50. 50:     {
  51. 51:         $this->uri = (string) $uri;
  52. 52:         $this->code = (int) $code;
  53. 53:     }
  54. 54:  
  55. 55:  
  56. 56:  
  57. 57:     /**
  58. 58:      * @return string 
  59. 59:      */
  60. 60:     final public function getUri()
  61. 61:     {
  62. 62:         return $this->uri;
  63. 63:     }
  64. 64:  
  65. 65:  
  66. 66:  
  67. 67:     /**
  68. 68:      * @return int 
  69. 69:      */
  70. 70:     final public function getCode()
  71. 71:     {
  72. 72:         return $this->code;
  73. 73:     }
  74. 74:  
  75. 75:  
  76. 76:  
  77. 77:     /**
  78. 78:      * Sends response to output.
  79. 79:      * @return void 
  80. 80:      */
  81. 81:     public function send()
  82. 82:     {
  83. 83:         Environment::getHttpResponse()->redirect($this->uri$this->code);
  84. 84:     }
  85. 85:  
  86. 86: }