Skip to content

Commit 88a36ab

Browse files
committed
Merge branch 'develop' of git://github.com/Saeven/php-domain-parser into Saeven-develop
Resolving merge conflicts I caused so @Saeven doesn't have to sort out what I broke :-)
2 parents ee17687 + 4a4678f commit 88a36ab

File tree

9 files changed

+154
-144
lines changed

9 files changed

+154
-144
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ domain parser implemented in PHP.
1111

1212
While there are plenty of excellent URL parsers and builders available, there
1313
are very few projects that can accurately parse a url into its component
14-
subdomain, registerable domain, and public suffix parts.
14+
subdomain, registrable domain, and public suffix parts.
1515

1616
Consider the domain www.pref.okinawa.jp. In this domain, the
17-
*public suffix* portion is **okinawa.jp**, the *registerable domain* is
17+
*public suffix* portion is **okinawa.jp**, the *registrable domain* is
1818
**pref.okinawa.jp**, and the *subdomain* is **www**. You can't regex that.
1919

2020
Other similar libraries focus primarily on URL building, parsing, and
@@ -77,7 +77,7 @@ class Pdp\Uri\Url#6 (8) {
7777
class Pdp\Uri\Url\Host#5 (3) {
7878
private $subdomain =>
7979
string(3) "www"
80-
private $registerableDomain =>
80+
private $registrableDomain =>
8181
string(15) "pref.okinawa.jp"
8282
private $publicSuffix =>
8383
string(10) "okinawa.jp"
@@ -139,7 +139,7 @@ class Pdp\Uri\Url#6 (8) {
139139
class Pdp\Uri\Url\Host#5 (4) {
140140
private $subdomain =>
141141
NULL
142-
private $registerableDomain =>
142+
private $registrableDomain =>
143143
string(17) "яндекс.рф"
144144
private $publicSuffix =>
145145
string(4) "рф"
@@ -175,7 +175,7 @@ class Pdp\Uri\Url#6 (8) {
175175
class Pdp\Uri\Url\Host#5 (4) {
176176
private $subdomain =>
177177
NULL
178-
private $registerableDomain =>
178+
private $registrableDomain =>
179179
string(22) "xn--d1acpjx3f.xn--p1ai"
180180
private $publicSuffix =>
181181
string(8) "xn--p1ai"
@@ -211,7 +211,7 @@ class Pdp\Uri\Url#6 (8) {
211211
class Pdp\Uri\Url\Host#5 (4) {
212212
private $subdomain =>
213213
NULL
214-
private $registerableDomain =>
214+
private $registrableDomain =>
215215
NULL
216216
private $publicSuffix =>
217217
NULL
@@ -257,7 +257,7 @@ The above will output:
257257
class Pdp\Uri\Url\Host#7 (3) {
258258
private $subdomain =>
259259
string(1) "a"
260-
private $registerableDomain =>
260+
private $registrableDomain =>
261261
string(6) "b.c.cy"
262262
private $publicSuffix =>
263263
string(4) "c.cy"
@@ -292,7 +292,7 @@ retrieve only the component you're interested in
292292
<?php
293293

294294
var_dump($parser->getSubdomain('www.scottwills.co.uk'));
295-
var_dump($parser->getRegisterableDomain('www.scottwills.co.uk'));
295+
var_dump($parser->getRegistrableDomain('www.scottwills.co.uk'));
296296
var_dump($parser->getPublicSuffix('www.scottwills.co.uk'));
297297
```
298298

@@ -331,7 +331,7 @@ Array
331331
[pass] =>
332332
[host] => www.waxaudio.com.au
333333
[subdomain] => www
334-
[registerableDomain] => waxaudio.com.au
334+
[registrableDomain] => waxaudio.com.au
335335
[publicSuffix] => com.au
336336
[port] =>
337337
[path] => /

example.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,31 @@
1515
// Accessing elements of the URL
1616
var_dump($url);
1717
var_dump($url->__toString());
18-
var_dump($url->path);
19-
var_dump($url->fragment);
18+
var_dump($url->getPath());
19+
var_dump($url->getFragment());
2020

2121
// Getting the Host object from the URL
22-
$host = $url->host;
22+
$host = $url->getHost();
2323

2424
// Accessing elements of the Host
2525
var_dump($host);
2626
var_dump($host->__toString());
27-
var_dump($host->subdomain);
28-
var_dump($host->registerableDomain);
29-
var_dump($host->publicSuffix);
27+
var_dump($host->getSubdomain());
28+
var_dump($host->getRegistrableDomain());
29+
var_dump($host->getPublicSuffix());
3030

3131
// It's possible to parse a host only, if you prefer
3232
$host = $parser->parseHost('a.b.c.cy');
3333

3434
// Accessing elements of the Host
3535
var_dump($host);
3636
var_dump($host->__toString());
37-
var_dump($host->subdomain);
38-
var_dump($host->registerableDomain);
39-
var_dump($host->publicSuffix);
37+
var_dump($host->getSubdomain());
38+
var_dump($host->getRegistrableDomain());
39+
var_dump($host->getPublicSuffix());
4040

41-
// If you just need to know subdomain/registerable domain/public suffix info
41+
// If you just need to know subdomain/registrable domain/public suffix info
4242
// about a host, there are public methods available for that in the Parser
4343
var_dump($parser->getSubdomain('www.scottwills.co.uk'));
44-
var_dump($parser->getRegisterableDomain('www.scottwills.co.uk'));
44+
var_dump($parser->getRegistrableDomain('www.scottwills.co.uk'));
4545
var_dump($parser->getPublicSuffix('www.scottwills.co.uk'));

src/Pdp/Parser.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,21 @@ public function parseHost($host)
120120
$host = mb_strtolower($host, 'UTF-8');
121121

122122
$subdomain = null;
123-
$registerableDomain = null;
123+
$registrableDomain = null;
124124
$publicSuffix = null;
125125

126126
// Fixes #22: Single label domains are set as Host::$host and all other
127127
// properties are null.
128128
// Fixes #43: Ip Addresses should not be parsed
129-
if ($this->isMutliLabelDomain($host) || !$this->isIpv4Address($host)) {
129+
if ($this->isMultiLabelDomain($host) || !$this->isIpv4Address($host)) {
130130
$subdomain = $this->getSubdomain($host);
131-
$registerableDomain = $this->getRegisterableDomain($host);
131+
$registrableDomain = $this->getRegistrableDomain($host);
132132
$publicSuffix = $this->getPublicSuffix($host);
133133
}
134134

135135
return new Host(
136136
$subdomain,
137-
$registerableDomain,
137+
$registrableDomain,
138138
$publicSuffix,
139139
$host
140140
);
@@ -210,7 +210,7 @@ public function getPublicSuffix($host)
210210
// Fixes #22: If a single label domain makes it this far (e.g.,
211211
// localhost, foo, etc.), this stops it from incorrectly being set as
212212
// the public suffix.
213-
if (!$this->isMutliLabelDomain($host)) {
213+
if (!$this->isMultiLabelDomain($host)) {
214214
return;
215215
}
216216

@@ -245,7 +245,7 @@ public function isSuffixValid($host)
245245
}
246246

247247
/**
248-
* Returns registerable domain portion of provided host.
248+
* Returns registrable domain portion of provided host.
249249
*
250250
* Per the test cases provided by Mozilla
251251
* (http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1),
@@ -255,7 +255,7 @@ public function isSuffixValid($host)
255255
*
256256
* @return string|null registerable domain
257257
*/
258-
public function getRegisterableDomain($host)
258+
public function getRegistrableDomain($host)
259259
{
260260
if (strpos($host, '.') === false) {
261261
return;
@@ -269,9 +269,9 @@ public function getRegisterableDomain($host)
269269

270270
$publicSuffixParts = array_reverse(explode('.', $publicSuffix));
271271
$hostParts = array_reverse(explode('.', $host));
272-
$registerableDomainParts = $publicSuffixParts + array_slice($hostParts, 0, count($publicSuffixParts) + 1);
272+
$registrableDomainParts = $publicSuffixParts + array_slice($hostParts, 0, count($publicSuffixParts) + 1);
273273

274-
return implode('.', array_reverse($registerableDomainParts));
274+
return implode('.', array_reverse($registrableDomainParts));
275275
}
276276

277277
/**
@@ -283,18 +283,18 @@ public function getRegisterableDomain($host)
283283
*/
284284
public function getSubdomain($host)
285285
{
286-
$registerableDomain = $this->getRegisterableDomain($host);
286+
$registrableDomain = $this->getRegistrableDomain($host);
287287

288-
if ($registerableDomain === null || $host === $registerableDomain) {
288+
if ($registrableDomain === null || $host === $registrableDomain) {
289289
return;
290290
}
291291

292-
$registerableDomainParts = array_reverse(explode('.', $registerableDomain));
292+
$registrableDomainParts = array_reverse(explode('.', $registrableDomain));
293293

294294
$host = $this->normalize($host);
295295

296296
$hostParts = array_reverse(explode('.', $host));
297-
$subdomainParts = array_slice($hostParts, count($registerableDomainParts));
297+
$subdomainParts = array_slice($hostParts, count($registrableDomainParts));
298298

299299
$subdomain = implode('.', array_reverse($subdomainParts));
300300

@@ -348,7 +348,7 @@ protected function denormalize($part)
348348
*
349349
* @return bool True if multi-label domain, false otherwise
350350
*/
351-
protected function isMutliLabelDomain($host)
351+
protected function isMultiLabelDomain($host)
352352
{
353353
return strpos($host, '.') !== false;
354354
}

src/Pdp/Uri/Url.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,42 @@ class Url
2121
/**
2222
* @var string scheme
2323
*/
24-
private $scheme;
24+
protected $scheme;
2525

2626
/**
2727
* @var Host Host object
2828
*/
29-
private $host;
29+
protected $host;
3030

3131
/**
3232
* @var int port
3333
*/
34-
private $port;
34+
protected $port;
3535

3636
/**
3737
* @var string user
3838
*/
39-
private $user;
39+
protected $user;
4040

4141
/**
4242
* @var string pass
4343
*/
44-
private $pass;
44+
protected $pass;
4545

4646
/**
4747
* @var string path
4848
*/
49-
private $path;
49+
protected $path;
5050

5151
/**
5252
* @var string query
5353
*/
54-
private $query;
54+
protected $query;
5555

5656
/**
5757
* @var string fragment
5858
*/
59-
private $fragment;
59+
protected $fragment;
6060

6161
/**
6262
* Public constructor.
@@ -90,15 +90,6 @@ public function __construct(
9090
$this->fragment = $fragment;
9191
}
9292

93-
/**
94-
* Magic getter.
95-
*
96-
* @param mixed $name Property name to get
97-
*/
98-
public function __get($name)
99-
{
100-
return $this->$name;
101-
}
10293

10394
/**
10495
* Gets schemeless url.
@@ -169,7 +160,7 @@ public function toArray()
169160
'pass' => $this->pass,
170161
'host' => $this->host->__toString(),
171162
'subdomain' => $this->host->getSubdomain(),
172-
'registerableDomain' => $this->host->getRegisterableDomain(),
163+
'registrableDomain' => $this->host->getRegistrableDomain(),
173164
'publicSuffix' => $this->host->getPublicSuffix(),
174165
'port' => $this->port,
175166
'path' => $this->path,

0 commit comments

Comments
 (0)