Skip to content

Commit 4179375

Browse files
committed
bug fix Rules and CurlHttpClient
1 parent 91d24af commit 4179375

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ final class Rules
8787

8888
Domain name resolution is done using the `Pdp\Rules::resolve` method which expects at most two parameters:
8989

90-
- `$domain` a valid domain name as a string
91-
- `$type` a string to optionnally specify which section of the PSL you want to validate the given domain against. The possible values are:
90+
- `$domain` a domain name as a string
91+
- `$type` a string which specifies which section of the PSL you want to validate the given domain against. The possible values are:
9292
- `Rules::ALL_DOMAINS`, to validate against the full PSL.
93-
- `Rules::ICANN_DOMAINS`, to validate against the PSL ICANN section only.
94-
- `Rules::PRIVATE_DOMAINS`, to validate against the PSL PRIVATE section only.
93+
- `Rules::ICANN_DOMAINS`, to validate against the PSL ICANN DOMAINS section only.
94+
- `Rules::PRIVATE_DOMAINS`, to validate against the PSL PRIVATE DOMAINS section only.
9595

96-
By default, the `$type` argument is equal to `Rules::ALL_DOMAINS`. If an unrecognized section is submitted otherwise, a `Pdp\Exception` exception will be thrown.
96+
By default, the `$type` argument is equal to `Rules::ALL_DOMAINS`. If an unsupported section is submitted otherwise, a `Pdp\Exception` exception will be thrown.
9797

9898

9999
The `Pdp\Rules::resolve` returns a `Pdp\Domain` object.
@@ -118,15 +118,15 @@ The `Pdp\Domain` getter methods returns:
118118
- the submitted domain name using `Pdp\Domain::getDomain`
119119
- the public suffix part normalized according to the domain using `Pdp\Domain::getPublicSuffix`
120120
- the registrable domain part using `Pdp\Domain::getRegistrableDomain`
121-
- the subdomain part usung `Pdp\Domain::getSubDomain`.
121+
- the subdomain part using `Pdp\Domain::getSubDomain`.
122122

123123
If the domain name or some of its part are seriously malformed or unrecognized, the getter methods will return `null`.
124124

125-
**The Domain name public status status depends on the PSL section used to resolve them:**
125+
**The Domain name status depends on the PSL section used to resolve it:**
126126

127-
- `Pdp\Domain::isKnown` returns `true` if the public suffix is found in the selected PSL
128-
- `Pdp\Domain::isICANN` returns `true` if the domain name resolution is done against a PSL which includes the ICANN DOMAINS section and its public suffix is found in it;
129-
- `Pdp\Domain::isPrivate` returns `true` if the domain name resolution is done against a PSL which includes the PRIVATE DOMAINS section and its public suffix is found in it;
127+
- `Pdp\Domain::isKnown` returns `true` if the public suffix is found in the selected PSL;
128+
- `Pdp\Domain::isICANN` returns `true` if the public suffix is found in a selected PSL which includes the ICANN DOMAINS section;
129+
- `Pdp\Domain::isPrivate` returns `true` if the public suffix is found in a selected PSL which includes the PRIVATE DOMAINS section;
130130

131131
**THIS EXAMPLE ILLUSTRATES HOW EACH OBJECT IS USED BUT SHOULD BE AVOID IN A PRODUCTIVE ENVIRONMENT**
132132

@@ -137,8 +137,8 @@ use Pdp\Converter;
137137
use Pdp\Rules;
138138

139139
$content = file_get_contents('https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat');
140-
$arr = (new Converter())->convert($raw);
141-
$rules = new Rules($arr);
140+
$arr_rules = (new Converter())->convert($content);
141+
$rules = new Rules($arr_rules);
142142

143143
$domain = $rules->resolve('www.ulb.ac.be'); //using Rules::ALL_DOMAINS
144144
$domain->getDomain(); //returns 'www.ulb.ac.be'
@@ -278,9 +278,9 @@ echo json_encode($domain, JSON_PRETTY_PRINT);
278278
// }
279279
~~~
280280

281-
#### Refreshing the cached rules
281+
#### Refreshing the cached PSL
282282

283-
The `Manager::refreshRules` method enables refreshing your local copy of the PSL stored with your [PSR-16](http://www.php-fig.org/psr/psr-16/) Cache and retrieved using the Http Client. By default the method will use the `Manager::PSL_URL` as the source URL but you are free to substitute this URL with your own.
283+
The `Pdp\Manager::refreshRules` method enables refreshing your local copy of the PSL stored with your [PSR-16](http://www.php-fig.org/psr/psr-16/) Cache and retrieved using the Http Client. By default the method will use the `Manager::PSL_URL` as the source URL but you are free to substitute this URL with your own.
284284
The method returns a boolean value which is `true` on success.
285285

286286
~~~php

src/CurlHttpClient.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Pdp;
1313

14-
use InvalidArgumentException;
15-
1614
/**
1715
* Simple cURL Http client
1816
*
@@ -52,7 +50,7 @@ public function __construct(array $options = [])
5250
$res = @curl_setopt_array($curl, $this->options);
5351
curl_close($curl);
5452
if (!$res) {
55-
throw new InvalidArgumentException('Please verify your curl additionnal options');
53+
throw new Exception('Please verify your curl additionnal options');
5654
}
5755
}
5856

src/Rules.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private function findPublicSuffix(string $domain, string $type): PublicSuffix
145145
*/
146146
private function findPublicSuffixFromSection(array $labels, string $type): PublicSuffix
147147
{
148-
$rules = $this->rules[$type];
148+
$rules = $this->rules[$type] ?? null;
149149
$matches = [];
150150
foreach ($labels as $label) {
151151
//match exception rule
@@ -161,11 +161,6 @@ private function findPublicSuffixFromSection(array $labels, string $type): Publi
161161

162162
//no match found
163163
if (!isset($rules[$label])) {
164-
// Avoids improper parsing when $domain's subdomain + public suffix ===
165-
// a valid public suffix (e.g. domain 'us.example.com' and public suffix 'us.com')
166-
//
167-
// Added by @goodhabit in https://github.com/jeremykendall/php-domain-parser/pull/15
168-
// Resolves https://github.com/jeremykendall/php-domain-parser/issues/16
169164
break;
170165
}
171166

tests/CurlHttpClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace pdp\tests;
66

7-
use InvalidArgumentException;
87
use Pdp\CurlHttpClient;
8+
use Pdp\Exception;
99
use Pdp\HttpClientException;
1010
use PHPUnit\Framework\TestCase;
1111

@@ -26,7 +26,7 @@ public function testThrowsException()
2626

2727
public function testConstructorThrowsException()
2828
{
29-
$this->expectException(InvalidArgumentException::class);
29+
$this->expectException(Exception::class);
3030
new CurlHttpClient(['foo' => 'bar']);
3131
}
3232
}

0 commit comments

Comments
 (0)