* /united-states/california/los-angeles/convention-centers/places.html * * This router should be used as the most generic routing pattern as it will * match almost any passed request path. It will not match a request path if the * path does not end with the expected extension (default .html) or a Uri delimiter * (but not a trailing slash followed immediately byb a Uri delimiter). * If the path is empty or ended with a trailing slash, "index" will be passed as the * page name. It is up to the receiving controller to determine if the path and page * are valid (or not and should 404) according to the individual implementation. * * Portions of this code based on the other Zend_Controller_Router_Route_* classes. * * @package Zend_Controller * @subpackage Router * @copyright Copyright (c) 2007 Kevin Vaughan (http://www.kevinvaughan.com/) * @license http://www.zend.com/license/framework/1_0.txt Zend Framework License version 1.0 */ class Zend_Controller_Router_Route_ContentPath implements Zend_Controller_Router_Route_Interface { const URI_DELIMITER = '/'; protected $_contentExtension = '.html'; protected $_regex = null; protected $_defaults = array(); protected $_reverse = null; protected $_values = array(); /** * Instantiates route based on passed Zend_Config structure */ public static function getInstance(Zend_Config $config) { $defs = ($config->defaults instanceof Zend_Config) ? $config->defaults->toArray() : array(); $ext = (isset($config->extension)) ? $config->extension : ".html"; return new self($defs, $ext); } public function __construct($defaults = array(), $extension = ".html") { $this->_defaults = (array) $defaults; $this->_contentExtension = $extension; } /** * Matches a user submitted path with a previously defined route. * Assigns and returns an array of path information on a successful match. * Format for return is { "path" => {..., ...}, "page" => "..." } * Uri delimiters are removed and content extension is removed from page * * @param string Path used to match against this routing map * @return array|false An array of path values or false if the path doesn't match */ public function match($path) { $path = urldecode($path); if ((substr($path, -1*strlen($this->_contentExtension)) != $this->_contentExtension) && (substr($path, -1) != self::URI_DELIMITER)) { return false; } else { if (substr($path, -1*strlen(self::URI_DELIMITER.$this->_contentExtension)) == (self::URI_DELIMITER.$this->_contentExtension)) { return false; } } if (substr($path, -1) == self::URI_DELIMITER) { $path .= "index"; } else { $path = rtrim($path, $this->_contentExtension); } $values = split(self::URI_DELIMITER, trim($path, self::URI_DELIMITER)); $return = array(); $return["page"] = array_pop($values); $return["path"] = $values; return $return + $this->_defaults; } /** * Assembles a URL path defined by this route * * @param array 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()) { if ((!isset($data["page"]) || !is_string($data["page"])) && (!isset($data["path"]) || !is_array($data["path"]))) { require_once 'Zend/Controller/Router/Exception.php'; throw new Zend_Controller_Router_Exception('Cannot assemble. Too few arguments.'); } $return = "/"; foreach ($data["path"] as $directory) { $return .= $directory . "/"; } $return .= $data["page"] . $this->_contentExtension; return $return; } /** * Return a single parameter of route's defaults * * @param 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; } }