Made it slightly neater

This commit is contained in:
Mike Gibson 2014-03-10 15:01:52 +00:00
parent d40452b43d
commit 7205f5ec9c

View file

@ -517,28 +517,28 @@ class CakeRoute {
} }
$out = $this->template; $out = $this->template;
$search = $replace = array(); if(!empty($this->keys)) {
$search = $replace = array();
if(empty($this->keys)) {
$keys = array();
} else {
$lengths = array_map('strlen', $this->keys); $lengths = array_map('strlen', $this->keys);
$flipped = array_combine($this->keys, $lengths); $flipped = array_combine($this->keys, $lengths);
arsort($flipped); arsort($flipped);
$keys = array_keys($flipped); $keys = array_keys($flipped);
}
foreach ($keys as $key) { foreach ($keys as $key) {
$string = null; $string = null;
if (isset($params[$key])) { if (isset($params[$key])) {
$string = $params[$key]; $string = $params[$key];
} elseif (strpos($out, $key) != strlen($out) - strlen($key)) { } elseif (strpos($out, $key) != strlen($out) - strlen($key)) {
$key .= '/'; $key .= '/';
}
$search[] = ':' . $key;
$replace[] = $string;
} }
$search[] = ':' . $key; $out = str_replace($search, $replace, $out);
$replace[] = $string;
} }
$out = str_replace($search, $replace, $out);
if (strpos($this->template, '*')) { if (strpos($this->template, '*')) {
$out = str_replace('*', $params['pass'], $out); $out = str_replace('*', $params['pass'], $out);