-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from nadar/relative-urls
add option for relative url check
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,19 @@ | |
* | ||
* In order to retrieve the url from an object use `getNormalized()`. This value is mainly used to identife and store. | ||
* | ||
* An example where the url is checked for relative path, merge otherwise and validate: | ||
* | ||
* ```php | ||
* $url = new Url('/about/me'); | ||
* if ($url->isRelative()) { | ||
* $url->merge(new Url('https://luya.io')); | ||
* } | ||
* | ||
* if ($url->isValid()) { | ||
* echo $url->getNormalized(); // outputs https://luya.io/about/me | ||
* } | ||
* ``` | ||
* | ||
* @author Basil Suter <[email protected]> | ||
* @since 1.0.0 | ||
*/ | ||
|
@@ -150,6 +163,17 @@ public function isValid() | |
{ | ||
return !in_array($this->getScheme(), ['mailto', 'tel', 'ftp']); | ||
} | ||
|
||
/** | ||
* Whether the original url is a relative url or not | ||
* | ||
* @return boolean | ||
* @since 1.3.0 | ||
*/ | ||
public function isRelative() | ||
{ | ||
return strncmp($this->url, '//', 2) && strpos($this->url, '://') === false; | ||
} | ||
|
||
/** | ||
* If the current URL is missing informations, it cain obtain informations from the to merge url | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters