Skip to content

Commit 68b6461

Browse files
committed
improve documentation
1 parent bd920e9 commit 68b6461

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

README.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ $ composer require jeremykendall/php-domain-parser
4444
Documentation
4545
--------
4646

47-
### Public Suffix List conversion
47+
### Domain name resolution
48+
49+
50+
In order to resolve a domain name we must:
51+
52+
- Convert the Public Suffix List into a structure usable in PHP
53+
- Resolve the domain against the given PSL rules
54+
55+
Conversion is done using the `Pdp\Converter` class.
4856

4957
~~~php
5058
<?php
@@ -57,21 +65,19 @@ final class Converter
5765
}
5866
~~~
5967

60-
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.
68+
The `Pdp\Converter::convert` method expect the raw content of a public suffix list and returns its `array` representation.
6169

6270
~~~php
6371
<?php
6472

6573
use Pdp\Converter;
66-
use Pdp\Rules;
6774

6875
$content = file_get_contents('https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat');
6976
$converter = new Converter();
7077
$arr_rules = $converter->convert($raw);
71-
$rules = new Rules($arr_rules);
7278
~~~
7379

74-
### Domain name resolution
80+
Once the PSL has been converted we can feed its data to a `Pdp\Rules` object which is responsible for resolving a given domain name against the PSL rules.
7581

7682
~~~php
7783
<?php
@@ -91,11 +97,17 @@ final class Rules
9197

9298
The `Rules` constructor expects a `array` representation of the Public Suffix List. This `array` representation is constructed using the `Pdp\Converter` class.
9399

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
100+
Domain name resolution is done using the `Rules::resolve` method which returns a `Pdp\Domain` object. The method expects
95101

96102
- 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.
103+
- a string to optionnally specify which section of the PSL you want to validate the given domain against. The possible values are:
104+
- `Rules::ALL_DOMAINS`, will validate the domain name against the full PSL.
105+
- `Rules::ICANN_DOMAINS`, will validate the domain name againts the PSL ICANN section only.
106+
- `Rules::PRIVATE_DOMAINS`, will validate the domain name againts the PSL PRIVATE section only.
107+
108+
By default, the full PSL is used.
109+
110+
An exception will be thrown if an undefined section is submitted otherwise, a `Pdp\Domain` object is returned.
99111

100112
~~~php
101113
<?php
@@ -114,7 +126,8 @@ final class Domain implements JsonSerializable
114126

115127
The `Domain` getters method always return normalized value according to the domain status against the PSL rules.
116128

117-
<p class="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>
129+
**Warning:** `Domain::isKnown`, `Domain::isICANN` status depends on the PSL rules used.
130+
For the same domain, depending on the rules used a domain public suffix status may be known or not, may be ICANN or not.
118131

119132
~~~php
120133
<?php
@@ -126,7 +139,7 @@ $content = file_get_contents('https://raw.githubusercontent.com/publicsuffix/lis
126139
$arr = (new Converter())->convert($raw);
127140
$rules = new Rules($arr);
128141

129-
$domain = $rules->resolve('www.ulb.ac.be');
142+
$domain = $rules->resolve('www.ulb.ac.be'); //using Rules::ALL_DOMAINS
130143
$domain->getDomain(); //returns 'www.ulb.ac.be'
131144
$domain->getPublicSuffix(); //returns 'ac.be'
132145
$domain->getRegistrableDomain(); //returns 'ulb.ac.be'
@@ -158,12 +171,11 @@ $domain->isICANN(); //returns false
158171
$domain->isPrivate(); //returns false
159172
~~~
160173

161-
<p class="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>
174+
**Warning:** 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.
162175

163176
### Public Suffix List Maintenance
164177

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-
178+
**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, converts and caches the Public Suffix List for you as well as create a `Pdp\Rules` object on demand.
167179

168180
~~~php
169181
<?php
@@ -212,8 +224,6 @@ interface HttpClient
212224
}
213225
~~~
214226

215-
For advance usages you are free to use your own cache and/or http implementation.
216-
217227
By default and out of the box, the package uses:
218228

219229
- 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**.
@@ -283,7 +293,6 @@ If you prefer using your own implementations you should:
283293
1. Copy the `Pdp\Installer` class
284294
2. Adapt its code to reflect your requirements.
285295

286-
287296
In any cases your are required to update regularly your PSL information with your chosen script to keep your data up to date.
288297

289298
For example, below I'm using the `Manager` with

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
},
4646
"suggest": {
4747
"psr/simple-cache-implementation": "To enable using other cache providers",
48-
"ext-curl": "To use the package http client"
48+
"ext-curl": "To use the package http client",
49+
"league/uri-parser": "To parse URL and validate host"
4950
},
5051
"autoload": {
5152
"psr-4": {

0 commit comments

Comments
 (0)