Skip to content

Commit

Permalink
Slightly more efficient getRequest()
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 4, 2012
1 parent dd754b1 commit 43fc68a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/Cake/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,7 @@ public static function popRequest() {
*/
public static function getRequest($current = false) {
if ($current) {
$i = count(static::$_requests) - 1;
return isset(static::$_requests[$i]) ? static::$_requests[$i] : null;
return end(static::$_requests);
}
return isset(static::$_requests[0]) ? static::$_requests[0] : null;
}
Expand Down Expand Up @@ -611,13 +610,16 @@ public static function url($url = null, $options = array()) {
$full = false;
if (is_bool($options)) {
$full = $options;
$options = array();
}
$urlType = gettype($url);
if (
is_string($url) &&
$urlType === 'string' &&
strpos($url, ':') !== false &&
strpos($url, '/') === false
) {
$url = self::_splitName($url, $options);
$urlType = 'array';
}

// TODO refactor so there is less overhead
Expand All @@ -636,10 +638,9 @@ public static function url($url = null, $options = array()) {
}

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

if (is_string($url)) {
if ($urlType === 'string') {
$hasColonSlash = strpos($url, '://') !== false;
$hasLeadingSlash = isset($url[0]) ? $url[0] === '/' : false;
}
Expand All @@ -650,7 +651,7 @@ public static function url($url = null, $options = array()) {
$output = FULL_BASE_URL . $output;
}
return $output;
} elseif (is_array($url)) {
} elseif ($urlType === 'array') {
if (isset($url['_full']) && $url['_full'] === true) {
$full = true;
unset($url['_full']);
Expand Down Expand Up @@ -701,7 +702,7 @@ public static function url($url = null, $options = array()) {
);
$output = self::$_routes->match($url, $params);
} elseif (
is_string($url) &&
$urlType === 'string' &&
!$hasLeadingSlash &&
!$hasColonSlash
) {
Expand Down

0 comments on commit 43fc68a

Please sign in to comment.