PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Nette/Application/PresenterRequest.php

https://github.com/DocX/nette
PHP | 260 lines | 90 code | 60 blank | 110 comment | 0 complexity | 55825978231d64df7ebd08d7e6d8f860 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Nette Framework
  4. *
  5. * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  6. *
  7. * This source file is subject to the "Nette license" that is bundled
  8. * with this package in the file license.txt.
  9. *
  10. * For more information please see http://nettephp.com
  11. *
  12. * @copyright Copyright (c) 2004, 2009 David Grudl
  13. * @license http://nettephp.com/license Nette license
  14. * @link http://nettephp.com
  15. * @category Nette
  16. * @package Nette\Application
  17. */
  18. /*namespace Nette\Application;*/
  19. require_once dirname(__FILE__) . '/../FreezableObject.php';
  20. /**
  21. * Presenter request. Immutable object.
  22. *
  23. * @author David Grudl
  24. * @copyright Copyright (c) 2004, 2009 David Grudl
  25. * @package Nette\Application
  26. *
  27. * @property string $presenterName
  28. * @property array $params
  29. * @property array $post
  30. * @property array $files
  31. */
  32. final class PresenterRequest extends /*Nette\*/FreezableObject
  33. {
  34. /** method */
  35. const FORWARD = 'FORWARD';
  36. /** flag */
  37. const SECURED = 'secured';
  38. /** flag */
  39. const RESTORED = 'restored';
  40. /** @var string */
  41. private $method;
  42. /** @var array */
  43. private $flags = array();
  44. /** @var string */
  45. private $name;
  46. /** @var array */
  47. private $params;
  48. /** @var array */
  49. private $post;
  50. /** @var array */
  51. private $files;
  52. /**
  53. * @param string fully qualified presenter name (module:module:presenter)
  54. * @param string method
  55. * @param array variables provided to the presenter usually via URL
  56. * @param array variables provided to the presenter via POST
  57. * @param array all uploaded files
  58. */
  59. public function __construct($name, $method, array $params, array $post = array(), array $files = array(), array $flags = array())
  60. {
  61. $this->name = $name;
  62. $this->method = $method;
  63. $this->params = $params;
  64. $this->post = $post;
  65. $this->files = $files;
  66. $this->flags = $flags;
  67. }
  68. /**
  69. * Sets the presenter name.
  70. * @param string
  71. * @return PresenterRequest provides a fluent interface
  72. */
  73. public function setPresenterName($name)
  74. {
  75. $this->updating();
  76. $this->name = $name;
  77. return $this;
  78. }
  79. /**
  80. * Retrieve the presenter name.
  81. * @return string
  82. */
  83. public function getPresenterName()
  84. {
  85. return $this->name;
  86. }
  87. /**
  88. * Sets variables provided to the presenter.
  89. * @param array
  90. * @return PresenterRequest provides a fluent interface
  91. */
  92. public function setParams(array $params)
  93. {
  94. $this->updating();
  95. $this->params = $params;
  96. return $this;
  97. }
  98. /**
  99. * Returns all variables provided to the presenter (usually via URL).
  100. * @return array
  101. */
  102. public function getParams()
  103. {
  104. return $this->params;
  105. }
  106. /**
  107. * Sets variables provided to the presenter via POST.
  108. * @param array
  109. * @return PresenterRequest provides a fluent interface
  110. */
  111. public function setPost(array $params)
  112. {
  113. $this->updating();
  114. $this->post = $params;
  115. return $this;
  116. }
  117. /**
  118. * Returns all variables provided to the presenter via POST.
  119. * @return array
  120. */
  121. public function getPost()
  122. {
  123. return $this->post;
  124. }
  125. /**
  126. * Sets all uploaded files.
  127. * @param array
  128. * @return PresenterRequest provides a fluent interface
  129. */
  130. public function setFiles(array $files)
  131. {
  132. $this->updating();
  133. $this->files = $files;
  134. return $this;
  135. }
  136. /**
  137. * Returns all uploaded files.
  138. * @return array
  139. */
  140. public function getFiles()
  141. {
  142. return $this->files;
  143. }
  144. /**
  145. * Sets the method.
  146. * @param string
  147. * @return PresenterRequest provides a fluent interface
  148. */
  149. public function setMethod($method)
  150. {
  151. $this->method = $method;
  152. return $this;
  153. }
  154. /**
  155. * Returns the method.
  156. * @return string
  157. */
  158. public function getMethod()
  159. {
  160. return $this->method;
  161. }
  162. /**
  163. * Checks if the method is the given one.
  164. * @param string
  165. * @return bool
  166. */
  167. public function isMethod($method)
  168. {
  169. return strcasecmp($this->method, $method) === 0;
  170. }
  171. /**
  172. * Checks if the method is POST.
  173. * @return bool
  174. */
  175. public function isPost()
  176. {
  177. return strcasecmp($this->method, 'post') === 0;
  178. }
  179. /**
  180. * Sets the flag.
  181. * @param string
  182. * @param bool
  183. * @return PresenterRequest provides a fluent interface
  184. */
  185. public function setFlag($flag, $value = TRUE)
  186. {
  187. $this->updating();
  188. $this->flags[$flag] = (bool) $value;
  189. return $this;
  190. }
  191. /**
  192. * Checks the flag.
  193. * @param string
  194. * @return bool
  195. */
  196. public function hasFlag($flag)
  197. {
  198. return !empty($this->flags[$flag]);
  199. }
  200. }