Skip to content

Commit 583a4f3

Browse files
committed
RoutingPanel: fixed displaying withPath() + compatibility with routing 3.0.5
1 parent e059c8d commit 583a4f3

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"php": ">=7.2",
1919
"nette/component-model": "^3.0",
2020
"nette/http": "^3.0.2",
21-
"nette/routing": "^3.0.2",
21+
"nette/routing": "^3.0.5",
2222
"nette/utils": "^3.2.1 || ~4.0.0"
2323
},
2424
"suggest": {

src/Bridges/ApplicationTracy/RoutingPanel.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private function analyse(
8989
Routing\Router $router,
9090
?Nette\Http\IRequest $httpRequest,
9191
string $module = '',
92-
?string $path = null,
92+
string $path = '',
9393
int $level = -1,
9494
int $flag = 0
9595
): void
@@ -105,10 +105,13 @@ private function analyse(
105105

106106
$prop = (new \ReflectionProperty(Routing\RouteList::class, 'path'));
107107
$prop->setAccessible(true);
108-
if ($httpRequest && ($pathPrefix = $prop->getValue($router))) {
109-
$path .= $pathPrefix;
108+
$path .= $pathPrefix = $prop->getValue($router);
109+
if ($httpRequest && $pathPrefix) {
110110
$url = $httpRequest->getUrl();
111-
$httpRequest = $httpRequest->withUrl($url->withPath($url->getPath(), $url->getBasePath() . $pathPrefix));
111+
$url = $url->getRelativePath() . '/' === $pathPrefix
112+
? $url->withPath($url->getPath() . '/')
113+
: $url->withPath($url->getPath(), $url->getBasePath() . $pathPrefix);
114+
$httpRequest = $httpRequest->withUrl($url);
112115
}
113116

114117
$module .= ($router instanceof Nette\Application\Routers\RouteList ? $router->getModule() : '');

src/Bridges/ApplicationTracy/templates/RoutingPanel.panel.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use Tracy\Helpers;
9494
><?= ['yes' => '', 'may' => '', 'no' => '', 'oneway' => '', 'error' => ''][$router->matched] ?></td>
9595

9696
<td><code title="<?= Helpers::escapeHtml($router->class) ?>"><?=
97-
isset($router->path) ? '<small>' . Helpers::escapeHtml($router->path) . '</small>' : '',
97+
$router->path === '' ? '' : '<small>' . Helpers::escapeHtml($router->path) . '</small>',
9898
isset($router->mask) ? str_replace(['/', '-'], ['<wbr>/', '<wbr>-'], Helpers::escapeHtml($router->mask)) : str_replace('\\', '<wbr>\\', Helpers::escapeHtml($router->class))
9999
?></code></td>
100100

tests/Bridges.Tracy/RoutingPanel.analyse.withPath.phpt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test('URL: /', function () use ($router) {
4040
'mask' => 'sign-in',
4141
'params' => null,
4242
'module' => '',
43-
'path' => null,
43+
'path' => '',
4444
'error' => null,
4545
'gutterTop' => 0,
4646
],
@@ -52,7 +52,7 @@ test('URL: /', function () use ($router) {
5252
'mask' => '',
5353
'params' => null,
5454
'module' => '',
55-
'path' => null,
55+
'path' => 'admin/',
5656
'error' => null,
5757
'gutterTop' => 1,
5858
],
@@ -64,7 +64,7 @@ test('URL: /', function () use ($router) {
6464
'mask' => '<presenter>/<action=default>',
6565
'params' => null,
6666
'module' => '',
67-
'path' => null,
67+
'path' => 'admin/',
6868
'error' => null,
6969
'gutterBottom' => 1,
7070
],
@@ -76,7 +76,7 @@ test('URL: /', function () use ($router) {
7676
'mask' => '',
7777
'params' => ['presenter' => 'Article', 'action' => 'homepage'],
7878
'module' => '',
79-
'path' => null,
79+
'path' => '',
8080
'error' => null,
8181
],
8282
(object) [
@@ -87,7 +87,7 @@ test('URL: /', function () use ($router) {
8787
'mask' => '<presenter>/<action=default>',
8888
'params' => null,
8989
'module' => '',
90-
'path' => null,
90+
'path' => '',
9191
'error' => null,
9292
'gutterBottom' => 0,
9393
],
@@ -114,7 +114,7 @@ test('URL: /foo', function () use ($router) {
114114
'mask' => 'sign-in',
115115
'params' => null,
116116
'module' => '',
117-
'path' => null,
117+
'path' => '',
118118
'error' => null,
119119
'gutterTop' => 0,
120120
],
@@ -126,7 +126,7 @@ test('URL: /foo', function () use ($router) {
126126
'mask' => '',
127127
'params' => null,
128128
'module' => '',
129-
'path' => null,
129+
'path' => 'admin/',
130130
'error' => null,
131131
'gutterTop' => 1,
132132
],
@@ -138,7 +138,7 @@ test('URL: /foo', function () use ($router) {
138138
'mask' => '<presenter>/<action=default>',
139139
'params' => null,
140140
'module' => '',
141-
'path' => null,
141+
'path' => 'admin/',
142142
'error' => null,
143143
'gutterBottom' => 1,
144144
],
@@ -150,7 +150,7 @@ test('URL: /foo', function () use ($router) {
150150
'mask' => '',
151151
'params' => null,
152152
'module' => '',
153-
'path' => null,
153+
'path' => '',
154154
'error' => null,
155155
],
156156
(object) [
@@ -161,7 +161,7 @@ test('URL: /foo', function () use ($router) {
161161
'mask' => '<presenter>/<action=default>',
162162
'params' => ['presenter' => 'Foo', 'action' => 'default'],
163163
'module' => '',
164-
'path' => null,
164+
'path' => '',
165165
'error' => null,
166166
'gutterBottom' => 0,
167167
],
@@ -188,19 +188,19 @@ test('URL: /admin', function () use ($router) {
188188
'mask' => 'sign-in',
189189
'params' => null,
190190
'module' => '',
191-
'path' => null,
191+
'path' => '',
192192
'error' => null,
193193
'gutterTop' => 0,
194194
],
195195
(object) [
196196
'level' => 1,
197-
'matched' => 'no',
197+
'matched' => 'yes',
198198
'class' => 'Nette\Application\Routers\Route',
199199
'defaults' => ['presenter' => 'Admin:Home', 'action' => 'default'],
200200
'mask' => '',
201-
'params' => null,
201+
'params' => ['presenter' => 'Admin:Home', 'action' => 'default'],
202202
'module' => '',
203-
'path' => null,
203+
'path' => 'admin/',
204204
'error' => null,
205205
'gutterTop' => 1,
206206
],
@@ -212,7 +212,7 @@ test('URL: /admin', function () use ($router) {
212212
'mask' => '<presenter>/<action=default>',
213213
'params' => null,
214214
'module' => '',
215-
'path' => null,
215+
'path' => 'admin/',
216216
'error' => null,
217217
'gutterBottom' => 1,
218218
],
@@ -224,18 +224,18 @@ test('URL: /admin', function () use ($router) {
224224
'mask' => '',
225225
'params' => null,
226226
'module' => '',
227-
'path' => null,
227+
'path' => '',
228228
'error' => null,
229229
],
230230
(object) [
231231
'level' => 0,
232-
'matched' => 'yes',
232+
'matched' => 'may',
233233
'class' => 'Nette\Application\Routers\Route',
234234
'defaults' => ['action' => 'default'],
235235
'mask' => '<presenter>/<action=default>',
236236
'params' => ['presenter' => 'Admin', 'action' => 'default'],
237237
'module' => '',
238-
'path' => null,
238+
'path' => '',
239239
'error' => null,
240240
'gutterBottom' => 0,
241241
],
@@ -262,7 +262,7 @@ test('URL: /admin/', function () use ($router) {
262262
'mask' => 'sign-in',
263263
'params' => null,
264264
'module' => '',
265-
'path' => null,
265+
'path' => '',
266266
'error' => null,
267267
'gutterTop' => 0,
268268
],
@@ -298,7 +298,7 @@ test('URL: /admin/', function () use ($router) {
298298
'mask' => '',
299299
'params' => null,
300300
'module' => '',
301-
'path' => null,
301+
'path' => '',
302302
'error' => null,
303303
],
304304
(object) [
@@ -309,7 +309,7 @@ test('URL: /admin/', function () use ($router) {
309309
'mask' => '<presenter>/<action=default>',
310310
'params' => ['presenter' => 'Admin', 'action' => 'default'],
311311
'module' => '',
312-
'path' => null,
312+
'path' => '',
313313
'error' => null,
314314
'gutterBottom' => 0,
315315
],
@@ -336,7 +336,7 @@ test('URL: /admin/foo', function () use ($router) {
336336
'mask' => 'sign-in',
337337
'params' => null,
338338
'module' => '',
339-
'path' => null,
339+
'path' => '',
340340
'error' => null,
341341
'gutterTop' => 0,
342342
],
@@ -372,7 +372,7 @@ test('URL: /admin/foo', function () use ($router) {
372372
'mask' => '',
373373
'params' => null,
374374
'module' => '',
375-
'path' => null,
375+
'path' => '',
376376
'error' => null,
377377
],
378378
(object) [
@@ -383,7 +383,7 @@ test('URL: /admin/foo', function () use ($router) {
383383
'mask' => '<presenter>/<action=default>',
384384
'params' => ['presenter' => 'Admin', 'action' => 'foo'],
385385
'module' => '',
386-
'path' => null,
386+
'path' => '',
387387
'error' => null,
388388
'gutterBottom' => 0,
389389
],

0 commit comments

Comments
 (0)