Skip to content

Commit e47fccb

Browse files
committed
remove supports and getSection methods
1 parent fc579c0 commit e47fccb

File tree

3 files changed

+17
-34
lines changed

3 files changed

+17
-34
lines changed

CHANGELOG.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ All Notable changes to `PHP Domain Parser` **5.x** series will be documented in
66

77
### Added
88

9-
- `Pdp\Rules::supports` returns a boolean to indicates if a given section is supported
109
- `Pdp\Rules::getPublicSuffix` returns a `Pdp\PublicSuffix` value object
1110
- `Pdp\Rules::__set_state` is implemented
12-
- `Pdp\Domain::getSection` returns a string containing the section name used to determine the public suffix
1311
- `Pdp\Domain::toUnicode` returns a `Pdp\Domain` with its value converted to its Unicode form
1412
- `Pdp\Domain::toAscii` returns a `Pdp\Domain` with its value converted to its AScii form
15-
- `Pdp\PublicSuffix::getSection` returns a string containing the section name used to determine the public suffix
1613
- `Pdp\PublicSuffix::toUnicode` returns a `Pdp\PublicSuffix` with its value converted to its Unicode form
1714
- `Pdp\PublicSuffix::toAscii` returns a `Pdp\PublicSuffix` with its value converted to its AScii form
1815

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,13 @@ final class Rules
6464
public static function createFromPath(string $path, $context = null): self
6565
public static function createFromString(string $content): self
6666
public function __construct(array $rules)
67-
public function supports(string $section): bool
6867
public function getPublicSuffix(string $domain = null, string $section = self::ALL_DOMAINS): PublicSuffix
6968
public function resolve(string $domain = null, string $section = self::ALL_DOMAINS): Domain
7069
}
7170
~~~
7271

7372
**NEW IN VERSION 5.2:**
7473

75-
- `Rules::supports` returns a boolean to tell whether the specific section is present in the `Rules` object;
7674
- `Rules::getPublicSuffix` returns a `PublicSuffix` object determined from the `Rules` object;
7775

7876
**NEW IN VERSION 5.1:**
@@ -111,17 +109,16 @@ final class Domain implements JsonSerializable
111109
public function isKnown(): bool;
112110
public function isICANN(): bool;
113111
public function isPrivate(): bool;
114-
public function getSection(): string;
115112
public function toUnicode(): self;
116113
public function toAscii(): self;
117114
}
118115
~~~
119116

120117
**NEW IN VERSION 5.2:**
121118

122-
- `Domain::getSection` returns the section string name if presents else returns an empty string;
123119
- `Domain::toUnicode` returns an instance with the domain converted to its unicode representation;
124120
- `Domain::toAscii` returns an instance with the domain converted to its ascii representation;
121+
- `Domain::getDomain` will lowercase the domain name to normalize its content;
125122

126123
**THIS EXAMPLE ILLUSTRATES HOW THE OBJECT WORK BUT SHOULD BE AVOIDED IN PRODUCTON**
127124

@@ -134,7 +131,7 @@ use Pdp\Converter;
134131
$pdp_url = 'https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat';
135132
$rules = Rules::createFromPath($pdp_url);
136133

137-
$domain = $rules->resolve('www.ulb.ac.be'); //using Rules::ALL_DOMAINS
134+
$domain = $rules->resolve('www.Ulb.AC.be'); //using Rules::ALL_DOMAINS
138135
$domain->getDomain(); //returns 'www.ulb.ac.be'
139136
$domain->getPublicSuffix(); //returns 'ac.be'
140137
$domain->getRegistrableDomain(); //returns 'ulb.ac.be'
@@ -156,7 +153,7 @@ echo json_encode($domain, JSON_PRETTY_PRINT);
156153

157154
//The same domain will yield a different result using the PSL PRIVATE DOMAIN SECTION only
158155

159-
$domain = $rules->resolve('www.ulb.ac.be', Rules::PRIVATE_DOMAINS);
156+
$domain = $rules->resolve('www.Ulb.AC.be', Rules::PRIVATE_DOMAINS);
160157
echo json_encode($domain, JSON_PRETTY_PRINT);
161158
// returns
162159
// {
@@ -196,16 +193,15 @@ final class PublicSuffix implements Countable, JsonSerializable
196193
public function isKnown(): bool;
197194
public function isICANN(): bool;
198195
public function isPrivate(): bool;
199-
public function getSection(): string;
200196
public function toUnicode(): self;
201197
public function toAscii(): self;
202198
}
203199
~~~
204200

205201
While `Rules::resolve` will only throws an exception if the section value is invalid, the `Rules::getPublicSuffix` is more restrictive and will additionnally throw if:
206202

207-
- If the Domain is invalid or seriously malformed
208-
- If the PublicSuffix can not be normalized and converted using the domain encoding.
203+
- The domain name is invalid or seriously malformed
204+
- The public suffix can not be normalized and converted using the domain encoding.
209205

210206
**WARNING:**
211207

@@ -241,8 +237,9 @@ To work as intended, the `Pdp\Manager` constructor requires:
241237

242238
- a [PSR-16](http://www.php-fig.org/psr/psr-16/) Cache object to store the rules locally.
243239

244-
- a `Pdp\HttpClient` object to retrieve the PSL.
245-
the `Pdp\HttpClient` is a simple interface which exposes the `HttpClient::getContent` method. This method expects a string URL representation has its sole argument and returns the body from the given URL resource as a string.
240+
- a `Pdp\HttpClient` object to retrieve the PSL.
241+
242+
The `Pdp\HttpClient` is a simple interface which exposes the `HttpClient::getContent` method. This method expects a string URL representation has its sole argument and returns the body from the given URL resource as a string.
246243
If an error occurs while retrieving such body a `HttpClientException` exception is thrown.
247244

248245
~~~php

src/Rules.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,6 @@ public function __construct(array $rules)
8787
$this->rules = $rules;
8888
}
8989

90-
/**
91-
* Tell whether the submitted section if supported by the current object
92-
*
93-
* @param string $section
94-
*
95-
* @return bool
96-
*/
97-
public function supports(string $section): bool
98-
{
99-
if (self::ALL_DOMAINS === $section) {
100-
return true;
101-
}
102-
103-
$rules = $this->rules[$section] ?? null;
104-
105-
return !(null === $rules || !is_array($rules) || empty($rules));
106-
}
107-
10890
/**
10991
* Determines the public suffix for a given domain.
11092
*
@@ -174,9 +156,16 @@ private function isMatchable($domain): bool
174156
*/
175157
private function validateSection(string $section)
176158
{
177-
if (!$this->supports($section)) {
178-
throw new Exception(sprintf('%s is an unknown Public Suffix List section', $section));
159+
if (self::ALL_DOMAINS === $section) {
160+
return;
179161
}
162+
163+
$rules = $this->rules[$section] ?? null;
164+
if (null !== $rules && is_array($rules)) {
165+
return;
166+
}
167+
168+
throw new Exception(sprintf('%s is an unknown Public Suffix List section', $section));
180169
}
181170

182171
/**

0 commit comments

Comments
 (0)