Skip to content
Permalink
Browse files

Remove sprintf() calls.

The extra loop and function calls aren't necessary.
  • Loading branch information...
markstory committed Jul 5, 2014
1 parent 839282c commit 407388a43cda07e0c5424d098883bbe83ad3075d
Showing with 15 additions and 41 deletions.
  1. +15 −41 src/Routing/RouteCollection.php
@@ -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;
}
@@ -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;

0 comments on commit 407388a

Please sign in to comment.
You can’t perform that action at this time.