Skip to content

Commit 417bab4

Browse files
JanTvrdikdg
authored andcommitted
UrlScript: added getRelativePath() [Closes #45]
1 parent 08bd4fc commit 417bab4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Http/UrlScript.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* - pathInfo: /pathinfo/ (additional path information)
2525
*
2626
* @property string $scriptPath
27+
* @property-read string $relativePath
2728
* @property-read string $pathInfo
2829
*/
2930
class UrlScript extends Url
@@ -59,6 +60,12 @@ public function getScriptPath(): string
5960
}
6061

6162

63+
public function getRelativePath(): string
64+
{
65+
return substr($this->getPath(), strrpos($this->scriptPath, '/') + 1);
66+
}
67+
68+
6269
/**
6370
* Returns the base-path.
6471
*/

tests/Http/UrlScript.modify.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,21 @@ Assert::same('/test/', $url->basePath);
2323
Assert::same('?q=search', $url->relativeUrl);
2424
Assert::same('', $url->pathInfo);
2525
Assert::same('http://nette.org:8080/test/?q=search', $url->absoluteUrl);
26+
27+
28+
$url = new UrlScript('http://nette.org:8080/www/about');
29+
$url->scriptPath = '/www/';
30+
31+
Assert::same('/www/about', $url->path);
32+
Assert::same('/www/', $url->scriptPath);
33+
Assert::same('about', $url->relativePath);
34+
Assert::same('about', $url->pathInfo);
35+
36+
37+
$url = new UrlScript('http://nette.org:8080/www/index.php');
38+
$url->scriptPath = '/www/index.php';
39+
40+
Assert::same('/www/index.php', $url->path);
41+
Assert::same('/www/index.php', $url->scriptPath);
42+
Assert::same('index.php', $url->relativePath);
43+
Assert::same('', $url->pathInfo);

0 commit comments

Comments
 (0)