Skip to content

Commit

Permalink
Remove sprintf() calls.
Browse files Browse the repository at this point in the history
The extra loop and function calls aren't necessary.
  • Loading branch information
markstory committed Jul 6, 2014
1 parent 839282c commit 407388a
Showing 1 changed file with 15 additions and 41 deletions.
56 changes: 15 additions & 41 deletions src/Routing/RouteCollection.php
Expand Up @@ -128,38 +128,34 @@ public function parse($url) {
* @return string The name of the url
*/
protected function _getNames($url) {
$name = false;
if (isset($url['_name'])) {
return [$url['_name']];
}
$plugin = false;
if (isset($url['plugin'])) {
$plugin = $url['plugin'];
}
$controller = $url['controller'];
$action = $url['action'];

$fallbacks = [
'%2$s:%3$s',
'%2$s:_action',
'_controller:%3$s',
'_controller:_action'
"${controller}:${action}",
"${controller}:_action",
"_controller:${action}",
"_controller:_action"
];
if ($plugin) {
$fallbacks = [
'%1$s.%2$s:%3$s',
'%1$s.%2$s:_action',
'%1$s._controller:%3$s',
'%1$s._controller:_action',
'_plugin.%2$s:%3$s',
'_plugin._controller:%3$s',
'_plugin._controller:_action',
'_controller:_action'
"${plugin}.${controller}:${action}",
"${plugin}.${controller}:_action",
"${plugin}._controller:${action}",
"${plugin}._controller:_action",
"_plugin.${controller}:${action}",
"_plugin._controller:${action}",
"_plugin._controller:_action",
"_controller:_action"
];
}
foreach ($fallbacks as $i => $template) {
$fallbacks[$i] = strtolower(sprintf($template, $plugin, $url['controller'], $url['action']));
}
if ($name) {
array_unshift($fallbacks, $name);
}
return $fallbacks;
}

Expand All @@ -185,28 +181,6 @@ public function match($url, $context) {
}
}

/*
// Check the scope that matches key params.
$plugin = isset($url['plugin']) ? $url['plugin'] : '';
$prefix = isset($url['prefix']) ? $url['prefix'] : '';
$collection = null;
$attempts = [[$plugin, $prefix], ['', '']];
foreach ($attempts as $attempt) {
if (isset($this->_byParams[$attempt[0]][$attempt[1]])) {
$collection = $this->_byParams[$attempt[0]][$attempt[1]];
break;
}
}
if ($collection) {
$match = $collection->match($url, static::$_requestContext);
if ($match !== false) {
return $match;
}
}
*/

foreach ($this->_getNames($url) as $name) {
if (empty($this->_routeTable[$name])) {
continue;
Expand Down

0 comments on commit 407388a

Please sign in to comment.