Skip to content

Commit 74b9293

Browse files
committed
Update documentation for 5.5 release
1 parent f81bfe9 commit 74b9293

File tree

2 files changed

+83
-16
lines changed

2 files changed

+83
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ All Notable changes to `PHP Domain Parser` **5.x** series will be documented in
66

77
### Added
88

9-
- Support for `IDNA_OPTIONS` settings in all the classes see [#236](https://github.com/jeremykendall/php-domain-parser/pull/236) thanks to [Insolita](https://github.com/Insolita)
9+
- Support for IDNA options see [#236](https://github.com/jeremykendall/php-domain-parser/pull/236) thanks to [Insolita](https://github.com/Insolita).
10+
1011
- `PublicSuffix::labels` and `Domain::labels` to return the VO labels see [#241](https://github.com/jeremykendall/php-domain-parser/pull/241)
1112

1213
### Fixed

README.md

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,33 @@ foreach($tldList as $tld) {
8989

9090
Using the above code you have parse, validate and resolve a domain name and its public suffix status against the Public Suffix list.
9191

92+
**Starting with vesion 5.5 support for IDNA options is added to the package**
93+
94+
**Before**
95+
96+
~~~php
97+
$manager = new Manager(new Cache(), new CurlHttpClient());
98+
$rules = $manager->getRules();
99+
100+
$domain = $rules->resolve('faß.test.de');
101+
echo $domain->toAscii()->getContent(); // 'fass.test.de'
102+
~~~
103+
104+
**After**
105+
106+
~~~php
107+
$manager = new Manager(new Cache(), new CurlHttpClient());
108+
$rules = $manager->getRules(Manager::PSL_URL, null, IDNA_NONTRANSITIONAL_TO_ASCII,
109+
IDNA_NONTRANSITIONAL_TO_UNICODE);
110+
// or
111+
// $rules = $rules
112+
// ->withAsciiIDNAOption(IDNA_NONTRANSITIONAL_TO_ASCII)
113+
// ->withUnicodeIDNAOption(IDNA_NONTRANSITIONAL_TO_UNICODE);
114+
115+
$domain = $rules->resolve('faß.test.de');
116+
echo $domain->toAscii()->getContent(); // 'xn--fa-hia.test.de'
117+
~~~
118+
92119
Documentation
93120
--------
94121

@@ -135,6 +162,8 @@ public function Domain::append($label): Domain
135162
public function Domain::prepend($label): Domain
136163
public function Domain::withPublicSuffix($publicSuffix): Domain
137164
public function Domain::withSubDomain($subDomain): Domain
165+
public function Domain::withAsciiIDNAOption(int $option): Domain
166+
public function Domain::withUnicodeIDNAOption(int $option): Domain
138167
~~~
139168

140169
~~~php
@@ -162,7 +191,6 @@ Because the `Pdp\Domain` object is immutable:
162191

163192
**WARNING: URI and URL accept registered name which encompass domain name. Therefore, some URI host are invalid domain name and will trigger an exception if you try to instantiate a `Pdp\Domain` with them.**
164193

165-
166194
The `Pdp\Domain` object can tell whether a public suffix can be attached to it using the `Pdp\Domain::isResolvable` method.
167195

168196
~~~php
@@ -222,11 +250,27 @@ namespace Pdp;
222250

223251
final class Rules
224252
{
225-
public static function createFromPath(string $path, $context = null): Rules
226-
public static function createFromString(string $content): Rules
227-
public function __construct(array $rules)
253+
public static function createFromPath(
254+
string $path, $context = null,
255+
int $asciiIDNAOption = IDNA_DEFAULT,
256+
int $unicodeIDNAOption = IDNA_DEFAULT
257+
): Rules
258+
public static function createFromString(
259+
string $content,
260+
int $asciiIDNAOption = IDNA_DEFAULT,
261+
int $unicodeIDNAOption = IDNA_DEFAULT
262+
): Rules
263+
public function __construct(
264+
array $rules,
265+
int $asciiIDNAOption = IDNA_DEFAULT,
266+
int $unicodeIDNAOption = IDNA_DEFAULT
267+
): void
228268
public function resolve($domain, string $section = ''): Domain
229269
public function getPublicSuffix($domain, string $section = ''): PublicSuffix
270+
public function getAsciiIDNAOption(): int
271+
public function getUnicodeIDNAOption(): int
272+
public function withAsciiIDNAOption(int $asciiIDNAOption): Rules
273+
public function withUnicodeIDNAOption(int $unicodeIDNAOption): Rules
230274
}
231275
~~~
232276

@@ -304,12 +348,16 @@ namespace Pdp;
304348

305349
final class TopLevelDomains implements Countable, IteratorAggregate
306350
{
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)
351+
public static function createFromPath(string $path, $context = null, int $asciiIDNAOption = IDNA_DEFAULT, int $unicodeIDNAOption = IDNA_DEFAULT): Rules
352+
public static function createFromString(string $content, int $asciiIDNAOption = IDNA_DEFAULT, int $unicodeIDNAOption = IDNA_DEFAULT): Rules
353+
public function __construct(array $records, string $version, DateTimeInterface $modifiedDate, int $asciiIDNAOption = IDNA_DEFAULT, int $unicodeIDNAOption = IDNA_DEFAULT)
310354
public function resolve($domain): Domain
311355
public function contains($domain): bool
312356
public function isEmpty(): bool
357+
public function getAsciiIDNAOption(): int
358+
public function getUnicodeIDNAOption(): int
359+
public function withAsciiIDNAOption(int $option): TopLevelDomains
360+
public function withUnicodeIDNAOption(int $option): TopLevelDomains
313361
}
314362
~~~
315363

@@ -353,10 +401,6 @@ final class Manager
353401
const RZD_URL = 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt';
354402

355403
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
360404
}
361405
~~~
362406

@@ -376,7 +420,6 @@ The `$ttl` argument can be:
376420

377421
**the `$ttl` argument is added to improve PSR-16 interoperability**
378422

379-
380423
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.
381424
If an error occurs while retrieving such body a `HttpClientException` exception is thrown.
382425

@@ -414,7 +457,8 @@ public Manager::refreshRules(string $source_url = self::PSL_URL, $ttl = null): b
414457
public Manager::refreshTLD(string $source_url = self::RZD_URL, $ttl = null): bool
415458
~~~
416459

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.
460+
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.
461+
418462
The method returns a boolean value which is `true` on success.
419463

420464
~~~php
@@ -432,8 +476,19 @@ if ($retval) {
432476
~~~php
433477
<?php
434478

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
479+
public Manager::getRules(
480+
string $source_url = self::PSL_URL,
481+
$ttl = null,
482+
int $asciiIDNAOption = IDNA_DEFAULT,
483+
int $unicodeIDNAOption = IDNA_DEFAULT
484+
): Rules
485+
486+
public Manager::getTLDs(
487+
string $source_url = self::RZD_URL,
488+
$ttl = null,
489+
int $asciiIDNAOption = IDNA_DEFAULT,
490+
int $unicodeIDNAOption = IDNA_DEFAULT
491+
): TopLevelDomains
437492
~~~
438493

439494
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.
@@ -445,6 +500,17 @@ These methods take an optional `$source_url` argument which specifies the PSL so
445500

446501
On error, theses methods will throw an `Pdp\Exception`.
447502

503+
**since 5.5***
504+
505+
the following optional arguments are added to the methods:
506+
507+
- `$asciiIDNAOption` optional IDNA option for ascii conversion;
508+
- `$asciiIDNAOption` optional IDNA option for unicode conversion;
509+
510+
**theses arguments are a combination of `IDNA_*` constants (except `IDNA_ERROR_*` constants).**
511+
512+
They are used when instantiated the returned object.
513+
448514
**THIS IS THE RECOMMENDED WAY OF USING THE LIBRARY**
449515

450516
~~~php

0 commit comments

Comments
 (0)