Skip to content

Commit 209e227

Browse files
Jan Galekdg
authored andcommitted
Route: Added variable for domain second level name (%sld%)
1 parent a4862c7 commit 209e227

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Application/Routers/Route.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public function match(Nette\Http\IRequest $httpRequest)
155155
'/%basePath%/' => preg_quote($url->getBasePath(), '#'),
156156
'%tld%' => preg_quote($host[0], '#'),
157157
'%domain%' => preg_quote(isset($host[1]) ? "$host[1].$host[0]" : $host[0], '#'),
158+
'%sld%' => preg_quote(isset($host[1]) ? $host[1] : '', '#'),
158159
]);
159160

160161
} elseif ($this->type === self::RELATIVE) {
@@ -396,6 +397,7 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
396397
'/%basePath%/' => $refUrl->getBasePath(),
397398
'%tld%' => $host[0],
398399
'%domain%' => isset($host[1]) ? "$host[1].$host[0]" : $host[0],
400+
'%sld%' => isset($host[1]) ? $host[1] : '',
399401
]);
400402
$url = ($this->flags & self::SECURED ? 'https:' : 'http:') . $url;
401403
}

tests/Routers/Route.variables.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ testRouteIn(new Route('//%domain%/<path>', 'Default:default'), '/abc', 'Default'
4141
], '/abc?test=testvalue');
4242

4343

44+
testRouteIn(new Route('//%sld%.com/<path>', 'Default:default'), '/abc', 'Default', [
45+
'path' => 'abc',
46+
'action' => 'default',
47+
'test' => 'testvalue',
48+
], '/abc?test=testvalue');
49+
50+
51+
testRouteIn(new Route('//%sld%.%tld%/<path>', 'Default:default'), '/abc', 'Default', [
52+
'path' => 'abc',
53+
'action' => 'default',
54+
'test' => 'testvalue',
55+
], '/abc?test=testvalue');
56+
57+
4458
// alternative
4559
testRouteIn(new Route('//example.%tld%/<path>', 'Default:default'), '/abc', 'Default', [
4660
'path' => 'abc',

0 commit comments

Comments
 (0)