Source for file PresenterRequest.php

Documentation is available at PresenterRequest.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 https://nette.org
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    https://nette.org/license  Nette license
  15. 15:  * @link       https://nette.org
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Application
  18. 18:  * @version    $Id$
  19. 19:  */
  20. 20:  
  21. 21:  
  22. 22:  
  23. 23: require_once dirname(__FILE__'/../Object.php';
  24. 24:  
  25. 25:  
  26. 26:  
  27. 27: /**
  28. 28:  * Application presenter request. Immutable object.
  29. 29:  *
  30. 30:  * @author     David Grudl
  31. 31:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  32. 32:  * @package    Nette\Application
  33. 33:  */
  34. 34: final class PresenterRequest extends Object
  35. 35: {
  36. 36:     /** method */
  37. 37:     const FORWARD = 'FORWARD';
  38. 38:  
  39. 39:     /** @var string */
  40. 40:     private $method;
  41. 41:  
  42. 42:     /** @var array */
  43. 43:     private $flags array();
  44. 44:  
  45. 45:     /** @var string */
  46. 46:     private $name;
  47. 47:  
  48. 48:     /** @var array */
  49. 49:     private $params;
  50. 50:  
  51. 51:     /** @var array */
  52. 52:     private $post;
  53. 53:  
  54. 54:     /** @var array */
  55. 55:     private $files;
  56. 56:  
  57. 57:  
  58. 58:  
  59. 59:     /**
  60. 60:      * @param  string  fully qualified presenter name (module:module:presenter)
  61. 61:      * @param  string  method
  62. 62:      * @param  array   variables provided to the presenter usually via URL
  63. 63:      * @param  array   variables provided to the presenter via POST
  64. 64:      * @param  array   all uploaded files
  65. 65:      */
  66. 66:     public function __construct($name$methodarray $paramsarray $post array()array $files array()array $flags array())
  67. 67:     {
  68. 68:         $this->name $name;
  69. 69:         $this->method $method;
  70. 70:         $this->params $params;
  71. 71:         $this->post $post;
  72. 72:         $this->files $files;
  73. 73:         $this->flags $flags;
  74. 74:     }
  75. 75:  
  76. 76:  
  77. 77:  
  78. 78:     /**
  79. 79:      * Retrieve the presenter name.
  80. 80:      * @return string 
  81. 81:      */
  82. 82:     public function getPresenterName()
  83. 83:     {
  84. 84:         return $this->name;
  85. 85:     }
  86. 86:  
  87. 87:  
  88. 88:  
  89. 89:     /**
  90. 90:      * Returns all variables provided to the presenter (usually via URL).
  91. 91:      * @return array 
  92. 92:      */
  93. 93:     public function getParams()
  94. 94:     {
  95. 95:         return $this->params;
  96. 96:     }
  97. 97:  
  98. 98:  
  99. 99:  
  100. 100:     /**
  101. 101:      * Returns all variables provided to the presenter via POST.
  102. 102:      * @return array 
  103. 103:      */
  104. 104:     public function getPost()
  105. 105:     {
  106. 106:         return $this->post;
  107. 107:     }
  108. 108:  
  109. 109:  
  110. 110:  
  111. 111:     /**
  112. 112:      * Returns all uploaded files.
  113. 113:      * @return array 
  114. 114:      */
  115. 115:     public function getFiles()
  116. 116:     {
  117. 117:         return $this->files;
  118. 118:     }
  119. 119:  
  120. 120:  
  121. 121:  
  122. 122:     /**
  123. 123:      * Checks if the method is the given one.
  124. 124:      * @param  string 
  125. 125:      * @return bool 
  126. 126:      */
  127. 127:     public function isMethod($method)
  128. 128:     {
  129. 129:         return strcasecmp($this->method$method=== 0;
  130. 130:     }
  131. 131:  
  132. 132:  
  133. 133:  
  134. 134:     /**
  135. 135:      * Checks if the method is POST.
  136. 136:      * @return bool 
  137. 137:      */
  138. 138:     public function isPost()
  139. 139:     {
  140. 140:         return strcasecmp($this->method'post'=== 0;
  141. 141:     }
  142. 142:  
  143. 143:  
  144. 144:  
  145. 145:     /**
  146. 146:      * Checks the flag.
  147. 147:      * @param  string 
  148. 148:      * @return bool 
  149. 149:      */
  150. 150:     public function hasFlag($flag)
  151. 151:     {
  152. 152:         return !empty($this->flags[$flag]);
  153. 153:     }
  154. 154:  
  155. 155:  
  156. 156:  
  157. 157:     /**
  158. 158:      * @return array 
  159. 159:      * @ignore internal
  160. 160:      */
  161. 161:     public function modify($var$key$value NULL)
  162. 162:     {
  163. 163:         if (func_num_args(=== 3{
  164. 164:             $this->{$var}[$key$value;
  165. 165:  
  166. 166:         else {
  167. 167:             $this->$var $key;
  168. 168:         }
  169. 169:     }
  170. 170: