Skip to content

Commit

Permalink
Made it slightly neater
Browse files Browse the repository at this point in the history
  • Loading branch information
mgdigital committed Mar 10, 2014
1 parent d40452b commit 7205f5e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/Cake/Routing/Route/CakeRoute.php
Expand Up @@ -517,28 +517,28 @@ protected function _writeUrl($params) {
}
$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);
$flipped = array_combine($this->keys, $lengths);
arsort($flipped);
$keys = array_keys($flipped);
}

foreach ($keys as $key) {
$string = null;
if (isset($params[$key])) {
$string = $params[$key];
} elseif (strpos($out, $key) != strlen($out) - strlen($key)) {
$key .= '/';
foreach ($keys as $key) {
$string = null;
if (isset($params[$key])) {
$string = $params[$key];
} elseif (strpos($out, $key) != strlen($out) - strlen($key)) {
$key .= '/';
}
$search[] = ':' . $key;
$replace[] = $string;
}
$search[] = ':' . $key;
$replace[] = $string;
$out = str_replace($search, $replace, $out);

}
$out = str_replace($search, $replace, $out);

if (strpos($this->template, '*')) {
$out = str_replace('*', $params['pass'], $out);
Expand Down

0 comments on commit 7205f5e

Please sign in to comment.