From 7205f5ec9c6256f4f52fc1d3d87dc6ccaa105af1 Mon Sep 17 00:00:00 2001 From: Mike Gibson Date: Mon, 10 Mar 2014 15:01:52 +0000 Subject: [PATCH] Made it slightly neater --- lib/Cake/Routing/Route/CakeRoute.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index 1f7cdaaf0..2284c71aa 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -517,28 +517,28 @@ class CakeRoute { } $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);