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
-`Pdp\IDNAConverterTrait` throws a `UnexpectedValueException` if the Intl extension is misconfigured see [#230](https://github.com/jeremykendall/php-domain-parser/issues/230)
@@ -20,7 +20,7 @@ Consider the domain www.pref.okinawa.jp. In this domain, the
20
20
*public suffix* portion is **okinawa.jp**, the *registrable domain* is
21
21
**pref.okinawa.jp**, and the *subdomain* is **www**. You can't regex that.
22
22
23
-
PHP Domain Parser is built around accurate Public Suffix List based parsing. For URL parsing, building or manipulation please refer to [libraries](https://packagist.org/packages/sabre/uri?q=uri%20rfc3986&p=0) focused on those area of development.
23
+
PHP Domain Parser is built around accurate Public Suffix List based parsing. For URL parsing, building or manipulation please refer to [libraries][link-parse-library] focused on those area of development.
**Using the PSL to determine what is a valid domain name and what isn't is dangerous, particularly in these days where new gTLDs are arriving at a rapid pace. The DNS is the proper source for this information. If you must use this library for this purpose, please consider integrating a PSL update mechanism into your software.**
288
295
289
-
### Managing the Public Suffix List
296
+
### Top Level Domains resolutions
297
+
298
+
**since version 5.4**
299
+
300
+
~~~php
301
+
<?php
302
+
303
+
namespace Pdp;
304
+
305
+
final class TopLevelDomains implements Countable, IteratorAggregate
306
+
{
307
+
public static function createFromPath(string $path, $context = null): Rules
308
+
public static function createFromString(string $content): Rules
309
+
public function __construct(array $records, string $version, DateTimeInterface $modifiedDate)
310
+
public function resolve($domain): Domain
311
+
public function contains($domain): bool
312
+
public function isEmpty(): bool
313
+
}
314
+
~~~
315
+
316
+
The `Pdp\TopLevelDomains` object is responsible for top level domain resolution for a given domain. The resolution is done using a resource which should follow [IANA resource file](https://data.iana.org/TLD/tlds-alpha-by-domain.txt). The class is a collection which contains the list of all top levels domain as registered on the IANA servers.
317
+
318
+
**THIS EXAMPLE ILLUSTRATES HOW THE OBJECT WORK BUT SHOULD BE AVOIDED IN PRODUCTON**
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.
292
342
@@ -300,9 +350,13 @@ use Psr\SimpleCache\CacheInterface;
public function __construct(CacheInterface $cache, HttpClient $http, $ttl = null)
356
+
public function getRules(string $source_url = self::PSL_URL, $ttl = null): Rules
357
+
public function refreshRules(string $source_url = self::PSL_URL, $ttl = null): bool
358
+
public function getTLDs(string $source_url = self::RZD_URL, $ttl = null): Rules
359
+
public function refreshTLDs(string $source_url = self::RZD_URL, $ttl = null): bool
306
360
}
307
361
~~~
308
362
@@ -311,8 +365,17 @@ final class Manager
311
365
To work as intended, the `Pdp\Manager` constructor requires:
312
366
313
367
- a [PSR-16](http://www.php-fig.org/psr/psr-16/) Cache object to store the rules locally.
314
-
315
368
- a `Pdp\HttpClient` object to retrieve the PSL.
369
+
- a `$ttl` argument if you need to set the default $ttl; **since 5.4**
370
+
371
+
The `$ttl` argument can be:
372
+
373
+
- an `int` representing time in second (see PSR-16);
374
+
- a `DateInterval` object (see PSR-16);
375
+
- a `DateTimeInterface` object representing the date and time when the item should expire;
376
+
377
+
**the `$ttl` argument is added to improve PSR-16 interoperability**
378
+
316
379
317
380
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.
318
381
If an error occurs while retrieving such body a `HttpClientException` exception is thrown.
@@ -342,15 +405,16 @@ The package comes bundle with:
342
405
- 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**.
343
406
- a HTTP client based on the cURL extension.
344
407
345
-
#### Refreshing the cached PSL
408
+
#### Refreshing the cached PSL and TLD data
346
409
347
410
~~~php
348
411
<?php
349
412
350
-
public Manager::refreshRules(string $source_url = self::PSL_URL): bool
413
+
public Manager::refreshRules(string $source_url = self::PSL_URL, $ttl = null): bool
414
+
public Manager::refreshTLD(string $source_url = self::RZD_URL, $ttl = null): bool
351
415
~~~
352
416
353
-
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.
417
+
The both methods method enables refreshing your local copy of the stored resources 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 resource default source URL but you are free to substitute this URL with your own.
354
418
The method returns a boolean value which is `true` on success.
public Manager::getRules(string $source_url = self::PSL_URL): Rules
435
+
public Manager::getRules(string $source_url = self::PSL_URL, $ttl = null): Rules
436
+
public Manager::getTLDs(string $source_url = self::RZD_URL, $ttl = null): TopLevelDomains
372
437
~~~
373
438
374
-
This method returns a `Rules`object which is instantiated with the PSL rules.
439
+
These methods returns a `Pdp\Rules`or `Pdp\TopLevelDomains` objects seeded with their corresponding data fetch from the cache or from the external resources depending on the submitted `$ttl` argument.
375
440
376
-
The method takes an optional `$source_url` argument which specifies the PSL source URL. If no local cache exists for the submitted source URL, the method will:
441
+
These methods take an optional `$source_url` argument which specifies the PSL source URL. If no local cache exists for the submitted source URL, the method will:
377
442
378
-
1. call `Manager::refreshRules` with the given URL to update its local cache
379
-
2. instantiate the `Rules`object with the newly cached data.
443
+
1. call `Manager::refreshRules` with the given URL and `$ttl` argument to update its local cache
444
+
2. instantiate the `Rules`or the `TopLevelDomains` objects with the newly cached data.
380
445
381
-
On error, the method throws an `Pdp\Exception`.
446
+
On error, theses methods will throw an `Pdp\Exception`.
382
447
383
448
**THIS IS THE RECOMMENDED WAY OF USING THE LIBRARY**
384
449
385
450
~~~php
386
451
<?php
387
452
388
453
$manager = new Pdp\Manager(new Pdp\Cache(), new Pdp\CurlHttpClient());
0 commit comments