diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
commit | 8ca6cc32b2c789a3149861159ad258f2cb9491e3 (patch) | |
tree | 2492de6f1528dd44eaa169a5c1555026d9cb75ec /library/vendor/Zend/Controller/Router/Route | |
parent | Initial commit. (diff) | |
download | icingaweb2-upstream.tar.xz icingaweb2-upstream.zip |
Adding upstream version 2.11.4.upstream/2.11.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/vendor/Zend/Controller/Router/Route')
-rw-r--r-- | library/vendor/Zend/Controller/Router/Route/Abstract.php | 119 | ||||
-rw-r--r-- | library/vendor/Zend/Controller/Router/Route/Chain.php | 228 | ||||
-rw-r--r-- | library/vendor/Zend/Controller/Router/Route/Hostname.php | 377 | ||||
-rw-r--r-- | library/vendor/Zend/Controller/Router/Route/Interface.php | 38 | ||||
-rw-r--r-- | library/vendor/Zend/Controller/Router/Route/Module.php | 322 | ||||
-rw-r--r-- | library/vendor/Zend/Controller/Router/Route/Regex.php | 316 | ||||
-rw-r--r-- | library/vendor/Zend/Controller/Router/Route/Static.php | 148 |
7 files changed, 1548 insertions, 0 deletions
diff --git a/library/vendor/Zend/Controller/Router/Route/Abstract.php b/library/vendor/Zend/Controller/Router/Route/Abstract.php new file mode 100644 index 0000000..7ec1e30 --- /dev/null +++ b/library/vendor/Zend/Controller/Router/Route/Abstract.php @@ -0,0 +1,119 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id$ + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** + * @see Zend_Controller_Router_Route_Interface + */ + +/** + * Abstract Route + * + * Implements interface and provides convenience methods + * + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +abstract class Zend_Controller_Router_Route_Abstract implements Zend_Controller_Router_Route_Interface +{ + /** + * URI delimiter + */ + const URI_DELIMITER = '/'; + + /** + * Wether this route is abstract or not + * + * @var boolean + */ + protected $_isAbstract = false; + + /** + * Path matched by this route + * + * @var string + */ + protected $_matchedPath = null; + + /** + * Get the version of the route + * + * @return integer + */ + public function getVersion() + { + return 2; + } + + /** + * Set partially matched path + * + * @param string $path + * @return void + */ + public function setMatchedPath($path) + { + $this->_matchedPath = $path; + } + + /** + * Get partially matched path + * + * @return string + */ + public function getMatchedPath() + { + return $this->_matchedPath; + } + + /** + * Check or set wether this is an abstract route or not + * + * @param boolean $flag + * @return boolean + */ + public function isAbstract($flag = null) + { + if ($flag !== null) { + $this->_isAbstract = $flag; + } + + return $this->_isAbstract; + } + + /** + * Create a new chain + * + * @param Zend_Controller_Router_Route_Abstract $route + * @param string $separator + * @return Zend_Controller_Router_Route_Chain + */ + public function chain(Zend_Controller_Router_Route_Abstract $route, $separator = '/') + { + + $chain = new Zend_Controller_Router_Route_Chain(); + $chain->chain($this)->chain($route, $separator); + + return $chain; + } +} diff --git a/library/vendor/Zend/Controller/Router/Route/Chain.php b/library/vendor/Zend/Controller/Router/Route/Chain.php new file mode 100644 index 0000000..a4414bd --- /dev/null +++ b/library/vendor/Zend/Controller/Router/Route/Chain.php @@ -0,0 +1,228 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id$ + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** Zend_Controller_Router_Route_Abstract */ + +/** + * Chain route is used for managing route chaining. + * + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Abstract +{ + + /** + * Routes + * + * @var array + */ + protected $_routes = array(); + + /** + * Separators + * + * @var array + */ + protected $_separators = array(); + + /** + * Instantiates route based on passed Zend_Config structure + * + * @param Zend_Config $config Configuration object + * @return Zend_Controller_Router_Route_Chain + */ + public static function getInstance(Zend_Config $config) + { + $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); + + return new self($config->route, $defs); + } + + /** + * Add a route to this chain + * + * @param Zend_Controller_Router_Route_Abstract $route + * @param string $separator + * @return Zend_Controller_Router_Route_Chain + */ + public function chain(Zend_Controller_Router_Route_Abstract $route, $separator = self::URI_DELIMITER) + { + $this->_routes[] = $route; + $this->_separators[] = $separator; + + return $this; + } + + /** + * Matches a user submitted path with a previously defined route. + * Assigns and returns an array of defaults on a successful match. + * + * @param Zend_Controller_Request_Http $request Request to get the path info from + * @param null $partial + * @return array|false An array of assigned values or a false on a mismatch + */ + public function match($request, $partial = null) + { + $rawPath = $request->getPathInfo(); + $path = trim($request->getPathInfo(), self::URI_DELIMITER); + $subPath = $path; + $values = array(); + $matchedPath = null; + + foreach ($this->_routes as $key => $route) { + if ($key > 0 + && $matchedPath !== null + && $subPath !== '' + && $subPath !== false + ) { + $separator = substr($subPath, 0, strlen($this->_separators[$key])); + + if ($separator !== $this->_separators[$key]) { + $request->setPathInfo($rawPath); + return false; + } + + $subPath = substr($subPath, strlen($separator)); + } + // TODO: Should be an interface method. Hack for 1.0 BC + if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) { + $match = $subPath; + } else { + $request->setPathInfo($subPath); + $match = $request; + } + + $res = $route->match($match, true); + + if ($res === false) { + $request->setPathInfo($rawPath); + return false; + } + + $matchedPath = $route->getMatchedPath(); + + if ($matchedPath !== null) { + $subPath = substr($subPath, strlen($matchedPath)); + } + + $values = $res + $values; + } + + $request->setPathInfo($path); + + if ($subPath !== '' && $subPath !== false) { + return false; + } + + return $values; + } + + /** + * Assembles a URL path defined by this route + * + * @param array $data An array of variable and value pairs used as parameters + * @param bool $reset + * @param bool $encode + * @return string Route path with user submitted parameters + */ + public function assemble($data = array(), $reset = false, $encode = false) + { + $value = ''; + $numRoutes = count($this->_routes); + + foreach ($this->_routes as $key => $route) { + if ($key > 0) { + $value .= $this->_separators[$key]; + } + + $value .= $route->assemble($data, $reset, $encode, (($numRoutes - 1) > $key)); + + if (method_exists($route, 'getVariables')) { + $variables = $route->getVariables(); + + foreach ($variables as $variable) { + $data[$variable] = null; + } + } + } + + return $value; + } + + /** + * Set the request object for this and the child routes + * + * @param Zend_Controller_Request_Abstract|null $request + * @return void + */ + public function setRequest(Zend_Controller_Request_Abstract $request = null) + { + $this->_request = $request; + + foreach ($this->_routes as $route) { + if (method_exists($route, 'setRequest')) { + $route->setRequest($request); + } + } + } + + /** + * Return a single parameter of route's defaults + * + * @param string $name Array key of the parameter + * @return string Previously set default + */ + public function getDefault($name) + { + $default = null; + foreach ($this->_routes as $route) { + if (method_exists($route, 'getDefault')) { + $current = $route->getDefault($name); + if (null !== $current) { + $default = $current; + } + } + } + + return $default; + } + + /** + * Return an array of defaults + * + * @return array Route defaults + */ + public function getDefaults() + { + $defaults = array(); + foreach ($this->_routes as $route) { + if (method_exists($route, 'getDefaults')) { + $defaults = array_merge($defaults, $route->getDefaults()); + } + } + + return $defaults; + } +} diff --git a/library/vendor/Zend/Controller/Router/Route/Hostname.php b/library/vendor/Zend/Controller/Router/Route/Hostname.php new file mode 100644 index 0000000..b2be1c1 --- /dev/null +++ b/library/vendor/Zend/Controller/Router/Route/Hostname.php @@ -0,0 +1,377 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id$ + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** Zend_Controller_Router_Route_Abstract */ + +/** + * Hostname Route + * + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @see http://manuals.rubyonrails.com/read/chapter/65 + */ +class Zend_Controller_Router_Route_Hostname extends Zend_Controller_Router_Route_Abstract +{ + + /** + * Host variable + * + * @var string + */ + protected $_hostVariable = ':'; + + /** + * Regex delimiter + * + * @var string + */ + protected $_regexDelimiter = '#'; + + /** + * Default regex string + * + * @var string|null + */ + protected $_defaultRegex = null; + + /** + * Holds names of all route's pattern variable names. Array index holds a position in host. + * + * @var array + */ + protected $_variables = array(); + + /** + * Holds Route patterns for all host parts. In case of a variable it stores it's regex + * requirement or null. In case of a static part, it holds only it's direct value. + * + * @var array + */ + protected $_parts = array(); + + /** + * Holds user submitted default values for route's variables. Name and value pairs. + * + * @var array + */ + protected $_defaults = array(); + + /** + * Holds user submitted regular expression patterns for route's variables' values. + * Name and value pairs. + * + * @var array + */ + protected $_requirements = array(); + + /** + * Default scheme + * + * @var string + */ + protected $_scheme = null; + + /** + * Associative array filled on match() that holds matched path values + * for given variable names. + * + * @var array + */ + protected $_values = array(); + + /** + * Current request object + * + * @var Zend_Controller_Request_Abstract + */ + protected $_request; + + /** + * Helper var that holds a count of route pattern's static parts + * for validation + * + * @var int + */ + private $_staticCount = 0; + + /** + * Set the request object + * + * @param Zend_Controller_Request_Abstract|null $request + */ + public function setRequest(Zend_Controller_Request_Abstract $request = null) + { + $this->_request = $request; + } + + /** + * Get the request object + * + * @return Zend_Controller_Request_Abstract $request + */ + public function getRequest() + { + if ($this->_request === null) { + $this->_request = Zend_Controller_Front::getInstance()->getRequest(); + } + + return $this->_request; + } + + /** + * Instantiates route based on passed Zend_Config structure + * + * @param Zend_Config $config Configuration object + * @return Zend_Controller_Router_Route_Hostname + */ + public static function getInstance(Zend_Config $config) + { + $reqs = ($config->reqs instanceof Zend_Config) ? $config->reqs->toArray() : array(); + $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); + $scheme = (isset($config->scheme)) ? $config->scheme : null; + + return new self($config->route, $defs, $reqs, $scheme); + } + + /** + * Prepares the route for mapping by splitting (exploding) it + * to a corresponding atomic parts. These parts are assigned + * a position which is later used for matching and preparing values. + * + * @param string $route Map used to match with later submitted hostname + * @param array $defaults Defaults for map variables with keys as variable names + * @param array $reqs Regular expression requirements for variables (keys as variable names) + * @param string $scheme + */ + public function __construct($route, $defaults = array(), $reqs = array(), $scheme = null) + { + $route = trim($route, '.'); + $this->_defaults = (array) $defaults; + $this->_requirements = (array) $reqs; + $this->_scheme = $scheme; + + if ($route != '') { + foreach (explode('.', $route) as $pos => $part) { + if (substr($part, 0, 1) == $this->_hostVariable) { + $name = substr($part, 1); + $this->_parts[$pos] = (isset($reqs[$name]) ? $reqs[$name] : $this->_defaultRegex); + $this->_variables[$pos] = $name; + } else { + $this->_parts[$pos] = $part; + $this->_staticCount++; + } + } + } + } + + /** + * Matches a user submitted path with parts defined by a map. Assigns and + * returns an array of variables on a successful match. + * + * @param Zend_Controller_Request_Http $request Request to get the host from + * @return array|false An array of assigned values or a false on a mismatch + */ + public function match($request) + { + // Check the scheme if required + if ($this->_scheme !== null) { + $scheme = $request->getScheme(); + + if ($scheme !== $this->_scheme) { + return false; + } + } + + // Get the host and remove unnecessary port information + $host = $request->getHttpHost(); + if (preg_match('#:\d+$#', $host, $result) === 1) { + $host = substr($host, 0, -strlen($result[0])); + } + + $hostStaticCount = 0; + $values = array(); + + $host = trim($host, '.'); + + if ($host != '') { + $host = explode('.', $host); + + foreach ($host as $pos => $hostPart) { + // Host is longer than a route, it's not a match + if (!array_key_exists($pos, $this->_parts)) { + return false; + } + + $name = isset($this->_variables[$pos]) ? $this->_variables[$pos] : null; + $hostPart = urldecode($hostPart); + + // If it's a static part, match directly + if ($name === null && $this->_parts[$pos] != $hostPart) { + return false; + } + + // If it's a variable with requirement, match a regex. If not - everything matches + if ($this->_parts[$pos] !== null + && !preg_match( + $this->_regexDelimiter . '^' . $this->_parts[$pos] . '$' . $this->_regexDelimiter . 'iu', + $hostPart + ) + ) { + return false; + } + + // If it's a variable store it's value for later + if ($name !== null) { + $values[$name] = $hostPart; + } else { + $hostStaticCount++; + } + } + } + + // Check if all static mappings have been matched + if ($this->_staticCount != $hostStaticCount) { + return false; + } + + $return = $values + $this->_defaults; + + // Check if all map variables have been initialized + foreach ($this->_variables as $var) { + if (!array_key_exists($var, $return)) { + return false; + } + } + + $this->_values = $values; + + return $return; + } + + /** + * Assembles user submitted parameters forming a hostname defined by this route + * + * @param array $data An array of variable and value pairs used as parameters + * @param boolean $reset Whether or not to set route defaults with those provided in $data + * @param boolean $encode + * @param boolean $partial + * @throws Zend_Controller_Router_Exception + * @return string Route path with user submitted parameters + */ + public function assemble($data = array(), $reset = false, $encode = false, $partial = false) + { + $host = array(); + $flag = false; + + foreach ($this->_parts as $key => $part) { + $name = isset($this->_variables[$key]) ? $this->_variables[$key] : null; + + $useDefault = false; + if (isset($name) && array_key_exists($name, $data) && $data[$name] === null) { + $useDefault = true; + } + + if (isset($name)) { + if (isset($data[$name]) && !$useDefault) { + $host[$key] = $data[$name]; + unset($data[$name]); + } elseif (!$reset && !$useDefault && isset($this->_values[$name])) { + $host[$key] = $this->_values[$name]; + } elseif (isset($this->_defaults[$name])) { + $host[$key] = $this->_defaults[$name]; + } else { + throw new Zend_Controller_Router_Exception($name . ' is not specified'); + } + } else { + $host[$key] = $part; + } + } + + $return = ''; + + foreach (array_reverse($host, true) as $key => $value) { + if ($flag || !isset($this->_variables[$key]) || $value !== $this->getDefault($this->_variables[$key]) + || $partial + ) { + if ($encode) { + $value = urlencode($value); + } + $return = '.' . $value . $return; + $flag = true; + } + } + + $url = trim($return, '.'); + + if ($this->_scheme !== null) { + $scheme = $this->_scheme; + } else { + $request = $this->getRequest(); + if ($request instanceof Zend_Controller_Request_Http) { + $scheme = $request->getScheme(); + } else { + $scheme = 'http'; + } + } + + $url = $scheme . '://' . $url; + + return $url; + } + + /** + * Return a single parameter of route's defaults + * + * @param string $name Array key of the parameter + * @return string Previously set default + */ + public function getDefault($name) + { + if (isset($this->_defaults[$name])) { + return $this->_defaults[$name]; + } + + return null; + } + + /** + * Return an array of defaults + * + * @return array Route defaults + */ + public function getDefaults() + { + return $this->_defaults; + } + + /** + * Get all variables which are used by the route + * + * @return array + */ + public function getVariables() + { + return $this->_variables; + } +} diff --git a/library/vendor/Zend/Controller/Router/Route/Interface.php b/library/vendor/Zend/Controller/Router/Route/Interface.php new file mode 100644 index 0000000..6a14f9d --- /dev/null +++ b/library/vendor/Zend/Controller/Router/Route/Interface.php @@ -0,0 +1,38 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id$ + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** Zend_Config */ + +/** + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +interface Zend_Controller_Router_Route_Interface +{ + public function match($path); + + public function assemble($data = array(), $reset = false, $encode = false); + + public static function getInstance(Zend_Config $config); +}
\ No newline at end of file diff --git a/library/vendor/Zend/Controller/Router/Route/Module.php b/library/vendor/Zend/Controller/Router/Route/Module.php new file mode 100644 index 0000000..2227495 --- /dev/null +++ b/library/vendor/Zend/Controller/Router/Route/Module.php @@ -0,0 +1,322 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id$ + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** Zend_Controller_Router_Route_Abstract */ + +/** + * Module Route + * + * Default route for module functionality + * + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @see http://manuals.rubyonrails.com/read/chapter/65 + */ +class Zend_Controller_Router_Route_Module extends Zend_Controller_Router_Route_Abstract +{ + + /** + * Default values for the route (ie. module, controller, action, params) + * + * @var array + */ + protected $_defaults; + + /** + * Default values for the route (ie. module, controller, action, params) + * + * @var array + */ + protected $_values = array(); + + /** + * @var boolean + */ + protected $_moduleValid = false; + + /** + * @var boolean + */ + protected $_keysSet = false; + + /**#@+ + * Array keys to use for module, controller, and action. Should be taken out of request. + * + * @var string + */ + protected $_moduleKey = 'module'; + protected $_controllerKey = 'controller'; + protected $_actionKey = 'action'; + /**#@-*/ + + /** + * @var Zend_Controller_Dispatcher_Interface + */ + protected $_dispatcher; + + /** + * @var Zend_Controller_Request_Abstract + */ + protected $_request; + + /** + * Get the version of the route + * + * @return int + */ + public function getVersion() + { + return 1; + } + + /** + * Instantiates route based on passed Zend_Config structure + * + * @param Zend_Config $config + * @return Zend_Controller_Router_Route_Module + */ + public static function getInstance(Zend_Config $config) + { + $frontController = Zend_Controller_Front::getInstance(); + + $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); + $dispatcher = $frontController->getDispatcher(); + $request = $frontController->getRequest(); + + return new self($defs, $dispatcher, $request); + } + + /** + * Constructor + * + * @param array $defaults Defaults for map variables with keys as variable names + * @param Zend_Controller_Dispatcher_Interface $dispatcher Dispatcher object + * @param Zend_Controller_Request_Abstract $request Request object + */ + public function __construct( + array $defaults = array(), + Zend_Controller_Dispatcher_Interface $dispatcher = null, + Zend_Controller_Request_Abstract $request = null + ) + { + $this->_defaults = $defaults; + + if (isset($request)) { + $this->_request = $request; + } + + if (isset($dispatcher)) { + $this->_dispatcher = $dispatcher; + } + } + + /** + * Set request keys based on values in request object + * + * @return void + */ + protected function _setRequestKeys() + { + if (null !== $this->_request) { + $this->_moduleKey = $this->_request->getModuleKey(); + $this->_controllerKey = $this->_request->getControllerKey(); + $this->_actionKey = $this->_request->getActionKey(); + } + + if (null !== $this->_dispatcher) { + $this->_defaults += array( + $this->_controllerKey => $this->_dispatcher->getDefaultControllerName(), + $this->_actionKey => $this->_dispatcher->getDefaultAction(), + $this->_moduleKey => $this->_dispatcher->getDefaultModule() + ); + } + + $this->_keysSet = true; + } + + /** + * Matches a user submitted path. Assigns and returns an array of variables + * on a successful match. + * + * If a request object is registered, it uses its setModuleName(), + * setControllerName(), and setActionName() accessors to set those values. + * Always returns the values as an array. + * + * @param string $path Path used to match against this routing map + * @param boolean $partial + * @return array An array of assigned values or a false on a mismatch + */ + public function match($path, $partial = false) + { + $this->_setRequestKeys(); + + $values = array(); + $params = array(); + + if (!$partial) { + $path = trim($path, self::URI_DELIMITER); + } else { + $matchedPath = $path; + } + + if ($path != '') { + $path = explode(self::URI_DELIMITER, $path); + + if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) { + $values[$this->_moduleKey] = array_shift($path); + $this->_moduleValid = true; + } + + if (count($path) && !empty($path[0])) { + $values[$this->_controllerKey] = array_shift($path); + } + + if (count($path) && !empty($path[0])) { + $values[$this->_actionKey] = array_shift($path); + } + + if ($numSegs = count($path)) { + for ($i = 0; $i < $numSegs; $i = $i + 2) { + $key = urldecode($path[$i]); + $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null; + $params[$key] = (isset($params[$key]) ? (array_merge((array)$params[$key], array($val))) : $val); + } + } + } + + if ($partial) { + $this->setMatchedPath($matchedPath); + } + + $this->_values = $values + $params; + + return $this->_values + $this->_defaults; + } + + /** + * Assembles user submitted parameters forming a URL path defined by this route + * + * @param array $data An array of variable and value pairs used as parameters + * @param boolean $reset Weither to reset the current params + * @param boolean $encode + * @param boolean $partial + * @return string Route path with user submitted parameters + */ + public function assemble($data = array(), $reset = false, $encode = true, $partial = false) + { + if (!$this->_keysSet) { + $this->_setRequestKeys(); + } + + $params = (!$reset) ? $this->_values : array(); + + foreach ($data as $key => $value) { + if ($value !== null) { + $params[$key] = $value; + } elseif (isset($params[$key])) { + unset($params[$key]); + } + } + + $params += $this->_defaults; + + $url = ''; + + if ($this->_moduleValid || array_key_exists($this->_moduleKey, $data)) { + if ($params[$this->_moduleKey] != $this->_defaults[$this->_moduleKey]) { + $module = $params[$this->_moduleKey]; + } + } + unset($params[$this->_moduleKey]); + + $controller = $params[$this->_controllerKey]; + unset($params[$this->_controllerKey]); + + $action = $params[$this->_actionKey]; + unset($params[$this->_actionKey]); + + foreach ($params as $key => $value) { + $key = ($encode) ? urlencode($key) : $key; + if (is_array($value)) { + foreach ($value as $arrayValue) { + $arrayValue = ($encode) ? urlencode($arrayValue) : $arrayValue; + $url .= self::URI_DELIMITER . $key; + $url .= self::URI_DELIMITER . $arrayValue; + } + } else { + if ($encode) { + $value = urlencode($value); + } + $url .= self::URI_DELIMITER . $key; + $url .= self::URI_DELIMITER . $value; + } + } + + if (!empty($url) || $action !== $this->_defaults[$this->_actionKey]) { + if ($encode) { + $action = urlencode($action); + } + $url = self::URI_DELIMITER . $action . $url; + } + + if (!empty($url) || $controller !== $this->_defaults[$this->_controllerKey]) { + if ($encode) { + $controller = urlencode($controller); + } + $url = self::URI_DELIMITER . $controller . $url; + } + + if (isset($module)) { + if ($encode) { + $module = urlencode($module); + } + $url = self::URI_DELIMITER . $module . $url; + } + + return ltrim($url, self::URI_DELIMITER); + } + + /** + * Return a single parameter of route's defaults + * + * @param string $name Array key of the parameter + * @return string Previously set default + */ + public function getDefault($name) + { + if (isset($this->_defaults[$name])) { + return $this->_defaults[$name]; + } + } + + /** + * Return an array of defaults + * + * @return array Route defaults + */ + public function getDefaults() + { + return $this->_defaults; + } +} diff --git a/library/vendor/Zend/Controller/Router/Route/Regex.php b/library/vendor/Zend/Controller/Router/Route/Regex.php new file mode 100644 index 0000000..8dea1c0 --- /dev/null +++ b/library/vendor/Zend/Controller/Router/Route/Regex.php @@ -0,0 +1,316 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id$ + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** Zend_Controller_Router_Route_Abstract */ + +/** + * Regex Route + * + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Controller_Router_Route_Regex extends Zend_Controller_Router_Route_Abstract +{ + + /** + * Regex string + * + * @var string|null + */ + protected $_regex = null; + + /** + * Default values for the route (ie. module, controller, action, params) + * + * @var array + */ + protected $_defaults = array(); + + /** + * Reverse + * + * @var string|null + */ + protected $_reverse = null; + + /** + * Map + * + * @var array + */ + protected $_map = array(); + + /** + * Values + * + * @var array + */ + protected $_values = array(); + + /** + * Instantiates route based on passed Zend_Config structure + * + * @param Zend_Config $config Configuration object + * @return Zend_Controller_Router_Route_Regex + */ + public static function getInstance(Zend_Config $config) + { + $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); + $map = ($config->map instanceof Zend_Config) ? $config->map->toArray() : array(); + $reverse = (isset($config->reverse)) ? $config->reverse : null; + + return new self($config->route, $defs, $map, $reverse); + } + + /** + * Constructor + * + * @param $route + * @param array $defaults + * @param array $map + * @param null $reverse + */ + public function __construct($route, $defaults = array(), $map = array(), $reverse = null) + { + $this->_regex = $route; + $this->_defaults = (array) $defaults; + $this->_map = (array) $map; + $this->_reverse = $reverse; + } + + /** + * Get the version of the route + * + * @return int + */ + public function getVersion() + { + return 1; + } + + /** + * Matches a user submitted path with a previously defined route. + * Assigns and returns an array of defaults on a successful match. + * + * @param string $path Path used to match against this routing map + * @return array|false An array of assigned values or a false on a mismatch + */ + public function match($path, $partial = false) + { + if (!$partial) { + $path = trim(urldecode($path), self::URI_DELIMITER); + $regex = '#^' . $this->_regex . '$#i'; + } else { + $regex = '#^' . $this->_regex . '#i'; + } + + $res = preg_match($regex, $path, $values); + + if ($res === 0) { + return false; + } + + if ($partial) { + $this->setMatchedPath($values[0]); + } + + // array_filter_key()? Why isn't this in a standard PHP function set yet? :) + foreach ($values as $i => $value) { + if (!is_int($i) || $i === 0) { + unset($values[$i]); + } + } + + $this->_values = $values; + + $values = $this->_getMappedValues($values); + $defaults = $this->_getMappedValues($this->_defaults, false, true); + $return = $values + $defaults; + + return $return; + } + + /** + * Maps numerically indexed array values to it's associative mapped counterpart. + * Or vice versa. Uses user provided map array which consists of index => name + * parameter mapping. If map is not found, it returns original array. + * + * Method strips destination type of keys form source array. Ie. if source array is + * indexed numerically then every associative key will be stripped. Vice versa if reversed + * is set to true. + * + * @param array $values Indexed or associative array of values to map + * @param boolean $reversed False means translation of index to association. True means reverse. + * @param boolean $preserve Should wrong type of keys be preserved or stripped. + * @return array An array of mapped values + */ + protected function _getMappedValues($values, $reversed = false, $preserve = false) + { + if (count($this->_map) == 0) { + return $values; + } + + $return = array(); + + foreach ($values as $key => $value) { + if (is_int($key) && !$reversed) { + if (array_key_exists($key, $this->_map)) { + $index = $this->_map[$key]; + } elseif (false === ($index = array_search($key, $this->_map))) { + $index = $key; + } + $return[$index] = $values[$key]; + } elseif ($reversed) { + $index = $key; + if (!is_int($key)) { + if (array_key_exists($key, $this->_map)) { + $index = $this->_map[$key]; + } else { + $index = array_search($key, $this->_map, true); + } + } + if (false !== $index) { + $return[$index] = $values[$key]; + } + } elseif ($preserve) { + $return[$key] = $value; + } + } + + return $return; + } + + /** + * Assembles a URL path defined by this route + * + * @param array $data An array of name (or index) and value pairs used as parameters + * @param boolean $reset + * @param boolean $encode + * @param boolean $partial + * @throws Zend_Controller_Router_Exception + * @return string Route path with user submitted parameters + */ + public function assemble($data = array(), $reset = false, $encode = false, $partial = false) + { + if ($this->_reverse === null) { + throw new Zend_Controller_Router_Exception('Cannot assemble. Reversed route is not specified.'); + } + + $defaultValuesMapped = $this->_getMappedValues($this->_defaults, true, false); + $matchedValuesMapped = $this->_getMappedValues($this->_values, true, false); + $dataValuesMapped = $this->_getMappedValues($data, true, false); + + // handle resets, if so requested (By null value) to do so + if (($resetKeys = array_search(null, $dataValuesMapped, true)) !== false) { + foreach ((array)$resetKeys as $resetKey) { + if (isset($matchedValuesMapped[$resetKey])) { + unset($matchedValuesMapped[$resetKey]); + unset($dataValuesMapped[$resetKey]); + } + } + } + + // merge all the data together, first defaults, then values matched, then supplied + $mergedData = $defaultValuesMapped; + $mergedData = $this->_arrayMergeNumericKeys($mergedData, $matchedValuesMapped); + $mergedData = $this->_arrayMergeNumericKeys($mergedData, $dataValuesMapped); + + if ($encode) { + foreach ($mergedData as $key => &$value) { + $value = urlencode($value); + } + } + + ksort($mergedData); + + $return = @vsprintf($this->_reverse, $mergedData); + + if ($return === false) { + throw new Zend_Controller_Router_Exception('Cannot assemble. Too few arguments?'); + } + + return $return; + } + + /** + * Return a single parameter of route's defaults + * + * @param string $name Array key of the parameter + * @return string Previously set default + */ + public function getDefault($name) + { + if (isset($this->_defaults[$name])) { + return $this->_defaults[$name]; + } + } + + /** + * Return an array of defaults + * + * @return array Route defaults + */ + public function getDefaults() + { + return $this->_defaults; + } + + /** + * Get all variables which are used by the route + * + * @return array + */ + public function getVariables() + { + $variables = array(); + + foreach ($this->_map as $key => $value) { + if (is_numeric($key)) { + $variables[] = $value; + } else { + $variables[] = $key; + } + } + + return $variables; + } + + /** + * _arrayMergeNumericKeys() - allows for a strict key (numeric's included) array_merge. + * php's array_merge() lacks the ability to merge with numeric keys. + * + * @param array $array1 + * @param array $array2 + * @return array + */ + protected function _arrayMergeNumericKeys(Array $array1, Array $array2) + { + $returnArray = $array1; + foreach ($array2 as $array2Index => $array2Value) { + $returnArray[$array2Index] = $array2Value; + } + + return $returnArray; + } +} diff --git a/library/vendor/Zend/Controller/Router/Route/Static.php b/library/vendor/Zend/Controller/Router/Route/Static.php new file mode 100644 index 0000000..86363da --- /dev/null +++ b/library/vendor/Zend/Controller/Router/Route/Static.php @@ -0,0 +1,148 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @version $Id$ + * @license http://framework.zend.com/license/new-bsd New BSD License + */ + +/** Zend_Controller_Router_Route_Abstract */ + +/** + * StaticRoute is used for managing static URIs. + * + * It's a lot faster compared to the standard Route implementation. + * + * @package Zend_Controller + * @subpackage Router + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Controller_Router_Route_Static extends Zend_Controller_Router_Route_Abstract +{ + + /** + * Route + * + * @var string|null + */ + protected $_route = null; + + /** + * Default values for the route (ie. module, controller, action, params) + * + * @var array + */ + protected $_defaults = array(); + + /** + * Get the version of the route + * + * @return int + */ + public function getVersion() + { + return 1; + } + + /** + * Instantiates route based on passed Zend_Config structure + * + * @param Zend_Config $config Configuration object + * @return Zend_Controller_Router_Route_Static + */ + public static function getInstance(Zend_Config $config) + { + $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); + + return new self($config->route, $defs); + } + + /** + * Prepares the route for mapping. + * + * @param string $route Map used to match with later submitted URL path + * @param array $defaults Defaults for map variables with keys as variable names + */ + public function __construct($route, $defaults = array()) + { + $this->_route = trim($route, self::URI_DELIMITER); + $this->_defaults = (array) $defaults; + } + + /** + * Matches a user submitted path with a previously defined route. + * Assigns and returns an array of defaults on a successful match. + * + * @param string $path Path used to match against this routing map + * @return array|false An array of assigned values or a false on a mismatch + */ + public function match($path, $partial = false) + { + if ($partial) { + if ((empty($path) && empty($this->_route)) + || (substr($path, 0, strlen($this->_route)) === $this->_route) + ) { + $this->setMatchedPath($this->_route); + + return $this->_defaults; + } + } else { + if (trim($path, self::URI_DELIMITER) == $this->_route) { + return $this->_defaults; + } + } + + return false; + } + + /** + * Assembles a URL path defined by this route + * + * @param array $data An array of variable and value pairs used as parameters + * @return string Route path with user submitted parameters + */ + public function assemble($data = array(), $reset = false, $encode = false, $partial = false) + { + return $this->_route; + } + + /** + * Return a single parameter of route's defaults + * + * @param string $name Array key of the parameter + * @return string Previously set default + */ + public function getDefault($name) + { + if (isset($this->_defaults[$name])) { + return $this->_defaults[$name]; + } + + return null; + } + + /** + * Return an array of defaults + * + * @return array Route defaults + */ + public function getDefaults() + { + return $this->_defaults; + } +} |