PageRenderTime 56ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins_repo/openXWorkflow/www/admin/plugins/openXWorkflow/library/Zend/Controller/Router/Route/Chain.php

https://github.com/orchestra-io/sample-openx
PHP | 168 lines | 81 code | 27 blank | 60 comment | 14 complexity | 76e99a0ad0498129de2ae4008bb89057 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @package Zend_Controller
  16. * @subpackage Router
  17. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @version $Id: Route.php 1847 2006-11-23 11:36:41Z martel $
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Controller_Router_Route_Abstract */
  22. require_once 'Zend/Controller/Router/Route/Abstract.php';
  23. /**
  24. * Chain route is used for managing route chaining.
  25. *
  26. * @package Zend_Controller
  27. * @subpackage Router
  28. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Abstract
  32. {
  33. protected $_routes = array();
  34. protected $_separators = array();
  35. /**
  36. * Instantiates route based on passed Zend_Config structure
  37. *
  38. * @param Zend_Config $config Configuration object
  39. */
  40. public static function getInstance(Zend_Config $config)
  41. {
  42. $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
  43. return new self($config->route, $defs);
  44. }
  45. /**
  46. * Add a route to this chain
  47. *
  48. * @param Zend_Controller_Router_Route_Abstract $route
  49. * @param string $separator
  50. * @return Zend_Controller_Router_Route_Chain
  51. */
  52. public function chain(Zend_Controller_Router_Route_Abstract $route, $separator = '/')
  53. {
  54. $this->_routes[] = $route;
  55. $this->_separators[] = $separator;
  56. return $this;
  57. }
  58. /**
  59. * Matches a user submitted path with a previously defined route.
  60. * Assigns and returns an array of defaults on a successful match.
  61. *
  62. * @param Zend_Controller_Request_Http $request Request to get the path info from
  63. * @return array|false An array of assigned values or a false on a mismatch
  64. */
  65. public function match($request, $partial = null)
  66. {
  67. $path = trim($request->getPathInfo(), '/');
  68. $subPath = $path;
  69. $values = array();
  70. foreach ($this->_routes as $key => $route) {
  71. if ($key > 0 && $matchedPath !== null) {
  72. $separator = substr($subPath, 0, strlen($this->_separators[$key]));
  73. if ($separator !== $this->_separators[$key]) {
  74. return false;
  75. }
  76. $subPath = substr($subPath, strlen($separator));
  77. }
  78. // TODO: Should be an interface method. Hack for 1.0 BC
  79. if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) {
  80. $match = $subPath;
  81. } else {
  82. $request->setPathInfo($subPath);
  83. $match = $request;
  84. }
  85. $res = $route->match($match, true);
  86. if ($res === false) {
  87. return false;
  88. }
  89. $matchedPath = $route->getMatchedPath();
  90. if ($matchedPath !== null) {
  91. $subPath = substr($subPath, strlen($matchedPath));
  92. $separator = substr($subPath, 0, strlen($this->_separators[$key]));
  93. }
  94. $values = $res + $values;
  95. }
  96. $request->setPathInfo($path);
  97. if ($subPath !== '' && $subPath !== false) {
  98. return false;
  99. }
  100. return $values;
  101. }
  102. /**
  103. * Assembles a URL path defined by this route
  104. *
  105. * @param array $data An array of variable and value pairs used as parameters
  106. * @return string Route path with user submitted parameters
  107. */
  108. public function assemble($data = array(), $reset = false, $encode = false)
  109. {
  110. $value = '';
  111. $numRoutes = count($this->_routes);
  112. foreach ($this->_routes as $key => $route) {
  113. if ($key > 0) {
  114. $value .= $this->_separators[$key];
  115. }
  116. $value .= $route->assemble($data, $reset, $encode, (($numRoutes - 1) > $key));
  117. if (method_exists($route, 'getVariables')) {
  118. $variables = $route->getVariables();
  119. foreach ($variables as $variable) {
  120. $data[$variable] = null;
  121. }
  122. }
  123. }
  124. return $value;
  125. }
  126. /**
  127. * Set the request object for this and the child routes
  128. *
  129. * @param Zend_Controller_Request_Abstract|null $request
  130. * @return void
  131. */
  132. public function setRequest(Zend_Controller_Request_Abstract $request = null)
  133. {
  134. $this->_request = $request;
  135. foreach ($this->_routes as $route) {
  136. if (method_exists($route, 'setRequest')) {
  137. $route->setRequest($request);
  138. }
  139. }
  140. }
  141. }