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:  * 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 PresenterRequest  provides a fluent interface
  92. 92:      */
  93. 93:     public function setPresenterName($name)
  94. 94:     {
  95. 95:         $this->updating();
  96. 96:         $this->name $name;
  97. 97:         return $this;
  98. 98:     }
  99. 99:  
  100. 100:  
  101. 101:  
  102. 102:     /**
  103. 103:      * Retrieve the presenter name.
  104. 104:      * @return string 
  105. 105:      */
  106. 106:     public function getPresenterName()
  107. 107:     {
  108. 108:         return $this->name;
  109. 109:     }
  110. 110:  
  111. 111:  
  112. 112:  
  113. 113:     /**
  114. 114:      * Sets variables provided to the presenter.
  115. 115:      * @param  array 
  116. 116:      * @return PresenterRequest  provides a fluent interface
  117. 117:      */
  118. 118:     public function setParams(array $params)
  119. 119:     {
  120. 120:         $this->updating();
  121. 121:         $this->params $params;
  122. 122:         return $this;
  123. 123:     }
  124. 124:  
  125. 125:  
  126. 126:  
  127. 127:     /**
  128. 128:      * Returns all variables provided to the presenter (usually via URL).
  129. 129:      * @return array 
  130. 130:      */
  131. 131:     public function getParams()
  132. 132:     {
  133. 133:         return $this->params;
  134. 134:     }
  135. 135:  
  136. 136:  
  137. 137:  
  138. 138:     /**
  139. 139:      * Sets variables provided to the presenter via POST.
  140. 140:      * @param  array 
  141. 141:      * @return PresenterRequest  provides a fluent interface
  142. 142:      */
  143. 143:     public function setPost(array $params)
  144. 144:     {
  145. 145:         $this->updating();
  146. 146:         $this->post $params;
  147. 147:         return $this;
  148. 148:     
  149. 149:  
  150. 150:  
  151. 151:  
  152. 152:     /**
  153. 153:      * Returns all variables provided to the presenter via POST.
  154. 154:      * @return array 
  155. 155:      */
  156. 156:     public function getPost()
  157. 157:     {
  158. 158:         return $this->post;
  159. 159:     }
  160. 160:  
  161. 161:  
  162. 162:  
  163. 163:     /**
  164. 164:      * Sets all uploaded files.
  165. 165:      * @param  array 
  166. 166:      * @return PresenterRequest  provides a fluent interface
  167. 167:      */
  168. 168:     public function setFiles(array $files)
  169. 169:     {
  170. 170:         $this->updating();
  171. 171:         $this->files $files;
  172. 172:         return $this;
  173. 173:     
  174. 174:  
  175. 175:  
  176. 176:  
  177. 177:     /**
  178. 178:      * Returns all uploaded files.
  179. 179:      * @return array 
  180. 180:      */
  181. 181:     public function getFiles()
  182. 182:     {
  183. 183:         return $this->files;
  184. 184:     }
  185. 185:  
  186. 186:  
  187. 187:  
  188. 188:     /**
  189. 189:      * Sets the method.
  190. 190:      * @param  string 
  191. 191:      * @return PresenterRequest  provides a fluent interface
  192. 192:      */
  193. 193:     public function setMethod($method)
  194. 194:     {
  195. 195:         $this->method $method;
  196. 196:         return $this;
  197. 197:     }
  198. 198:  
  199. 199:  
  200. 200:  
  201. 201:     /**
  202. 202:      * Returns the method.
  203. 203:      * @return string 
  204. 204:      */
  205. 205:     public function getMethod()
  206. 206:     {
  207. 207:         return $this->method;
  208. 208:     }
  209. 209:  
  210. 210:  
  211. 211:  
  212. 212:     /**
  213. 213:      * Checks if the method is the given one.
  214. 214:      * @param  string 
  215. 215:      * @return bool 
  216. 216:      */
  217. 217:     public function isMethod($method)
  218. 218:     {
  219. 219:         return strcasecmp($this->method$method=== 0;
  220. 220:     }
  221. 221:  
  222. 222:  
  223. 223:  
  224. 224:     /**
  225. 225:      * Checks if the method is POST.
  226. 226:      * @return bool 
  227. 227:      */
  228. 228:     public function isPost()
  229. 229:     {
  230. 230:         return strcasecmp($this->method'post'=== 0;
  231. 231:     }
  232. 232:  
  233. 233:  
  234. 234:  
  235. 235:     /**
  236. 236:      * Sets the flag.
  237. 237:      * @param  string 
  238. 238:      * @param  bool 
  239. 239:      * @return PresenterRequest  provides a fluent interface
  240. 240:      */
  241. 241:     public function setFlag($flag$value TRUE)
  242. 242:     {
  243. 243:         $this->updating();
  244. 244:         $this->flags[$flag= (bool) $value;
  245. 245:         return $this;
  246. 246:     }
  247. 247:  
  248. 248:  
  249. 249:  
  250. 250:     /**
  251. 251:      * Checks the flag.
  252. 252:      * @param  string 
  253. 253:      * @return bool 
  254. 254:      */
  255. 255:     public function hasFlag($flag)
  256. 256:     {
  257. 257:         return !empty($this->flags[$flag]);
  258. 258:     }
  259. 259: