Skip to content

Commit

Permalink
Starting to refactor RouterRoute::_writeRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 26, 2009
1 parent 0b9ae92 commit 6661c2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion cake/libs/router.php
Expand Up @@ -1276,7 +1276,26 @@ function _writeRoute($route, $default, $params) {
$this->keys = array();
return;
}
$names = $parsed = array();
$names = $replacements = array();
$parsed = $route;

preg_match_all('#:([A-Za-z0-9_-]+[A-Z0-9a-z])#', $route, $namedElements);
foreach ($namedElements[1] as $i => $name) {
$option = null;
if (isset($params[$name])) {
if ($name !== 'plugin' && array_key_exists($name, $default)) {
$option = '?';
}
$replacements[] = '(?:/(' . $params[$name] . ')' . $option . ')' . $option;
} else {
$replacements[] = '(?:/(^[\/]+))?';
}
$names[] = $name;
}
$route = str_replace($namedElements[0], $replacements, $route);
$this->_compiledRoute = '#^' . $route . '[\/]*$#';
$this->keys = $names;
/*
$elements = explode('/', $route);
foreach ($elements as $element) {
Expand Down Expand Up @@ -1333,6 +1352,7 @@ function _writeRoute($route, $default, $params) {
}
$this->_compiledRoute = '#^' . join('', $parsed) . '[\/]*$#';
$this->keys = $names;
*/
}

/**
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/libs/router.test.php
Expand Up @@ -1980,7 +1980,7 @@ function testRouterConnectDefaults() {

}
}

SimpleTest::ignore('RouterTest');
/**
* Test case for RouterRoute
*
Expand Down

0 comments on commit 6661c2f

Please sign in to comment.