PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/library/XenForo/RouteMatch.php

https://github.com/hanguyenhuu/DTUI_201105
PHP | 195 lines | 64 code | 19 blank | 112 comment | 1 complexity | 417af75ed3a9871395e4d13f299ff7cc MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * Class that represents a result to be returned by a {@link XenForo_Route_Interface}.
  4. *
  5. * @package XenForo_Mvc
  6. */
  7. class XenForo_RouteMatch
  8. {
  9. /**
  10. * If not null, represents a modified version of the routing path to be passed
  11. * into subsequent rules (if there are any). Useful only when the rule generating
  12. * the object doesn't list a controller and action. Can be set to an empty string
  13. * to cause the next rule to receive {@link XenForo_Router::$_routePathIfEmpty} as the
  14. * routing path.
  15. *
  16. * @var null|string
  17. */
  18. public $_modifiedRoutePath = null;
  19. /**
  20. * If not empty, the type of response (eg, html, json) that should be returned via
  21. * the response. If left as an empty string, any previously set type will be used.
  22. *
  23. * @var string
  24. */
  25. protected $_responseType = '';
  26. /**
  27. * The name of the controller class to handle this match. If not empty, no further
  28. * rules will be processed and routing will finishe.
  29. *
  30. * @var string
  31. */
  32. protected $_controllerName = '';
  33. /**
  34. * The name of the action to call in the specified controller class. Applies only when
  35. * {@link $controllerName} is not empty; must be specified if a controller is specified.
  36. *
  37. * @var string
  38. */
  39. protected $_action = '';
  40. /**
  41. * The major section of the page being routed to. This is used as a navigation aid;
  42. * for example, to show the right tab and child sections.
  43. *
  44. * @var string
  45. */
  46. protected $_majorSection = '';
  47. /**
  48. * The minor section of the page being routed to. This can, for example, allow the
  49. * current section within a tab to be displayed as if it's selected.
  50. *
  51. * @var string
  52. */
  53. protected $_minorSection = '';
  54. /**
  55. * Constructor. Allows quick set of the controller and action. Other elements
  56. * should be set directly via the properties.
  57. *
  58. * @param string If routing to a controller, the controller name to call
  59. * @param string|false If routing to a controller, the action in that controller
  60. * @param string The major section of the page we're being routed to
  61. * @param string The minor section of the page we're being routed to
  62. */
  63. public function __construct($controllerName = '', $action = false, $majorSection = '', $minorSection = '')
  64. {
  65. $this->setControllerName($controllerName);
  66. if ($action !== false)
  67. {
  68. $this->setAction($action);
  69. }
  70. $this->setSections($majorSection, $minorSection);
  71. }
  72. /**
  73. * Sets the controller name.
  74. *
  75. * @param string $controllerName
  76. */
  77. public function setControllerName($controllerName)
  78. {
  79. $this->_controllerName = strval($controllerName);
  80. }
  81. /**
  82. * Gets the controller name.
  83. *
  84. * @return string
  85. */
  86. public function getControllerName()
  87. {
  88. return $this->_controllerName;
  89. }
  90. /**
  91. * Helper method to set the action. This will automatically translate the
  92. * action into a a more usable form, by replacing dashes with word breaks.
  93. * For example, confirm-test will be mapped to ConfirmTest.
  94. *
  95. * @param string
  96. */
  97. public function setAction($action)
  98. {
  99. $this->_action = $action;
  100. }
  101. /**
  102. * Gets the action.
  103. *
  104. * @return string
  105. */
  106. public function getAction()
  107. {
  108. return $this->_action;
  109. }
  110. /**
  111. * Sets the response type.
  112. *
  113. * @param string $responseType
  114. */
  115. public function setResponseType($responseType)
  116. {
  117. $this->_responseType = strval($responseType);
  118. }
  119. /**
  120. * Gets the response type.
  121. *
  122. * @return string
  123. */
  124. public function getResponseType()
  125. {
  126. return $this->_responseType;
  127. }
  128. /**
  129. * Sets the modified route path that will be passed to subsequent matches.
  130. *
  131. * @param string|null $routePath
  132. */
  133. public function setModifiedRoutePath($routePath)
  134. {
  135. $this->_modifiedRoutePath = $routePath;
  136. }
  137. /**
  138. * Gets the modified route path. If null, no modification is requested.
  139. *
  140. * @return string|null
  141. */
  142. public function getModifiedRoutePath()
  143. {
  144. return $this->_modifiedRoutePath;
  145. }
  146. /**
  147. * Sets the major and minor sections that we're routing to. This is used to
  148. * aid navigation.
  149. *
  150. * @param string $majorSection
  151. * @param string $minorSection
  152. */
  153. public function setSections($majorSection, $minorSection = '')
  154. {
  155. $this->_majorSection = strval($majorSection);
  156. $this->_minorSection = strval($minorSection);
  157. }
  158. /**
  159. * Gets the major section that the routing points to.
  160. *
  161. * @return string
  162. */
  163. public function getMajorSection()
  164. {
  165. return $this->_majorSection;
  166. }
  167. /**
  168. * Gets the minor section that the routing points to.
  169. *
  170. * @return string
  171. */
  172. public function getMinorSection()
  173. {
  174. return $this->_minorSection;
  175. }
  176. }