Skip to content

Commit 415b630

Browse files
committed
Merge pull request #61 from Saeven/develop
Overall modification prompted by magic functions breaking phpspec tests.
2 parents 9db2bfa + 8e19752 commit 415b630

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
@@ -122,21 +122,21 @@ public function parseHost($host)
122122
$host = mb_strtolower($host, 'UTF-8');
123123

124124
$subdomain = null;
125-
$registerableDomain = null;
125+
$registrableDomain = null;
126126
$publicSuffix = null;
127127

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

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

@@ -247,7 +247,7 @@ public function isSuffixValid($host)
247247
}
248248

249249
/**
250-
* Returns registerable domain portion of provided host.
250+
* Returns registrable domain portion of provided host.
251251
*
252252
* Per the test cases provided by Mozilla
253253
* (http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1),
@@ -257,7 +257,7 @@ public function isSuffixValid($host)
257257
*
258258
* @return string|null registerable domain
259259
*/
260-
public function getRegisterableDomain($host)
260+
public function getRegistrableDomain($host)
261261
{
262262
if (strpos($host, '.') === false) {
263263
return;
@@ -271,9 +271,9 @@ public function getRegisterableDomain($host)
271271

272272
$publicSuffixParts = array_reverse(explode('.', $publicSuffix));
273273
$hostParts = array_reverse(explode('.', $host));
274-
$registerableDomainParts = $publicSuffixParts + array_slice($hostParts, 0, count($publicSuffixParts) + 1);
274+
$registrableDomainParts = $publicSuffixParts + array_slice($hostParts, 0, count($publicSuffixParts) + 1);
275275

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

279279
/**
@@ -285,18 +285,18 @@ public function getRegisterableDomain($host)
285285
*/
286286
public function getSubdomain($host)
287287
{
288-
$registerableDomain = $this->getRegisterableDomain($host);
288+
$registrableDomain = $this->getRegistrableDomain($host);
289289

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

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

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

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

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

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

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.
@@ -92,15 +92,6 @@ public function __construct(
9292
$this->fragment = $fragment;
9393
}
9494

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

10596
/**
10697
* Gets schemeless url.
@@ -171,7 +162,7 @@ public function toArray()
171162
'pass' => $this->pass,
172163
'host' => $this->host->__toString(),
173164
'subdomain' => $this->host->getSubdomain(),
174-
'registerableDomain' => $this->host->getRegisterableDomain(),
165+
'registrableDomain' => $this->host->getRegistrableDomain(),
175166
'publicSuffix' => $this->host->getPublicSuffix(),
176167
'port' => $this->port,
177168
'path' => $this->path,

0 commit comments

Comments
 (0)