import v1.1.0_beta1 | 2009-08-21

This commit is contained in:
2019-07-17 22:16:19 +02:00
parent 2c1152f0d3
commit 8dee6b1a10
2306 changed files with 251360 additions and 23428 deletions

View File

@ -19,7 +19,9 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Controller_Router_Route_Interface */
/**
* @see Zend_Controller_Router_Route_Interface
*/
require_once 'Zend/Controller/Router/Route/Interface.php';
/**
@ -34,12 +36,74 @@ require_once 'Zend/Controller/Router/Route/Interface.php';
*/
abstract class Zend_Controller_Router_Route_Abstract implements Zend_Controller_Router_Route_Interface
{
/**
* Wether this route is abstract or not
*
* @var boolean
*/
protected $_isAbstract = false;
public function getVersion() {
/**
* Path matched by this route
*
* @var string
*/
protected $_matchedPath = null;
/**
* Get the version of the route
*
* @return integer
*/
public function getVersion()
{
return 2;
}
public function chain(Zend_Controller_Router_Route_Interface $route, $separator = '/')
/**
* 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 = '/')
{
require_once 'Zend/Controller/Router/Route/Chain.php';

View File

@ -32,7 +32,6 @@ require_once 'Zend/Controller/Router/Route/Abstract.php';
*/
class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Abstract
{
protected $_routes = array();
protected $_separators = array();
@ -42,11 +41,21 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
* @param Zend_Config $config Configuration object
*/
public static function getInstance(Zend_Config $config)
{ }
public function chain(Zend_Controller_Router_Route_Interface $route, $separator = '/') {
$this->_routes[] = $route;
{
$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 = '/')
{
$this->_routes[] = $route;
$this->_separators[] = $separator;
return $this;
@ -57,30 +66,53 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
* 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 Zend_Controller_Request_Http $request Request to get the path info from
* @return array|false An array of assigned values or a false on a mismatch
*/
public function match($request, $partial = null)
{
$path = $request->getPathInfo();
$values = array();
$path = trim($request->getPathInfo(), '/');
$subPath = $path;
$values = array();
foreach ($this->_routes as $key => $route) {
if ($key > 0 && $matchedPath !== null) {
$separator = substr($subPath, 0, strlen($this->_separators[$key]));
if ($separator !== $this->_separators[$key]) {
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 = $request->getPathInfo();
$match = $subPath;
} else {
$match = $request;
$request->setPathInfo($subPath);
$match = $request;
}
$res = $route->match($match);
if ($res === false) return false;
$res = $route->match($match, true);
if ($res === false) {
return false;
}
$matchedPath = $route->getMatchedPath();
if ($matchedPath !== null) {
$subPath = substr($subPath, strlen($matchedPath));
$separator = substr($subPath, 0, strlen($this->_separators[$key]));
}
$values = $res + $values;
}
$request->setPathInfo($path);
if ($subPath !== '' && $subPath !== false) {
return false;
}
return $values;
@ -94,14 +126,15 @@ class Zend_Controller_Router_Route_Chain extends Zend_Controller_Router_Route_Ab
*/
public function assemble($data = array(), $reset = false, $encode = false)
{
$value = '';
$value = '';
$numRoutes = count($this->_routes);
foreach ($this->_routes as $key => $route) {
if ($key > 0) {
$value .= $this->_separators[$key];
}
$value .= $route->assemble($data, $reset, $encode);
$value .= $route->assemble($data, $reset, $encode, (($numRoutes - 1) > $key));
if (method_exists($route, 'getVariables')) {
$variables = $route->getVariables();

View File

@ -248,7 +248,7 @@ class Zend_Controller_Router_Route_Hostname extends Zend_Controller_Router_Route
* @param boolean $reset Whether or not to set route defaults with those provided in $data
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = false)
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
{
$host = array();
$flag = false;
@ -281,7 +281,7 @@ class Zend_Controller_Router_Route_Hostname extends Zend_Controller_Router_Route
$return = '';
foreach (array_reverse($host, true) as $key => $value) {
if ($flag || !isset($this->_variables[$key]) || $value !== $this->getDefault($this->_variables[$key])) {
if ($flag || !isset($this->_variables[$key]) || $value !== $this->getDefault($this->_variables[$key]) || $partial) {
if ($encode) $value = urlencode($value);
$return = '.' . $value . $return;
$flag = true;

View File

@ -15,7 +15,7 @@
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Module.php 12310 2008-11-05 20:49:16Z dasprid $
* @version $Id: Module.php 15461 2009-05-09 15:54:21Z dasprid $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
@ -78,8 +78,13 @@ class Zend_Controller_Router_Route_Module extends Zend_Controller_Router_Route_A
*/
public static function getInstance(Zend_Config $config)
{
$defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array();
return new self($defs);
$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);
}
/**
@ -139,16 +144,20 @@ class Zend_Controller_Router_Route_Module extends Zend_Controller_Router_Route_A
* @param string $path Path used to match against this routing map
* @return array An array of assigned values or a false on a mismatch
*/
public function match($path)
public function match($path, $partial = false)
{
$this->_setRequestKeys();
$values = array();
$params = array();
$path = trim($path, self::URI_DELIMITER);
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])) {
@ -172,6 +181,10 @@ class Zend_Controller_Router_Route_Module extends Zend_Controller_Router_Route_A
}
}
}
if ($partial) {
$this->setMatchedPath($matchedPath);
}
$this->_values = $values + $params;
@ -185,7 +198,7 @@ class Zend_Controller_Router_Route_Module extends Zend_Controller_Router_Route_A
* @param bool $reset Weither to reset the current params
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = true)
public function assemble($data = array(), $reset = false, $encode = true, $partial = false)
{
if (!$this->_keysSet) {
$this->_setRequestKeys();

View File

@ -15,7 +15,7 @@
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Regex.php 12525 2008-11-10 20:18:32Z ralph $
* @version $Id: Regex.php 15461 2009-05-09 15:54:21Z dasprid $
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
@ -53,10 +53,10 @@ class Zend_Controller_Router_Route_Regex extends Zend_Controller_Router_Route_Ab
public function __construct($route, $defaults = array(), $map = array(), $reverse = null)
{
$this->_regex = '#^' . $route . '$#i';
$this->_regex = $route;
$this->_defaults = (array) $defaults;
$this->_map = (array) $map;
$this->_reverse = $reverse;
$this->_map = (array) $map;
$this->_reverse = $reverse;
}
public function getVersion() {
@ -67,15 +67,27 @@ class Zend_Controller_Router_Route_Regex extends Zend_Controller_Router_Route_Ab
* 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
* @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)
public function match($path, $partial = false)
{
$path = trim(urldecode($path), '/');
$res = preg_match($this->_regex, $path, $values);
if ($res === 0) return false;
if (!$partial) {
$path = trim(urldecode($path), '/');
$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) {
@ -86,10 +98,9 @@ class Zend_Controller_Router_Route_Regex extends Zend_Controller_Router_Route_Ab
$this->_values = $values;
$values = $this->_getMappedValues($values);
$values = $this->_getMappedValues($values);
$defaults = $this->_getMappedValues($this->_defaults, false, true);
$return = $values + $defaults;
$return = $values + $defaults;
return $return;
}
@ -103,10 +114,10 @@ class Zend_Controller_Router_Route_Regex extends Zend_Controller_Router_Route_Ab
* 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
* @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)
{
@ -140,10 +151,10 @@ class Zend_Controller_Router_Route_Regex extends Zend_Controller_Router_Route_Ab
/**
* Assembles a URL path defined by this route
*
* @param array $data An array of name (or index) and value pairs used as parameters
* @param array $data An array of name (or index) and value pairs used as parameters
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = false)
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
{
if ($this->_reverse === null) {
require_once 'Zend/Controller/Router/Exception.php';
@ -208,6 +219,26 @@ class Zend_Controller_Router_Route_Regex extends Zend_Controller_Router_Route_Ab
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.

View File

@ -72,11 +72,19 @@ class Zend_Controller_Router_Route_Static extends Zend_Controller_Router_Route_A
* @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)
public function match($path, $partial = false)
{
if (trim($path, '/') == $this->_route) {
return $this->_defaults;
if ($partial) {
if (substr($path, 0, strlen($this->_route)) === $this->_route) {
$this->setMatchedPath($this->_route);
return $this->_defaults;
}
} else {
if (trim($path, '/') == $this->_route) {
return $this->_defaults;
}
}
return false;
}
@ -86,7 +94,7 @@ class Zend_Controller_Router_Route_Static extends Zend_Controller_Router_Route_A
* @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)
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
{
return $this->_route;
}