Skip to content

Commit f0ae586

Browse files
vlastaveselydg
authored andcommitted
Route::constructUrl() fixed global filter on presenter name (#161)
1 parent 95433f7 commit f0ae586

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/Application/Routers/Route.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
291291
if ($params === NULL) {
292292
return NULL;
293293
}
294+
$presenter = $params[self::PRESENTER_KEY];
294295
}
295296

296297
if (isset($metadata[self::MODULE_KEY])) { // try split into module and [submodule:]presenter parts

tests/Routers/Route.filter.global.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,32 @@ testRouteIn($route, '/abc?param=1', 'Abc.in', [
4242
testRouteIn($route, '/cde?param=1');
4343

4444
\Tester\Assert::null(testRouteOut($route, 'Cde'));
45+
46+
47+
$route = new Route('<lang>/<presenter>/<action>', [
48+
NULL => [
49+
Route::FILTER_IN => function (array $arr) {
50+
$arr['presenter'] = substr($arr['presenter'], 0, -2); // App:AbcCs -> App:Abc
51+
$arr['action'] = substr($arr['action'], 0, -2);
52+
return $arr;
53+
},
54+
Route::FILTER_OUT => function (array $arr) {
55+
$arr['presenter'] .= ucfirst($arr['lang']); // App:Abc -> App:AbcCs
56+
$arr['action'] .= ucfirst($arr['lang']);
57+
return $arr;
58+
},
59+
],
60+
'module' => 'App'
61+
]);
62+
63+
64+
testRouteIn($route, '/cs/abc-cs/def-cs', 'App:Abc', [
65+
'lang' => 'cs',
66+
'action' => 'def',
67+
'test' => 'testvalue',
68+
], '/cs/abc-cs/def-cs?test=testvalue');
69+
70+
Assert::same(
71+
'http://example.com/cs/abc-cs/def-cs?test=testvalue',
72+
testRouteOut($route, 'App:Abc', ['lang' => 'cs', 'action' => 'def', 'test' => 'testvalue'])
73+
);

0 commit comments

Comments
 (0)