Skip to content

Commit

Permalink
UrlScript: added getRelativePath() [Closes #45]
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik authored and dg committed Feb 11, 2019
1 parent a074c59 commit eb8f5dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Http/UrlScript.php
Expand Up @@ -24,6 +24,7 @@
* - pathInfo: /pathinfo/ (additional path information)
*
* @property string $scriptPath
* @property-read string $relativePath
* @property-read string $pathInfo
*/
class UrlScript extends Url
Expand Down Expand Up @@ -59,6 +60,12 @@ public function getScriptPath(): string
}


public function getRelativePath(): string
{
return substr($this->getPath(), strrpos($this->scriptPath, '/') + 1);
}


/**
* Returns the base-path.
*/
Expand Down
18 changes: 18 additions & 0 deletions tests/Http/UrlScript.modify.phpt
Expand Up @@ -23,3 +23,21 @@ Assert::same('/test/', $url->basePath);
Assert::same('?q=search', $url->relativeUrl);
Assert::same('', $url->pathInfo);
Assert::same('http://nette.org:8080/test/?q=search', $url->absoluteUrl);


$url = new UrlScript('http://nette.org:8080/www/about');
$url->scriptPath = '/www/';

Assert::same('/www/about', $url->path);
Assert::same('/www/', $url->scriptPath);
Assert::same('about', $url->relativePath);
Assert::same('about', $url->pathInfo);


$url = new UrlScript('http://nette.org:8080/www/index.php');
$url->scriptPath = '/www/index.php';

Assert::same('/www/index.php', $url->path);
Assert::same('/www/index.php', $url->scriptPath);
Assert::same('index.php', $url->relativePath);
Assert::same('', $url->pathInfo);

0 comments on commit eb8f5dc

Please sign in to comment.