mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Expanding tests for passed arguments in route defaults working correctly. Refactoring passed arguments in route default handling.
This commit is contained in:
parent
889e367510
commit
f59b8daf2e
2 changed files with 22 additions and 27 deletions
|
@ -670,7 +670,7 @@ class Router {
|
||||||
* Returns an URL pointing to a combination of controller and action. Param
|
* Returns an URL pointing to a combination of controller and action. Param
|
||||||
* $url can be:
|
* $url can be:
|
||||||
*
|
*
|
||||||
* - Empty - the method will find adress to actuall controller/action.
|
* - Empty - the method will find address to actuall controller/action.
|
||||||
* - '/' - the method will find base URL of application.
|
* - '/' - the method will find base URL of application.
|
||||||
* - A combination of controller/action - the method will find url for it.
|
* - A combination of controller/action - the method will find url for it.
|
||||||
*
|
*
|
||||||
|
@ -693,7 +693,7 @@ class Router {
|
||||||
if (is_bool($full)) {
|
if (is_bool($full)) {
|
||||||
$escape = false;
|
$escape = false;
|
||||||
} else {
|
} else {
|
||||||
extract(array_merge(array('escape' => false, 'full' => false), $full));
|
extract($full + array('escape' => false, 'full' => false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($self->__params)) {
|
if (!empty($self->__params)) {
|
||||||
|
@ -751,17 +751,15 @@ class Router {
|
||||||
unset($url[$prefix]);
|
unset($url[$prefix]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$plugin = false;
|
|
||||||
if (array_key_exists('plugin', $url)) {
|
if (array_key_exists('plugin', $url)) {
|
||||||
$plugin = $url['plugin'];
|
$params['plugin'] = $url['plugin'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$_url = $url;
|
$_url = $url;
|
||||||
$url = array_merge(array('controller' => $params['controller'], 'plugin' => $params['plugin']), Set::filter($url, true));
|
$url = array_merge(
|
||||||
|
array('controller' => $params['controller'], 'plugin' => $params['plugin']),
|
||||||
if ($plugin !== false) {
|
Set::filter($url, true)
|
||||||
$url['plugin'] = $plugin;
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($url['ext'])) {
|
if (isset($url['ext'])) {
|
||||||
$extension = '.' . $url['ext'];
|
$extension = '.' . $url['ext'];
|
||||||
|
@ -771,8 +769,6 @@ class Router {
|
||||||
|
|
||||||
for ($i = 0, $len = count($self->routes); $i < $len; $i++) {
|
for ($i = 0, $len = count($self->routes); $i < $len; $i++) {
|
||||||
$route =& $self->routes[$i];
|
$route =& $self->routes[$i];
|
||||||
$route->compile();
|
|
||||||
|
|
||||||
$originalUrl = $url;
|
$originalUrl = $url;
|
||||||
|
|
||||||
if (isset($route->params['persist'], $self->__params[0])) {
|
if (isset($route->params['persist'], $self->__params[0])) {
|
||||||
|
@ -944,8 +940,7 @@ class Router {
|
||||||
if (!$actionMatches) {
|
if (!$actionMatches) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$valueMatches = !isset($rule['match']) || preg_match(sprintf('/%s/', $rule['match']), $val);
|
return (!isset($rule['match']) || preg_match('/' . $rule['match'] . '/', $val));
|
||||||
return $valueMatches;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1097,10 +1092,7 @@ class Router {
|
||||||
$pass = $named = array();
|
$pass = $named = array();
|
||||||
$args = explode('/', $args);
|
$args = explode('/', $args);
|
||||||
|
|
||||||
$greedy = $self->named['greedy'];
|
$greedy = isset($options['greedy']) ? $options['greedy'] : $self->named['greedy'];
|
||||||
if (isset($options['greedy'])) {
|
|
||||||
$greedy = $options['greedy'];
|
|
||||||
}
|
|
||||||
$context = array();
|
$context = array();
|
||||||
if (isset($options['context'])) {
|
if (isset($options['context'])) {
|
||||||
$context = $options['context'];
|
$context = $options['context'];
|
||||||
|
@ -1363,20 +1355,18 @@ class RouterRoute {
|
||||||
|
|
||||||
$pass = array();
|
$pass = array();
|
||||||
$params = Set::diff($url, $defaults);
|
$params = Set::diff($url, $defaults);
|
||||||
$urlInv = array_combine(array_values($url), array_keys($url));
|
|
||||||
|
|
||||||
|
if (isset($defaults[0])) {
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while (isset($defaults[$i])) {
|
while (isset($defaults[$i])) {
|
||||||
if (isset($urlInv[$defaults[$i]])) {
|
if (isset($url[$i]) && $defaults[$i] == $url[$i]) {
|
||||||
if (!in_array($defaults[$i], $url) && is_int($urlInv[$defaults[$i]])) {
|
unset($defaults[$i]);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
unset($urlInv[$defaults[$i]], $defaults[$i]);
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($params as $key => $value) {
|
foreach ($params as $key => $value) {
|
||||||
if (is_int($key)) {
|
if (is_int($key)) {
|
||||||
|
|
|
@ -1764,6 +1764,7 @@ class RouterTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testPassedArgsOrder() {
|
function testPassedArgsOrder() {
|
||||||
|
Router::connect('/test-passed/*', array('controller' => 'pages', 'action' => 'display', 'home'));
|
||||||
Router::connect('/test2/*', array('controller' => 'pages', 'action' => 'display', 2));
|
Router::connect('/test2/*', array('controller' => 'pages', 'action' => 'display', 2));
|
||||||
Router::connect('/test/*', array('controller' => 'pages', 'action' => 'display', 1));
|
Router::connect('/test/*', array('controller' => 'pages', 'action' => 'display', 1));
|
||||||
Router::parse('/');
|
Router::parse('/');
|
||||||
|
@ -1776,6 +1777,10 @@ class RouterTest extends CakeTestCase {
|
||||||
$expected = '/test2/whatever';
|
$expected = '/test2/whatever';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$result = Router::url(array('controller' => 'pages', 'action' => 'display', 'home', 'whatever'));
|
||||||
|
$expected = '/test-passed/whatever';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
Configure::write('Routing.prefixes', array('admin'));
|
Configure::write('Routing.prefixes', array('admin'));
|
||||||
Router::reload();
|
Router::reload();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue