Skip to content

Commit f97a39f

Browse files
committed
Updated to 1.1.3 version
1 parent 2893ec8 commit f97a39f

File tree

7 files changed

+42
-32
lines changed

7 files changed

+42
-32
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
## 1.1.3 - 2017-07-09
4+
* Added option to analyze concrete urls in some methods.
5+
36
## 1.1.2 - 2017-05-08
47
* Now you can choose to place backslash at the beginning, end or both ends in the addBackslash() method.
58

README-ES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ También puedes clonar el repositorio completo con Git:
4040

4141
### Requisitos
4242

43-
Esta ĺibrería es soportada por versiones de PHP 5.6 o superiores y es compatible con versiones de HHVM 3.0 o superiores.
43+
Esta biblioteca es soportada por versiones de PHP 5.6 o superiores y es compatible con versiones de HHVM 3.0 o superiores.
4444

4545
### Cómo empezar y ejemplos
4646

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ require __DIR__ . '/vendor/autoload.php';
5151

5252
use Josantonius\Url\Url;
5353
```
54+
5455
### Available Methods
5556

5657
Available methods in this library:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "josantonius/url",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"type": "library",
55
"description": "Library for urls manipulation.",
66
"keywords": [

src/Exception/UrlException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<?php
1+
<?php
22
/**
33
* Library for urls manipulation.
44
*
55
* @author Josantonius - [email protected]
6-
* @copyright Copyright (c) 2017 JST PHP Framework
6+
* @copyright Copyright (c) 2017
77
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
88
* @link https://github.com/Josantonius/PHP-Url
99
* @since 1.0.0

src/Url.php

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,21 @@
44
*
55
* @author Josantonius - [email protected]
66
* @author David Carr - [email protected]
7-
* @copyright Copyright (c) 2017 JST PHP Framework
7+
* @copyright Copyright (c) 2017
88
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
99
* @link https://github.com/Josantonius/PHP-Url
1010
* @since 1.0.0
1111
*/
1212

1313
namespace Josantonius\Url;
1414

15-
# use Josantonius\Url\Exception\UrlException;
16-
1715
/**
1816
* Url handler.
1917
*
2018
* @since 1.0.0
2119
*/
2220
class Url {
2321

24-
/**
25-
* Directory separator.
26-
*
27-
* @since 1.1.2
28-
*
29-
* @var string
30-
*/
31-
const DS = DIRECTORY_SEPARATOR;
32-
3322
/**
3423
* Get url from the current page.
3524
*
@@ -49,7 +38,7 @@ public static function getCurrentPage() {
4938

5039
$uri = self::getUri();
5140

52-
return $protocol . ':' . self::DS . self::DS . $host . $port . $uri;
41+
return $protocol . '://' . $host . $port . $uri;
5342
}
5443

5544
/**
@@ -65,9 +54,9 @@ public static function getBaseUrl() {
6554

6655
$url = self::addBackslash(self::getCurrentPage());
6756

68-
if ($uri !== self::DS) {
57+
if ($uri !== '/') {
6958

70-
$url = trim(str_replace($uri, '', $url), self::DS);
59+
$url = trim(str_replace($uri, '', $url), '/');
7160
}
7261

7362
return self::addBackslash($url);
@@ -78,13 +67,20 @@ public static function getBaseUrl() {
7867
*
7968
* @since 1.0.0
8069
*
70+
* @param string $url
71+
*
8172
* @return string → http|https
8273
*/
83-
public static function getProtocol() {
74+
public static function getProtocol($url = false) {
75+
76+
if ($url) {
77+
78+
return (preg_match('/^https/', $url)) ? 'https' : 'http';
79+
}
8480

8581
$protocol = strtolower($_SERVER['SERVER_PROTOCOL']);
8682

87-
$protocol = substr($protocol, 0, strpos($protocol, self::DS));
83+
$protocol = substr($protocol, 0, strpos($protocol, '/'));
8884

8985
$ssl = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on');
9086

@@ -96,21 +92,32 @@ public static function getProtocol() {
9692
*
9793
* @since 1.0.0
9894
*
95+
* @param string $url
96+
*
9997
* @return boolean
10098
*/
101-
public static function isSSL() {
99+
public static function isSSL($url = false) {
102100

103-
return (self::getProtocol() === 'https');
101+
return (self::getProtocol($url) === 'https');
104102
}
105103

106104
/**
107105
* Get the server name.
108106
*
109107
* @since 1.0.0
110108
*
111-
* @return string → server name
109+
* @param string $url
110+
*
111+
* @return string|false → server name
112112
*/
113-
public static function getDomain() {
113+
public static function getDomain($url = false) {
114+
115+
if ($url) {
116+
117+
preg_match('/([\w]+[.]){1,}[a-z]+/', $url, $matches);
118+
119+
return isset($matches[0]) ? $matches[0] : false;
120+
}
114121

115122
return $_SERVER['SERVER_NAME'];
116123
}
@@ -138,9 +145,9 @@ public static function getUriMethods() {
138145

139146
$root = str_replace($_SERVER["DOCUMENT_ROOT"], '', getcwd());
140147

141-
$subfolder = trim($root, self::DS);
148+
$subfolder = trim($root, '/');
142149

143-
return trim(str_replace($subfolder, '', self::getUri()), self::DS);
150+
return trim(str_replace($subfolder, '', self::getUri()), '/');
144151
}
145152

146153
/**
@@ -171,11 +178,11 @@ public static function addBackslash($uri, $position = 'end') {
171178

172179
case 'top':
173180

174-
return (substr($uri, 1) === self::DS) ? $uri : self::DS.$uri;
181+
return (substr($uri, 1) === '/') ? $uri : '/' . $uri;
175182

176183
case 'end':
177184

178-
return (substr($uri, -1) === self::DS) ? $uri : $uri.self::DS;
185+
return (substr($uri, -1) === '/') ? $uri : $uri . '/';
179186

180187
case 'both':
181188

@@ -240,7 +247,6 @@ public static function autoLink($url, $custom = null) {
240247
/**
241248
* This function converts and url segment to an safe one.
242249
* For example: `test name @132` will be converted to `test-name--123`.
243-
* Replace every character that isn't an letter or an number to an dash sign.
244250
* It will also return all letters in lowercase
245251
*
246252
* @since 1.0.0
@@ -272,7 +278,7 @@ public static function segment($uri = null) {
272278

273279
$uri = (!is_null($uri)) ? $uri : $_SERVER['REQUEST_URI'];
274280

275-
return explode(self::DS, trim($uri, self::DS));
281+
return explode('/', trim($uri, '/'));
276282
}
277283

278284
/**

tests/UrlTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Library for urls manipulation.
44
*
55
* @author Josantonius - [email protected]
6-
* @copyright Copyright (c) 2017 JST PHP Framework
6+
* @copyright Copyright (c) 2017
77
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
88
* @link https://github.com/Josantonius/PHP-Url
99
* @since 1.0.0

0 commit comments

Comments
 (0)