Skip to content

Commit

Permalink
Removing parameters from RouterRoute::_writeRoute().
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 2, 2009
1 parent 494875c commit 61b70f1
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions cake/libs/router.php
Expand Up @@ -1219,42 +1219,40 @@ function compile() {
if ($this->compiled()) {
return $this->_compiledRoute;
}
$this->_writeRoute($this->template, $this->defaults, $this->options);
$this->_writeRoute();
return $this->_compiledRoute;
}
/**
* Builds a route regular expression
* Builds a route regular expression. Uses the template, defaults and options
* properties to compile a regular expression that can be used to match/parse request strings.
*
* @param string $route An empty string, or a route string "/"
* @param array $default NULL or an array describing the default route
* @param array $params An array matching the named elements in the route to regular expressions
* which that element should match.
* @return void
* @access protected
*/
function _writeRoute($route, $default, $params) {
if (empty($route) || ($route === '/')) {
function _writeRoute() {
if (empty($this->template) || ($this->template === '/')) {
$this->_compiledRoute = '#^/*$#';
$this->keys = array();
return;
}
$route = $this->template;
$names = $replacements = $search = array();
$parsed = preg_quote($route, '#');
$parsed = preg_quote($this->template, '#');

preg_match_all('#:([A-Za-z0-9_-]+[A-Z0-9a-z])#', $route, $namedElements);
foreach ($namedElements[1] as $i => $name) {
if (isset($params[$name])) {
if (isset($this->options[$name])) {
$option = null;
if ($name !== 'plugin' && array_key_exists($name, $default)) {
if ($name !== 'plugin' && array_key_exists($name, $this->defaults)) {
$option = '?';
}
$slashParam = '/\\' . $namedElements[0][$i];
if (strpos($parsed, $slashParam) !== false) {
$replacements[] = '(?:/(?P<' . $name . '>' . $params[$name] . ')' . $option . ')' . $option;
$replacements[] = '(?:/(?P<' . $name . '>' . $this->options[$name] . ')' . $option . ')' . $option;
$search[] = $slashParam;
} else {
$search[] = '\\' . $namedElements[0][$i];
$replacements[] = '(?:(?P<' . $name . '>' . $params[$name] . ')' . $option . ')' . $option;
$replacements[] = '(?:(?P<' . $name . '>' . $this->options[$name] . ')' . $option . ')' . $option;
}
} else {
$replacements[] = '(?:(?P<' . $name . '>[^/]+))?';
Expand Down

0 comments on commit 61b70f1

Please sign in to comment.