mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Starting to try and re-factor named params to perform better and be more
explicit with how they are used.
This commit is contained in:
parent
de7b324444
commit
c5bab54125
3 changed files with 14 additions and 5 deletions
|
@ -263,6 +263,15 @@ class CakeRoute {
|
|||
if (array_intersect_key($keyNames, $url) != $keyNames) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//pull out named params so comparisons later on are faster.
|
||||
$named = array();
|
||||
foreach ($url as $key => $value) {
|
||||
if ($key[0] === ':') {
|
||||
$named[$key] = $value;
|
||||
unset($url[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$diffUnfiltered = Set::diff($url, $defaults);
|
||||
$diff = array();
|
||||
|
@ -289,7 +298,7 @@ class CakeRoute {
|
|||
return false;
|
||||
}
|
||||
|
||||
$passedArgsAndParams = array_diff_key($diff, $filteredDefaults, $keyNames);
|
||||
$passedArgsAndParams = array_diff_key($diff, $filteredDefaults, $keyNames) + $named;
|
||||
list($named, $params) = Router::getNamedElements($passedArgsAndParams, $url['controller'], $url['action']);
|
||||
|
||||
//remove any pass params, they have numeric indexes, skip any params that are in the defaults
|
||||
|
|
|
@ -89,7 +89,7 @@ class Router {
|
|||
* @access public
|
||||
*/
|
||||
public static $named = array(
|
||||
'default' => array('page', 'fields', 'order', 'limit', 'recursive', 'sort', 'direction', 'step'),
|
||||
'default' => array(':page', ':fields', ':order', ':limit', ':recursive', ':sort', ':direction', ':step'),
|
||||
'greedy' => true,
|
||||
'separator' => ':',
|
||||
'rules' => false,
|
||||
|
@ -972,7 +972,7 @@ class Router {
|
|||
if (isset(self::$named['rules'][$param])) {
|
||||
$rule = self::$named['rules'][$param];
|
||||
if (Router::matchNamed($param, $val, $rule, compact('controller', 'action'))) {
|
||||
$named[$param] = $val;
|
||||
$named[substr($param, 1)] = $val;
|
||||
unset($params[$param]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -298,13 +298,13 @@ class CakeRouteTestCase extends CakeTestCase {
|
|||
Router::connectNamed(true);
|
||||
|
||||
$route = new CakeRoute('/:controller/:action/*', array('plugin' => null));
|
||||
$result = $route->match(array('controller' => 'posts', 'action' => 'index', 'plugin' => null, 'page' => 1));
|
||||
$result = $route->match(array('controller' => 'posts', 'action' => 'index', 'plugin' => null, ':page' => 1));
|
||||
$this->assertEqual($result, '/posts/index/page:1');
|
||||
|
||||
$result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5));
|
||||
$this->assertEqual($result, '/posts/view/5');
|
||||
|
||||
$result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5, 'page' => 1, 'limit' => 20, 'order' => 'title'));
|
||||
$result = $route->match(array('controller' => 'posts', 'action' => 'view', 'plugin' => null, 5, ':page' => 1, ':limit' => 20, ':order' => 'title'));
|
||||
$this->assertEqual($result, '/posts/view/5/page:1/limit:20/order:title');
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue