Skip to content
This repository was archived by the owner on Nov 7, 2020. It is now read-only.

Commit 095a362

Browse files
committed
Merge remote-tracking branch 'origin/7.0_Next'
# Conflicts: # lib/blobfolio/domain/data.php
2 parents feebcab + e29c9c1 commit 095a362

File tree

6 files changed

+766
-266
lines changed

6 files changed

+766
-266
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ branches:
1212
- master
1313

1414
php:
15-
- 5.6
1615
- 7.0
1716
- 7.1
1817
- 7.2
1918

2019
install: travis_retry composer install --no-interaction
2120

22-
script: lib/vendor/bin/phpunit --configuration phpunit.xml.dist
21+
script: lib/vendor/bin/phpunit --configuration phpunit.xml.dist

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ blob-domain is a simple PHP library for parsing and validating domain names. It
2626

2727
## Requirements
2828

29-
blob-domain and its dependencies require PHP 5.6+ with the following modules:
29+
blob-domain and its dependencies require PHP 7.0+ with the following modules:
3030

3131
* BCMath
3232
* DOM

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"ICANN",
1212
"IDN"
1313
],
14-
"version": "0.4.2",
14+
"version": "dev-7.0_Next",
1515
"type": "library",
1616
"homepage": "https:\/\/github.com\/Blobfolio\/blob-domain",
1717
"license": "WTFPL",
@@ -23,13 +23,13 @@
2323
}
2424
],
2525
"require": {
26-
"php": ">= 5.6",
26+
"php": ">= 7.0",
2727
"ext-filter": "*",
2828
"ext-mbstring": "*",
2929
"ext-json": "*",
3030
"ext-intl": "*",
3131

32-
"blobfolio\/blob-common": "*"
32+
"blobfolio\/blob-common": "dev-7.0_Next"
3333
},
3434
"require-dev": {
3535
"phpunit\/phpunit": "5.7.*"

lib/blobfolio/domain/data.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Suffix Data
44
*
55
* This data was automatically generated by the build script on
6-
* 2018-06-01 14:15:32.
6+
* 2018-06-01 14:14:21.
77
*
88
* @see {build/build.php}
99
*

lib/blobfolio/domain/domain.php

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010

1111
namespace blobfolio\domain;
1212

13-
use \blobfolio\common;
13+
use \blobfolio\common\constants;
14+
use \blobfolio\common\data as c_data;
15+
use \blobfolio\common\mb as v_mb;
16+
use \blobfolio\common\ref\cast as r_cast;
17+
use \blobfolio\common\ref\file as r_file;
18+
use \blobfolio\common\ref\mb as r_mb;
19+
use \blobfolio\common\ref\sanitize as r_sanitize;
1420

1521
class domain {
1622

@@ -41,9 +47,7 @@ class domain {
4147
* @param bool $www Strip leading www.
4248
* @return bool True/false.
4349
*/
44-
public function __construct($host='', $www=false) {
45-
common\ref\cast::to_bool($www, true);
46-
50+
public function __construct($host='', bool $www=false) {
4751
// Parse the parts.
4852
if (false === ($parsed = static::parse_host_parts($host))) {
4953
return false;
@@ -73,44 +77,45 @@ public function __construct($host='', $www=false) {
7377
*/
7478
public static function parse_host($host) {
7579
// Try to parse it the easy way.
76-
$tmp = common\mb::parse_url($host, PHP_URL_HOST);
80+
$tmp = v_mb::parse_url($host, PHP_URL_HOST);
7781
if ($tmp) {
7882
$host = $tmp;
7983
}
8084
// Or the hard way?
8185
else {
82-
common\ref\cast::to_string($host, true);
83-
common\ref\mb::trim($host);
86+
r_cast::string($host, true);
87+
88+
r_mb::trim($host, true);
8489

8590
// Cut off the path, if any.
86-
if (false !== ($start = common\mb::strpos($host, '/'))) {
87-
$host = common\mb::substr($host, 0, $start);
91+
if (false !== ($start = v_mb::strpos($host, '/'))) {
92+
$host = v_mb::substr($host, 0, $start, true);
8893
}
8994

9095
// Cut off the query, if any.
91-
if (false !== ($start = common\mb::strpos($host, '?'))) {
92-
$host = common\mb::substr($host, 0, $start);
96+
if (false !== ($start = v_mb::strpos($host, '?'))) {
97+
$host = v_mb::substr($host, 0, $start, true);
9398
}
9499

95100
// Cut off credentials, if any.
96-
if (false !== ($start = common\mb::strpos($host, '@'))) {
97-
$host = common\mb::substr($host, $start + 1);
101+
if (false !== ($start = v_mb::strpos($host, '@'))) {
102+
$host = v_mb::substr($host, $start + 1, null, true);
98103
}
99104

100105
// Is this an IPv6 address?
101106
if (filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
102-
common\ref\sanitize::ip($host, true);
107+
r_sanitize::ip($host, true);
103108
}
104109
elseif (
105-
0 === common\mb::strpos($host, '[') &&
106-
false !== ($end = common\mb::strpos($host, ']'))
110+
(0 === strpos($host, '[')) &&
111+
false !== ($end = v_mb::strpos($host, ']'))
107112
) {
108-
$host = common\mb::substr($host, 1, $end - 1);
109-
common\ref\sanitize::ip($host, true);
113+
$host = v_mb::substr($host, 1, $end - 1, true);
114+
r_sanitize::ip($host, true);
110115
}
111116
// Cut off port, if any.
112-
elseif (false !== ($start = common\mb::strpos($host, ':'))) {
113-
$host = common\mb::substr($host, 0, $start);
117+
elseif (false !== ($start = v_mb::strpos($host, ':'))) {
118+
$host = v_mb::substr($host, 0, $start, true);
114119
}
115120

116121
// If it is empty or invalid, there is nothing we can do.
@@ -121,22 +126,22 @@ public static function parse_host($host) {
121126
// Convert to ASCII if possible.
122127
if (function_exists('idn_to_ascii')) {
123128
$host = explode('.', $host);
124-
common\ref\file::idn_to_ascii($host);
129+
r_file::idn_to_ascii($host);
125130
$host = implode('.', $host);
126131
}
127132

128133
// Lowercase it.
129-
common\ref\mb::strtolower($host);
134+
r_mb::strtolower($host, false, true);
130135

131136
// Get rid of trailing periods.
132137
$host = ltrim($host, '.');
133138
$host = rtrim($host, '.');
134139
}
135140

136141
// Liberate IPv6 from its walls.
137-
if (0 === common\mb::strpos($host, '[')) {
142+
if (0 === strpos($host, '[')) {
138143
$host = str_replace(array('[', ']'), '', $host);
139-
common\ref\sanitize::ip($host, true);
144+
r_sanitize::ip($host, true);
140145
}
141146

142147
// Is this an IP address? If so, we're done!
@@ -154,8 +159,8 @@ public static function parse_host($host) {
154159
// Gotta have length, and can't start or end with a dash.
155160
if (
156161
!strlen($v) ||
157-
'-' === substr($v, 0, 1) ||
158-
'-' === substr($v, -1)
162+
(0 === strpos($v, '-')) ||
163+
('-' === substr($v, -1))
159164
) {
160165
return false;
161166
}
@@ -197,7 +202,7 @@ public static function parse_host_parts($host) {
197202

198203
foreach ($parts as $k=>$part) {
199204
// Override rule.
200-
if (isset($suffixes[$part]) && isset($suffixes[$part]['!'])) {
205+
if (isset($suffixes[$part], $suffixes[$part]['!'])) {
201206
break;
202207
}
203208

@@ -259,8 +264,8 @@ public function strip_www() {
259264
}
260265

261266
if (
262-
'www' === $this->subdomain ||
263-
'www.' === common\mb::substr($this->subdomain, 0, 4)
267+
('www' === $this->subdomain) ||
268+
(0 === strpos($this->subdomain, 'www.'))
264269
) {
265270
$this->subdomain = preg_replace('/^www\.?/u', '', $this->subdomain);
266271
if (!strlen($this->subdomain)) {
@@ -288,8 +293,7 @@ public function strip_www() {
288293
* @param bool $dns Has DNS.
289294
* @return bool True/false.
290295
*/
291-
public function is_valid($dns=false) {
292-
common\ref\cast::to_bool($dns, true);
296+
public function is_valid(bool $dns=false) {
293297
return !is_null($this->host) && (!$dns || $this->has_dns());
294298
}
295299

@@ -311,9 +315,7 @@ public function is_fqdn() {
311315
* @param bool $restricted Allow restricted.
312316
* @return bool True/false.
313317
*/
314-
public function is_ip($restricted=true) {
315-
common\ref\cast::to_bool($restricted, true);
316-
318+
public function is_ip(bool $restricted=true) {
317319
if (!$this->is_valid()) {
318320
return false;
319321
}
@@ -322,7 +324,11 @@ public function is_ip($restricted=true) {
322324
return !!filter_var($this->host, FILTER_VALIDATE_IP);
323325
}
324326

325-
return !!filter_var($this->host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
327+
return !!filter_var(
328+
$this->host,
329+
FILTER_VALIDATE_IP,
330+
FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
331+
);
326332
}
327333

328334
/**
@@ -339,7 +345,11 @@ public function has_dns() {
339345
$this->dns = $this->is_ip(false);
340346
}
341347
else {
342-
$this->dns = !!filter_var(gethostbyname("{$this->host}."), FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
348+
$this->dns = !!filter_var(
349+
gethostbyname("{$this->host}."),
350+
FILTER_VALIDATE_IP,
351+
FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
352+
);
343353
}
344354
}
345355

@@ -401,14 +411,14 @@ public function __call($method, $args) {
401411
preg_match_all('/^get_(.+)$/', $method, $matches);
402412
if (
403413
count($matches[0]) &&
404-
'dns' !== $matches[1][0] &&
414+
('dns' !== $matches[1][0]) &&
405415
property_exists($this, $matches[1][0])
406416
) {
407417
$variable = $matches[1][0];
408418

409419
if (is_array($args) && count($args)) {
410-
$args = common\data::array_pop_top($args);
411-
common\ref\cast::to_bool($args);
420+
$args = c_data::array_pop_top($args);
421+
r_cast::bool($args);
412422
if ($args) {
413423
return $this->to_unicode($variable);
414424
}
@@ -417,7 +427,13 @@ public function __call($method, $args) {
417427
return $this->{$variable};
418428
}
419429

420-
throw new \Exception(sprintf('The required method "%s" does not exist for %s', $method, get_called_class()));
430+
throw new \Exception(
431+
sprintf(
432+
'The required method "%s" does not exist for %s',
433+
$method,
434+
get_called_class()
435+
)
436+
);
421437
}
422438

423439
/**
@@ -430,7 +446,7 @@ protected function to_unicode($key) {
430446
$value = $this->{$key};
431447
if (function_exists('idn_to_utf8') && is_string($value)) {
432448
$value = explode('.', $value);
433-
common\ref\file::idn_to_utf8($value);
449+
r_file::idn_to_utf8($value);
434450
return implode('.', $value);
435451
}
436452

@@ -443,9 +459,7 @@ protected function to_unicode($key) {
443459
* @param bool $unicode Unicode.
444460
* @return array|bool Host data or false.
445461
*/
446-
public function get_data($unicode=false) {
447-
common\ref\cast::to_bool($unicode, true);
448-
462+
public function get_data(bool $unicode=false) {
449463
if (!$this->is_valid()) {
450464
return false;
451465
}

0 commit comments

Comments
 (0)