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 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__'/../FreezableObject.php';
  23. 23:  
  24. 24:  
  25. 25:  
  26. 26: /**
  27. 27:  * Application presenter request. Immutable object.
  28. 28:  *
  29. 29:  * @author     David Grudl
  30. 30:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  31. 31:  * @package    Nette\Application
  32. 32:  *
  33. 33:  * @property   string $presenterName 
  34. 34:  * @property   array $params 
  35. 35:  * @property   array $post 
  36. 36:  * @property   array $files 
  37. 37:  */
  38. 38: final class PresenterRequest extends FreezableObject
  39. 39: {
  40. 40:     /** method */
  41. 41:     const FORWARD = 'FORWARD';
  42. 42:  
  43. 43:     /** flag */
  44. 44:     const SECURED = 'secured';
  45. 45:  
  46. 46:     /** flag */
  47. 47:     const RESTORED = 'restored';
  48. 48:  
  49. 49:     /** @var string */
  50. 50:     private $method;
  51. 51:  
  52. 52:     /** @var array */
  53. 53:     private $flags array();
  54. 54:  
  55. 55:     /** @var string */
  56. 56:     private $name;
  57. 57:  
  58. 58:     /** @var array */
  59. 59:     private $params;
  60. 60:  
  61. 61:     /** @var array */
  62. 62:     private $post;
  63. 63:  
  64. 64:     /** @var array */
  65. 65:     private $files;
  66. 66:  
  67. 67:  
  68. 68:  
  69. 69:     /**
  70. 70:      * @param  string  fully qualified presenter name (module:module:presenter)
  71. 71:      * @param  string  method
  72. 72:      * @param  array   variables provided to the presenter usually via URL
  73. 73:      * @param  array   variables provided to the presenter via POST
  74. 74:      * @param  array   all uploaded files
  75. 75:      */
  76. 76:     public function __construct($name$methodarray $paramsarray $post array()array $files array()array $flags array())
  77. 77:     {
  78. 78:         $this->name $name;
  79. 79:         $this->method $method;
  80. 80:         $this->params $params;
  81. 81:         $this->post $post;
  82. 82:         $this->files $files;
  83. 83:         $this->flags $flags;
  84. 84:     }
  85. 85:  
  86. 86:  
  87. 87:  
  88. 88:     /**
  89. 89:      * Sets the presenter name.
  90. 90:      * @param  string 
  91. 91:      * @return void 
  92. 92:      */
  93. 93:     public function setPresenterName($name)
  94. 94:     {
  95. 95:         $this->updating();
  96. 96:         $this->name $name;
  97. 97:     }
  98. 98:  
  99. 99:  
  100. 100:  
  101. 101:     /**
  102. 102:      * Retrieve the presenter name.
  103. 103:      * @return string 
  104. 104:      */
  105. 105:     public function getPresenterName()
  106. 106:     {
  107. 107:         return $this->name;
  108. 108:     }
  109. 109:  
  110. 110:  
  111. 111:  
  112. 112:     /**
  113. 113:      * Sets variables provided to the presenter.
  114. 114:      * @param  array 
  115. 115:      * @return void 
  116. 116:      */
  117. 117:     public function setParams(array $params)
  118. 118:     {
  119. 119:         $this->updating();
  120. 120:         $this->params $params;
  121. 121:     }
  122. 122:  
  123. 123:  
  124. 124:  
  125. 125:     /**
  126. 126:      * Returns all variables provided to the presenter (usually via URL).
  127. 127:      * @return array 
  128. 128:      */
  129. 129:     public function getParams()
  130. 130:     {
  131. 131:         return $this->params;
  132. 132:     }
  133. 133:  
  134. 134:  
  135. 135:  
  136. 136:     /**
  137. 137:      * Sets variables provided to the presenter via POST.
  138. 138:      * @param  array 
  139. 139:      * @return void 
  140. 140:      */
  141. 141:     public function setPost(array $params)
  142. 142:     {
  143. 143:         $this->updating();
  144. 144:         $this->post $params;
  145. 145:     
  146. 146:  
  147. 147:  
  148. 148:  
  149. 149:     /**
  150. 150:      * Returns all variables provided to the presenter via POST.
  151. 151:      * @return array 
  152. 152:      */
  153. 153:     public function getPost()
  154. 154:     {
  155. 155:         return $this->post;
  156. 156:     }
  157. 157:  
  158. 158:  
  159. 159:  
  160. 160:     /**
  161. 161:      * Sets all uploaded files.
  162. 162:      * @param  array 
  163. 163:      * @return void 
  164. 164:      */
  165. 165:     public function setFiles(array $files)
  166. 166:     {
  167. 167:         $this->updating();
  168. 168:         $this->files $files;
  169. 169:     
  170. 170:  
  171. 171:  
  172. 172:  
  173. 173:     /**
  174. 174:      * Returns all uploaded files.
  175. 175:      * @return array 
  176. 176:      */
  177. 177:     public function getFiles()
  178. 178:     {
  179. 179:         return $this->files;
  180. 180:     }
  181. 181:  
  182. 182:  
  183. 183:  
  184. 184:     /**
  185. 185:      * Sets the method.
  186. 186:      * @param  string 
  187. 187:      * @return void 
  188. 188:      */
  189. 189:     public function setMethod($method)
  190. 190:     {
  191. 191:         $this->method $method;
  192. 192:     }
  193. 193:  
  194. 194:  
  195. 195:  
  196. 196:     /**
  197. 197:      * Checks if the method is the given one.
  198. 198:      * @param  string 
  199. 199:      * @return bool 
  200. 200:      */
  201. 201:     public function isMethod($method)
  202. 202:     {
  203. 203:         return strcasecmp($this->method$method=== 0;
  204. 204:     }
  205. 205:  
  206. 206:  
  207. 207:  
  208. 208:     /**
  209. 209:      * Checks if the method is POST.
  210. 210:      * @return bool 
  211. 211:      */
  212. 212:     public function isPost()
  213. 213:     {
  214. 214:         return strcasecmp($this->method'post'=== 0;
  215. 215:     }
  216. 216:  
  217. 217:  
  218. 218:  
  219. 219:     /**
  220. 220:      * Sets the flag.
  221. 221:      * @param  string 
  222. 222:      * @param  bool 
  223. 223:      * @return void 
  224. 224:      */
  225. 225:     public function setFlag($flag$value TRUE)
  226. 226:     {
  227. 227:         $this->updating();
  228. 228:         $this->flags[$flag= (bool) $value;
  229. 229:     }
  230. 230:  
  231. 231:  
  232. 232:  
  233. 233:     /**
  234. 234:      * Checks the flag.
  235. 235:      * @param  string 
  236. 236:      * @return bool 
  237. 237:      */
  238. 238:     public function hasFlag($flag)
  239. 239:     {
  240. 240:         return !empty($this->flags[$flag]);
  241. 241:     }
  242. 242: