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
Copy file name to clipboardExpand all lines: README.md
+36-35Lines changed: 36 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,19 +81,19 @@ final class Rules
81
81
const PRIVATE_DOMAINS = 'PRIVATE_DOMAINS';
82
82
83
83
public function __construct(array $rules)
84
-
public function resolve(string $domain = null, string $type = self::ALL_DOMAINS): Domain
84
+
public function resolve(string $domain = null, string $section = self::ALL_DOMAINS): Domain
85
85
}
86
86
~~~
87
87
88
88
Domain name resolution is done using the `Pdp\Rules::resolve` method which expects at most two parameters:
89
89
90
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:
91
+
-`$section` a string which specifies which section of the PSL you want to validate the given domain against. The possible values are:
92
92
-`Rules::ALL_DOMAINS`, to validate against the full PSL.
93
93
-`Rules::ICANN_DOMAINS`, to validate against the PSL ICANN DOMAINS section only.
94
94
-`Rules::PRIVATE_DOMAINS`, to validate against the PSL PRIVATE DOMAINS section only.
95
95
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.
96
+
By default, the `$section` argument is equal to `Rules::ALL_DOMAINS`. If an unsupported section is submitted a `Pdp\Exception` exception will be thrown.
97
97
98
98
99
99
The `Pdp\Rules::resolve` returns a `Pdp\Domain` object.
@@ -128,7 +128,7 @@ If the domain name or some of its part are seriously malformed or unrecognized,
128
128
-`Pdp\Domain::isICANN` returns `true` if the public suffix is found in a selected PSL which includes the ICANN DOMAINS section;
129
129
-`Pdp\Domain::isPrivate` returns `true` if the public suffix is found in a selected PSL which includes the PRIVATE DOMAINS section;
130
130
131
-
**THIS EXAMPLE ILLUSTRATES HOW EACH OBJECT IS USED BUT SHOULD BE AVOID IN A PRODUCTIVE ENVIRONMENT**
131
+
**THIS EXAMPLE ILLUSTRATES HOW EACH OBJECT IS USED BUT SHOULD BE AVOID IN A PRODUCTON**
**As already stated, you should never user the library this way in a productive application, without at least a caching mechanism to load the PSL.**
181
+
**You should never use the library this way in production, without, at least, a caching mechanism to reduce PSL downloads.**
182
182
183
183
**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.**
184
184
185
185
### Public Suffix List Maintenance
186
186
187
-
Since **directly fetching the PSL without caching the result is not recommend**, the library comes bundle with a service which enables resolving domain name without the constant network overhead of continously downloading the PSL. The `Pdp\Manager` class retrieves, converts and caches the PSL as well as creates the corresponding `Pdp\Rules` object on demand. It internally uses a `Pdp\Converter` object to convert the fetched PSL into its `array` representation when required.
187
+
The library comes bundle with a service which enables resolving domain name without the constant network overhead of continously downloading the PSL. The `Pdp\Manager` class retrieves, converts and caches the PSL as well as creates the corresponding `Pdp\Rules` object on demand. It internally uses a `Pdp\Converter` object to convert the fetched PSL into its `array` representation when required.
188
188
189
189
~~~php
190
190
<?php
@@ -202,14 +202,15 @@ final class Manager
202
202
}
203
203
~~~
204
204
205
-
#### Creating a new manager
205
+
#### Instantiate `Pdp\Manager`
206
206
207
-
To work as intended, the `Manager` constructor requires:
207
+
To work as intended, the `Pdp\Manager` constructor requires:
208
208
209
-
- a [PSR-16](http://www.php-fig.org/psr/psr-16/) Cache object to store the retrieved rules using a basic HTTP client.
209
+
- a [PSR-16](http://www.php-fig.org/psr/psr-16/) Cache object to store the rules locally.
210
210
211
-
- 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.
212
-
If an error occurs while retrieving such body a `HttpClientException` is thrown.
211
+
- a `Pdp\HttpClient` object to retrieve the PSL.
212
+
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.
213
+
If an error occurs while retrieving such body a `HttpClientException` exception is thrown.
213
214
214
215
~~~php
215
216
<?php
@@ -231,11 +232,32 @@ interface HttpClient
231
232
}
232
233
~~~
233
234
234
-
By default and out of the box, the package uses:
235
+
The package comes bundle with:
235
236
236
237
- a file cache PSR-16 implementation based on the excellent [FileCache](https://github.com/kodus/file-cache) which **caches the local copy for a maximum of 7 days**.
237
238
- a HTTP client based on the cURL extension.
238
239
240
+
#### Refreshing the cached PSL
241
+
242
+
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.
243
+
The method returns a boolean value which is `true` on success.
244
+
245
+
~~~php
246
+
<?php
247
+
248
+
use Pdp\Cache;
249
+
use Pdp\CurlHttpClient;
250
+
use Pdp\Manager;
251
+
252
+
$manager = new Manager(new Cache(), new CurlHttpClient());
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.
284
-
The method returns a boolean value which is `true` on success.
285
-
286
-
~~~php
287
-
<?php
288
-
289
-
use Pdp\Cache;
290
-
use Pdp\CurlHttpClient;
291
-
use Pdp\Manager;
292
-
293
-
$manager = new Manager(new Cache(), new CurlHttpClient());
It is important to always have an up to date PSL. In order to do so the library comes bundle with an auto-update script located in the `bin` directory.
@@ -310,8 +311,8 @@ $ php ./bin/update-psl
310
311
This script requires:
311
312
312
313
- The PHP `curl` extension
313
-
- The `Pdp\Installer` class which comes bundle with this package
314
-
- The use of the Cache and HTTP Client implementations bundle with this package.
314
+
- The `Pdp\Installer` class which organizes how to update the cache.
315
+
- The `Pdp\Cache` and `Pdp\CurlHttpClient` classes to retrieve and cache the PSL
315
316
316
317
If you prefer using your own implementations you should:
0 commit comments