Skip to content

Commit d8480a1

Browse files
author
Paul M. Jones
committed
first pass at tweaking jeremy's work
1 parent 55df834 commit d8480a1

32 files changed

+81
-341
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

bin/aura-psl hold/bin/aura-psl

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src.php

-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
require_once __DIR__ . '/src/Aura/Uri/Path.php';
44
require_once __DIR__ . '/src/Aura/Uri/Query.php';
55
require_once __DIR__ . '/src/Aura/Uri/PublicSuffixList.php';
6-
require_once __DIR__ . '/src/Aura/Uri/PublicSuffixListManager.php';
76
require_once __DIR__ . '/src/Aura/Uri/Url.php';
8-
require_once __DIR__ . '/src/Aura/Uri/HttpAdapter/HttpAdapterInterface.php';
9-
require_once __DIR__ . '/src/Aura/Uri/HttpAdapter/CurlHttpAdapter.php';
107
require_once __DIR__ . '/src/Aura/Uri/Url/Factory.php';

src/Aura/Uri/Host.php

+34-23
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,41 @@
1717
* @package Aura.Uri
1818
*
1919
*/
20-
class Host extends \ArrayObject
20+
class Host
2121
{
2222
/**
2323
* @var PublicSuffixList Public Suffix List
2424
*/
25-
protected $publicSuffixList;
25+
protected $psl;
26+
27+
28+
protected $subdomain;
29+
protected $registerableDomain;
30+
protected $publicSuffix;
31+
2632

2733
/**
2834
*
2935
* Constructor
3036
*
31-
* @param PublicSuffixList $publicSuffixList Public Suffix List
37+
* @param PublicSuffixList $psl Public Suffix List
3238
*
3339
* @param array $spec Host elements
3440
*
3541
*/
36-
public function __construct(PublicSuffixList $publicSuffixList, array $spec = array())
42+
public function __construct(PublicSuffixList $psl, array $spec = [])
3743
{
38-
$this->publicSuffixList = $publicSuffixList;
39-
parent::__construct($spec);
44+
$this->psl = $psl;
45+
foreach ($spec as $key => $val) {
46+
$this->$key = $val;
47+
}
4048
}
4149

50+
public function __get($key)
51+
{
52+
return $this->$key;
53+
}
54+
4255
/**
4356
*
4457
* Converts the Host object to a string and returns it.
@@ -49,7 +62,7 @@ public function __construct(PublicSuffixList $publicSuffixList, array $spec = ar
4962
public function __toString()
5063
{
5164
$toString = array_filter(
52-
[$this['subdomain'], $this['registerableDomain']],
65+
[$this->subdomain, $this->registerableDomain],
5366
'strlen'
5467
);
5568

@@ -69,18 +82,16 @@ public function __toString()
6982
*/
7083
public function setFromString($spec)
7184
{
72-
$this->exchangeArray([]);
73-
74-
$this['registerableDomain'] = $this->getRegisterableDomain($spec);
75-
$this['publicSuffix'] = substr($this['registerableDomain'], strpos($this['registerableDomain'], '.') + 1);
85+
$this->registerableDomain = $this->getRegisterableDomain($spec);
86+
$this->publicSuffix = substr($this->registerableDomain, strpos($this->registerableDomain, '.') + 1);
7687

77-
$registerableDomainParts = explode('.', $this['registerableDomain']);
88+
$registerableDomainParts = explode('.', $this->registerableDomain);
7889
$hostParts = explode('.', $spec);
7990
$subdomainParts = array_diff($hostParts, $registerableDomainParts);
80-
$this['subdomain'] = implode('.', $subdomainParts);
91+
$this->subdomain = implode('.', $subdomainParts);
8192

82-
if (empty($this['subdomain']) && !is_null($this['subdomain'])) {
83-
$this['subdomain'] = null;
93+
if (empty($this->subdomain) && !is_null($this->subdomain)) {
94+
$this->subdomain = null;
8495
}
8596
}
8697

@@ -108,7 +119,7 @@ public function getRegisterableDomain($domain)
108119
$publicSuffix = array();
109120

110121
$domainParts = explode('.', strtolower($domain));
111-
$registerableDomain = $this->breakdown($domainParts, $this->publicSuffixList, $publicSuffix);
122+
$registerableDomain = $this->breakdown($domainParts, $this->psl, $publicSuffix);
112123

113124
// Remove null values
114125
$publicSuffix = array_filter($publicSuffix, 'strlen');
@@ -131,28 +142,28 @@ public function getRegisterableDomain($domain)
131142
* @link https://github.com/usrflo/registered-domain-libs/blob/master/PHP/regDomain.inc.php regDomain.inc.php
132143
*
133144
* @param array $domainParts Domain parts as array
134-
* @param array $publicSuffixList Array representation of the Public Suffix
145+
* @param array $psl Array representation of the Public Suffix
135146
* List
136147
* @param array $publicSuffix Builds the public suffix during recursion
137148
* @return string Public suffix
138149
*/
139-
protected function breakdown(array $domainParts, $publicSuffixList, &$publicSuffix)
150+
protected function breakdown(array $domainParts, $psl, &$publicSuffix)
140151
{
141152
$part = array_pop($domainParts);
142153
$result = null;
143154

144-
if (array_key_exists($part, $publicSuffixList) && array_key_exists('!', $publicSuffixList[$part])) {
155+
if (array_key_exists($part, $psl) && array_key_exists('!', $psl[$part])) {
145156
return $part;
146157
}
147158

148-
if (array_key_exists($part, $publicSuffixList)) {
159+
if (array_key_exists($part, $psl)) {
149160
array_unshift($publicSuffix, $part);
150-
$result = $this->breakdown($domainParts, $publicSuffixList[$part], $publicSuffix);
161+
$result = $this->breakdown($domainParts, $psl[$part], $publicSuffix);
151162
}
152163

153-
if (array_key_exists('*', $publicSuffixList)) {
164+
if (array_key_exists('*', $psl)) {
154165
array_unshift($publicSuffix, $part);
155-
$result = $this->breakdown($domainParts, $publicSuffixList['*'], $publicSuffix);
166+
$result = $this->breakdown($domainParts, $psl['*'], $publicSuffix);
156167
}
157168

158169
if ($result === null) {

src/Aura/Uri/PublicSuffixList.php

-16
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,4 @@
1919
*/
2020
class PublicSuffixList extends \ArrayObject
2121
{
22-
/**
23-
* Public constructor
24-
*
25-
* @param mixed $list Array representing Public Suffix List or PHP Public
26-
* Suffix List file
27-
* @throws \InvalidArgumentException If $list is not array, file did not
28-
* contain an array, or $list is not an object
29-
*/
30-
public function __construct($list)
31-
{
32-
if (!is_array($list)) {
33-
$list = include $list;
34-
}
35-
36-
parent::__construct($list);
37-
}
3822
}

src/Aura/Uri/Url/Factory.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Aura\Uri\Path;
1515
use Aura\Uri\Query;
1616
use Aura\Uri\Host;
17-
use Aura\Uri\PublicSuffixListManager;
17+
use Aura\Uri\PublicSuffixList;
1818

1919
/**
2020
*
@@ -34,14 +34,16 @@ class Factory
3434
*/
3535
protected $current;
3636

37+
protected $psl;
38+
3739
/**
3840
*
3941
* Constructor.
4042
*
4143
* @param array $server An array copy of $_SERVER.
4244
*
4345
*/
44-
public function __construct(array $server)
46+
public function __construct(array $server, PublicSuffixList $psl)
4547
{
4648
$https = isset($server['HTTPS'])
4749
&& strtolower($server['HTTPS']) == 'on';
@@ -68,6 +70,8 @@ public function __construct(array $server)
6870
}
6971

7072
$this->current = $scheme . '://' . $host . $resource;
73+
74+
$this->psl = $psl;
7175
}
7276

7377
/**
@@ -104,8 +108,7 @@ public function newInstance($spec)
104108
$query = new Query([]);
105109
$query->setFromString($elem['query']);
106110

107-
$listManager = new PublicSuffixListManager();
108-
$host = new Host($listManager->getList(), []);
111+
$host = new Host($this->psl, []);
109112
$host->setFromString($elem['host']);
110113

111114
return new Url(

tests/Aura/Uri/HostTest.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ class HostTest extends \PHPUnit_Framework_TestCase
1212
protected function setUp()
1313
{
1414
parent::setUp();
15-
$list = new PublicSuffixList(__DIR__ . '/../../_files/public-suffix-list.php');
15+
16+
$file = dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR
17+
. 'data' . DIRECTORY_SEPARATOR
18+
. 'public-suffix-list.php';
19+
20+
$list = new PublicSuffixList(require $file);
1621
$this->host = new Host($list);
1722
}
1823

@@ -55,9 +60,9 @@ public function testParse($url, $publicSuffix, $registerableDomain, $subdomain)
5560
{
5661
$this->host->setFromString($url);
5762

58-
$this->assertSame($subdomain, $this->host['subdomain']);
59-
$this->assertEquals($publicSuffix, $this->host['publicSuffix']);
60-
$this->assertEquals($registerableDomain, $this->host['registerableDomain']);
63+
$this->assertSame($subdomain, $this->host->subdomain);
64+
$this->assertEquals($publicSuffix, $this->host->publicSuffix);
65+
$this->assertEquals($registerableDomain, $this->host->registerableDomain);
6166
}
6267

6368
public function parseDataProvider()

tests/Aura/Uri/HttpAdapter/CurlHttpAdapterTest.php

-34
This file was deleted.

0 commit comments

Comments
 (0)