Skip to content

Commit

Permalink
Remove magic around string urls.
Browse files Browse the repository at this point in the history
String urls no longer magically get the controller, plugin, or prefix
applied to them.  You only get the basedir applied.  This simplifies the
code and removes possibly un-expected magic from usage.

Start to carve out where named routes will fit.
  • Loading branch information
markstory committed Jul 4, 2012
1 parent 9eca07a commit f4483ed
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lib/Cake/Routing/Router.php
Expand Up @@ -636,6 +636,13 @@ public static function url($url = null, $options = false) {
}

$output = $frag = null;
$hasColonSlash = false;
$hasLeadingSlash = false;

if (is_string($url)) {
$hasColonSlash = strpos($url, '://') !== false;
$hasLeadingSlash = isset($url[0]) ? $url[0] === '/' : false;
}

if (empty($url)) {
$output = isset($here) ? $here : '/';
Expand Down Expand Up @@ -693,32 +700,21 @@ public static function url($url = null, $options = false) {
'plugin' => $params['plugin']
);
$output = self::$_routes->match($url, $params);
// } elseif (is_string($url) && $url[0] !== '/') {
} elseif (is_string($url) && !$hasLeadingSlash && !$hasColonSlash) {
// named route.

} else {
// String urls.
if (
(strpos($url, '://') !== false ||
($hasColonSlash ||
(strpos($url, 'javascript:') === 0) ||
(strpos($url, 'mailto:') === 0)) ||
(!strncmp($url, '#', 1))
) {
return $url;
}
if (substr($url, 0, 1) === '/') {
if ($hasLeadingSlash) {
$output = substr($url, 1);
} else {
foreach (static::$_prefixes as $prefix) {
if (isset($params[$prefix])) {
$output .= $prefix . '/';
break;
}
}
if (!empty($params['plugin']) && $params['plugin'] !== $params['controller']) {
$output .= Inflector::underscore($params['plugin']) . '/';
}
$output .= Inflector::underscore($params['controller']) . '/' . $url;
}
}
$protocol = preg_match('#^[a-z][a-z0-9+-.]*\://#i', $output);
Expand Down

0 comments on commit f4483ed

Please sign in to comment.