You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To resolve the submitted domain name we must first convert the Public Suffix List into a structure consommable by the library. This is done using the `Pdp\Converter` class which converts the list into an `array` representation that can be then used by the `Pdp\Rules` object.
public function resolve(string $domain = null, string $type = self::ALL_DOMAINS): Domain
89
+
}
90
+
~~~
91
+
92
+
The `Rules` constructor expects a `array` representation of the Public Suffix List. This `array` representation is constructed using the `Pdp\Converter` class.
93
+
94
+
The `Rules` class resolves the submitted domain against the parsed rules from the PSL. This is done using the `Rules::resolve` method which returns a `Pdp\Domain` object. The method expects
95
+
96
+
- a valid domain name as a string
97
+
- a string to optionnally specify which section of the PSL you want to validate the given domain against.
98
+
By default all sections are used `Rules::ALL_DOMAINS` but you can validate your domain against the ICANN only section (`Rules::ICANN_DOMAINS` or the private section (`Rules::PRIVATE_DOMAINS`) of the PSL.
99
+
100
+
~~~php
101
+
<?php
102
+
103
+
final class Domain implements JsonSerializable
104
+
{
105
+
public function getDomain(): ?string
106
+
public function getPublicSuffix(): ?string
107
+
public function getRegistrableDomain(): ?string
108
+
public function getSubDomain(); ?string
109
+
public function isKnown(): bool;
110
+
public function isICANN(): bool;
111
+
public function isPrivate(): bool;
112
+
}
113
+
~~~
114
+
115
+
The `Domain` getters method always return normalized value according to the domain status against the PSL rules.
116
+
117
+
<pclass="message-notice"><code>Domain::isKnown</code> status depends on the PSL rules used. For the same domain, depending on the rules used a domain public suffix may be known or not.</p>
<pclass="message-warning"><strong>Warning:</strong> Some people use the PSL to determine what is a valid domain name and what isn't. This is dangerous, particularly in these days where new gTLDs are arriving at a rapid pace, if your software does not regularly receive PSL updates, it may erroneously think new gTLDs are not known. The DNS is the proper source for this information. If you must use it for this purpose, please do not bake static copies of the PSL into your software with no update mechanism.</p>
162
+
47
163
### Public Suffix List Maintenance
48
164
165
+
**Directly fetching the Public Suffix List without caching the result is not recommend** . For that reason, the package comes bundle with a `Pdp\Manager` class which retrieves, convert and cache the Public Suffix List for you.
166
+
167
+
49
168
~~~php
50
169
<?php
51
170
@@ -62,8 +181,6 @@ final class Manager
62
181
}
63
182
~~~
64
183
65
-
This class obtains, parses, caches, and returns a PHP representation of the PSL rules.
66
-
67
184
#### Creating a new manager
68
185
69
186
To work as intended, the `Manager` constructor requires:
@@ -73,6 +190,8 @@ To work as intended, the `Manager` constructor requires:
73
190
- a `HttpClient` interface which exposes the `HttpClient::getContent` method which expects a string URL representation has its sole argument and returns the body from the given URL resource as a string.
74
191
If an error occurs while retrieving such body a `HttpClientException` is thrown.
75
192
193
+
**Of note:** the class also uses internally a `Pdp\Converter` object to convert the fetched PSL into its `array` representation when required.
In any case, you should setup a cron to regularly update your local cache.
225
-
226
-
227
-
### Domain Resolution
228
-
229
-
~~~php
230
-
<?php
231
-
232
-
namespace Pdp;
233
-
234
-
final class Rules
235
-
{
236
-
const ALL_DOMAINS = 'ALL_DOMAINS';
237
-
const ICANN_DOMAINS = 'ICANN_DOMAINS';
238
-
const PRIVATE_DOMAINS = 'PRIVATE_DOMAINS';
239
-
240
-
public function __construct(array $rules)
241
-
public function resolve(string $domain = null, string $type = self::ALL_DOMAINS): Domain
242
-
}
243
-
~~~
244
-
245
-
The `Rules` constructor expects a `array` representation of the Public Suffix List. This `array` representation is constructed by the `Manager` and stored using a PSR-16 compliant cache.
246
-
247
-
The `Rules` class resolves the submitted domain against the parsed rules from the PSL. This is done using the `Rules::resolve` method which returns a `Pdp\Domain` object. The method expects
248
-
249
-
- a valid domain name as a string
250
-
- a string to optionnally specify which section of the PSL you want to validate the given domain against.
251
-
By default all sections are used `Rules::ALL_DOMAINS` but you can validate your domain against the ICANN only section (`Rules::ICANN_DOMAINS` or the private section (`Rules::PRIVATE_DOMAINS`) of the PSL.
252
-
253
-
~~~php
254
-
<?php
255
-
256
-
final class Domain implements JsonSerializable
257
-
{
258
-
public function getDomain(): ?string
259
-
public function getPublicSuffix(): ?string
260
-
public function getRegistrableDomain(): ?string
261
-
public function getSubDomain(); ?string
262
-
public function isKnown(): bool;
263
-
public function isICANN(): bool;
264
-
public function isPrivate(): bool;
265
-
}
266
-
~~~
267
-
268
-
The `Domain` getters method always return normalized value according to the domain status against the PSL rules.
269
-
270
-
<pclass="message-notice"><code>Domain::isKnown</code> status depends on the PSL rules used. For the same domain, depending on the rules used a domain public suffix may be known or not.</p>
271
-
272
-
~~~php
273
-
<?php
274
-
275
-
use Pdp\Cache;
276
-
use Pdp\CurlHttpClient;
277
-
use Pdp\Domain;
278
-
use Pdp\Manager;
279
-
280
-
$manager = new Manager(new Cache(), new CurlHttpClient());
<pclass="message-warning"><strong>Warning:</strong> Some people use the PSL to determine what is a valid domain name and what isn't. This is dangerous, particularly in these days where new gTLDs are arriving at a rapid pace, if your software does not regularly receive PSL updates, it may erroneously think new gTLDs are not known. The DNS is the proper source for this information. If you must use it for this purpose, please do not bake static copies of the PSL into your software with no update mechanism.</p>
343
+
In any case, you should setup a reccurent job to regularly update your local cache.
0 commit comments