Skip to content

Commit 91d24af

Browse files
committed
improve documentation
1 parent c5a5197 commit 91d24af

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

README.md

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ In order to resolve a domain name one we must:
5252
- Convert the Public Suffix List (PSL) into a structure usable in PHP
5353
- Resolve the domain name against the PSL rules
5454

55-
Conversion is done using the `Pdp\Converter` class.
55+
PSL Conversion is done using the `Pdp\Converter` class.
5656

5757
~~~php
5858
<?php
@@ -67,7 +67,7 @@ final class Converter
6767

6868
The `Pdp\Converter::convert` method expects the raw content of a PSL and returns its `array` representation.
6969

70-
Once the PSL has been converted we can feed its data to a `Pdp\Rules` object which is responsable for resolving a given domain name against its rules.
70+
Once the PSL has been converted we can used the returned `array` to instantiate a `Pdp\Rules` object which is responsable for resolving a given domain name.
7171

7272
~~~php
7373
<?php
@@ -85,20 +85,18 @@ final class Rules
8585
}
8686
~~~
8787

88-
The `Rules` constructor expects the result of the PSL conversion by the `Pdp\Converter` class.
88+
Domain name resolution is done using the `Pdp\Rules::resolve` method which expects at most two parameters:
8989

90-
Domain name resolution is done using the `Rules::resolve`. The method expects
90+
- `$domain` a valid domain name as a string
91+
- `$type` a string to optionnally specify which section of the PSL you want to validate the given domain against. The possible values are:
92+
- `Rules::ALL_DOMAINS`, to validate against the full PSL.
93+
- `Rules::ICANN_DOMAINS`, to validate against the PSL ICANN section only.
94+
- `Rules::PRIVATE_DOMAINS`, to validate against the PSL PRIVATE section only.
9195

92-
- a valid domain name as a string
93-
- a string to optionnally specify which section of the PSL you want to validate the given domain against. The possible values are:
94-
- `Rules::ALL_DOMAINS`, will validate the domain name against the full PSL.
95-
- `Rules::ICANN_DOMAINS`, will validate the domain name againts the PSL ICANN section only.
96-
- `Rules::PRIVATE_DOMAINS`, will validate the domain name againts the PSL PRIVATE section only.
96+
By default, the `$type` argument is equal to `Rules::ALL_DOMAINS`. If an unrecognized section is submitted otherwise, a `Pdp\Exception` exception will be thrown.
9797

98-
By default, the `$type` argument equals `Rules::ALL_DOMAINS`. If an unrecognized section is submitted otherwise, a `Pdp\Exception` exception will be thrown.
9998

100-
101-
`Rules::resolve` returns a `Domain` object.
99+
The `Pdp\Rules::resolve` returns a `Pdp\Domain` object.
102100

103101
~~~php
104102
<?php
@@ -115,22 +113,22 @@ final class Domain implements JsonSerializable
115113
}
116114
~~~
117115

118-
The `Domain` getter methods returns:
116+
The `Pdp\Domain` getter methods returns:
119117

120-
- the submitted domain name using `Domain::getDomain`
121-
- the public suffix part normalized according to the domain using `Domain::getPublicSuffix`
122-
- the registrable domain part using `Domain::getRegistrableDomain`
123-
- the subdomain part usung `Domain::getSubDomain`.
118+
- the submitted domain name using `Pdp\Domain::getDomain`
119+
- the public suffix part normalized according to the domain using `Pdp\Domain::getPublicSuffix`
120+
- the registrable domain part using `Pdp\Domain::getRegistrableDomain`
121+
- the subdomain part usung `Pdp\Domain::getSubDomain`.
124122

125-
If the domain name of some of its part are seriously malformed or unrecognized, the getter methods will return `null`.
123+
If the domain name or some of its part are seriously malformed or unrecognized, the getter methods will return `null`.
126124

127125
**The Domain name public status status depends on the PSL section used to resolve them:**
128126

129-
- `Domain::isICANN` returns `true` if the domain name resolution is done against a PSL which includes the ICANN DOMAINS section and its public suffix is found in it;
130-
- `Domain::isPrivate` returns `true` if the domain name resolution is done against a PSL which includes the PRIVATE DOMAINS section and its public suffix is found in it;
131-
- `Domain::isKnown` returns `true` if the public suffix is found in the selected PSL
127+
- `Pdp\Domain::isKnown` returns `true` if the public suffix is found in the selected PSL
128+
- `Pdp\Domain::isICANN` returns `true` if the domain name resolution is done against a PSL which includes the ICANN DOMAINS section and its public suffix is found in it;
129+
- `Pdp\Domain::isPrivate` returns `true` if the domain name resolution is done against a PSL which includes the PRIVATE DOMAINS section and its public suffix is found in it;
132130

133-
**THIS EXAMPLE ILLUSTRATE 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 PRODUCTIVE ENVIRONMENT**
134132

135133
~~~php
136134
<?php
@@ -162,7 +160,7 @@ echo json_encode($domain, JSON_PRETTY_PRINT);
162160
// "isPrivate": false
163161
// }
164162

165-
//The same domain will yield a different result using the PRIVATE DOMAIN SECTION only
163+
//The same domain will yield a different result using the PSL PRIVATE DOMAIN SECTION only
166164

167165
$domain = $rules->resolve('www.ulb.ac.be', Rules::PRIVATE_DOMAINS);
168166
echo json_encode($domain, JSON_PRETTY_PRINT);
@@ -180,13 +178,13 @@ echo json_encode($domain, JSON_PRETTY_PRINT);
180178

181179
**WARNING:**
182180

183-
**Yous should never user the library this way in a productive application, without at least a caching mechanism to load the PSL.**
181+
**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.**
184182

185183
**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.**
186184

187185
### Public Suffix List Maintenance
188186

189-
Since **directly fetching the PSL without caching the result is not recommend**, the library comes bundle with a `Pdp\Manager` class. This class is a service which enables resolving domain name without the constant network overhead of continously downloading the PSL. The 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+
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.
190188

191189
~~~php
192190
<?php
@@ -238,7 +236,7 @@ By default and out of the box, the package uses:
238236
- 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**.
239237
- a HTTP client based on the cURL extension.
240238

241-
#### Accessing the Public Suffix List rules
239+
#### Returning a `Pdp\Rules` object
242240

243241
~~~php
244242
<?php
@@ -293,27 +291,27 @@ use Pdp\CurlHttpClient;
293291
use Pdp\Manager;
294292

295293
$manager = new Manager(new Cache(), new CurlHttpClient());
296-
$res = $manager->refreshRules('https://publicsuffix.org/list/public_suffix_list.dat');
297-
if ($res === true) {
294+
$retval = $manager->refreshRules('https://publicsuffix.org/list/public_suffix_list.dat');
295+
if ($retval) {
298296
//the local cache has been updated
299297
} else {
300298
//the local cache has not been updated
301299
}
302300
~~~
303301

304-
## Automatic Updates
302+
### Automatic Updates
305303

306304
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.
307305

308306
~~~bash
309307
$ php ./bin/update-psl
310308
~~~
311309

312-
This script requires that:
310+
This script requires:
313311

314-
- the PHP `curl` extension
312+
- The PHP `curl` extension
315313
- The `Pdp\Installer` class which comes bundle with this package
316-
- The use of the Cache and HTTP Client implementations bundle with the package.
314+
- The use of the Cache and HTTP Client implementations bundle with this package.
317315

318316
If you prefer using your own implementations you should:
319317

@@ -376,8 +374,6 @@ $domain->getSubDomain(); //returns 'nl.shop'
376374
$domain->isKnown(); //returns false
377375
~~~
378376

379-
In any case, you should setup a reccurent job to regularly update your local cache.
380-
381377
Contributing
382378
-------
383379

0 commit comments

Comments
 (0)