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