Skip to content

Commit bdf16da

Browse files
vlastaveselydg
authored andcommitted
Route::constructUrl(): split of module and presenter moved before global filter (#167)
1 parent d5cfe63 commit bdf16da

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/Application/Routers/Route.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,6 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
286286
$presenter = $appRequest->getPresenterName();
287287
$params[self::PRESENTER_KEY] = $presenter;
288288

289-
if (isset($metadata[NULL][self::FILTER_OUT])) {
290-
$params = call_user_func($metadata[NULL][self::FILTER_OUT], $params);
291-
if ($params === NULL) {
292-
return NULL;
293-
}
294-
$presenter = $params[self::PRESENTER_KEY];
295-
}
296-
297289
if (isset($metadata[self::MODULE_KEY])) { // try split into module and [submodule:]presenter parts
298290
$module = $metadata[self::MODULE_KEY];
299291
if (isset($module['fixity']) && strncmp($presenter, $module[self::VALUE] . ':', strlen($module[self::VALUE]) + 1) === 0) {
@@ -309,6 +301,13 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
309301
}
310302
}
311303

304+
if (isset($metadata[NULL][self::FILTER_OUT])) {
305+
$params = call_user_func($metadata[NULL][self::FILTER_OUT], $params);
306+
if ($params === NULL) {
307+
return NULL;
308+
}
309+
}
310+
312311
foreach ($metadata as $name => $meta) {
313312
if (!isset($params[$name])) {
314313
continue; // retains NULL values

tests/Routers/Route.filter.global.phpt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,30 @@ testRouteIn($route, '/abc?param=1', 'Abc.in', [
4141

4242
testRouteIn($route, '/cde?param=1');
4343

44-
\Tester\Assert::null(testRouteOut($route, 'Cde'));
44+
Assert::null(testRouteOut($route, 'Cde'));
4545

4646

4747
$route = new Route('<lang>/<presenter>/<action>', [
4848
NULL => [
4949
Route::FILTER_IN => function (array $arr) {
50-
$arr['presenter'] = substr($arr['presenter'], 0, -2); // App:AbcCs -> App:Abc
50+
if ($arr['module'] !== 'App') {
51+
return NULL;
52+
}
53+
if ($arr['presenter'] !== 'AbcCs') {
54+
return NULL;
55+
}
56+
$arr['presenter'] = substr($arr['presenter'], 0, -2); // AbcCs -> Abc
5157
$arr['action'] = substr($arr['action'], 0, -2);
5258
return $arr;
5359
},
5460
Route::FILTER_OUT => function (array $arr) {
55-
$arr['presenter'] .= ucfirst($arr['lang']); // App:Abc -> App:AbcCs
61+
if ($arr['module'] !== 'App') {
62+
return NULL;
63+
}
64+
if ($arr['presenter'] !== 'Abc') {
65+
return NULL;
66+
}
67+
$arr['presenter'] .= ucfirst($arr['lang']); // Abc -> AbcCs
5668
$arr['action'] .= ucfirst($arr['lang']);
5769
return $arr;
5870
},

0 commit comments

Comments
 (0)