Skip to content

Commit 33c9409

Browse files
committed
Overall modification prompted by magic functions breaking phpspec tests.
* Fixed typo in 'isMultiLabelDomain' (was isMutliLabelDomain). * Standardized use of Registrable vs. Registerable (registrable is proper spelling) * Removed magic getters, substituted with proper accessors * Made private members previous accessed by accessors, protected to permit inheritance * Changed all tests and docs to reflect changes
1 parent eda0b57 commit 33c9409

File tree

10 files changed

+298
-124
lines changed

10 files changed

+298
-124
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: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,21 @@ public function parseHost($host)
121121
$host = mb_strtolower($host, 'UTF-8');
122122

123123
$subdomain = null;
124-
$registerableDomain = null;
124+
$registrableDomain = null;
125125
$publicSuffix = null;
126126

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

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

@@ -246,17 +246,17 @@ public function isSuffixValid($host)
246246
}
247247

248248
/**
249-
* Returns registerable domain portion of provided host.
249+
* Returns registrable domain portion of provided host.
250250
*
251251
* Per the test cases provided by Mozilla
252252
* (http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1),
253253
* this method should return null if the domain provided is a public suffix.
254254
*
255255
* @param string $host host
256256
*
257-
* @return string registerable domain
257+
* @return string registrable domain
258258
*/
259-
public function getRegisterableDomain($host)
259+
public function getRegistrableDomain($host)
260260
{
261261
if (strpos($host, '.') === false) {
262262
return;
@@ -270,9 +270,9 @@ public function getRegisterableDomain($host)
270270

271271
$publicSuffixParts = array_reverse(explode('.', $publicSuffix));
272272
$hostParts = array_reverse(explode('.', $host));
273-
$registerableDomainParts = $publicSuffixParts + array_slice($hostParts, 0, count($publicSuffixParts) + 1);
273+
$registrableDomainParts = $publicSuffixParts + array_slice($hostParts, 0, count($publicSuffixParts) + 1);
274274

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

278278
/**
@@ -284,18 +284,18 @@ public function getRegisterableDomain($host)
284284
*/
285285
public function getSubdomain($host)
286286
{
287-
$registerableDomain = $this->getRegisterableDomain($host);
287+
$registrableDomain = $this->getRegistrableDomain($host);
288288

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

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

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

297297
$hostParts = array_reverse(explode('.', $host));
298-
$subdomainParts = array_slice($hostParts, count($registerableDomainParts));
298+
$subdomainParts = array_slice($hostParts, count($registrableDomainParts));
299299

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

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

src/Pdp/PublicSuffixListManager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Pdp;
1313

14-
use Pdp\HttpAdapter\HttpAdapterInterface;
1514

1615
/**
1716
* Public Suffix List Manager.

0 commit comments

Comments
 (0)