diff options
Diffstat (limited to 'application/Url.php')
-rw-r--r-- | application/Url.php | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/application/Url.php b/application/Url.php index af43b457..a4ac2e73 100644 --- a/application/Url.php +++ b/application/Url.php | |||
@@ -52,6 +52,18 @@ function get_url_scheme($url) | |||
52 | } | 52 | } |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Adds a trailing slash at the end of URL if necessary. | ||
56 | * | ||
57 | * @param string $url URL to check/edit. | ||
58 | * | ||
59 | * @return string $url URL with a end trailing slash. | ||
60 | */ | ||
61 | function add_trailing_slash($url) | ||
62 | { | ||
63 | return $url . (!endsWith($url, '/') ? '/' : ''); | ||
64 | } | ||
65 | |||
66 | /** | ||
55 | * URL representation and cleanup utilities | 67 | * URL representation and cleanup utilities |
56 | * | 68 | * |
57 | * Form | 69 | * Form |
@@ -106,7 +118,7 @@ class Url | |||
106 | */ | 118 | */ |
107 | public function __construct($url) | 119 | public function __construct($url) |
108 | { | 120 | { |
109 | $this->parts = parse_url($url); | 121 | $this->parts = parse_url(trim($url)); |
110 | 122 | ||
111 | if (!empty($url) && empty($this->parts['scheme'])) { | 123 | if (!empty($url) && empty($this->parts['scheme'])) { |
112 | $this->parts['scheme'] = 'http'; | 124 | $this->parts['scheme'] = 'http'; |
@@ -189,4 +201,13 @@ class Url | |||
189 | } | 201 | } |
190 | return $this->parts['scheme']; | 202 | return $this->parts['scheme']; |
191 | } | 203 | } |
204 | |||
205 | /** | ||
206 | * Test if the Url is an HTTP one. | ||
207 | * | ||
208 | * @return true is HTTP, false otherwise. | ||
209 | */ | ||
210 | public function isHttp() { | ||
211 | return strpos(strtolower($this->parts['scheme']), 'http') !== false; | ||
212 | } | ||
192 | } | 213 | } |