PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/www/libs/nette-dev/Application/PresenterRequest.php

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