Skip to content

Commit f3f4275

Browse files
committed
documentation simplification
1 parent 40135b7 commit f3f4275

File tree

1 file changed

+26
-44
lines changed

1 file changed

+26
-44
lines changed

README.md

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,7 @@ Documentation
4848

4949
### Domain name resolution
5050

51-
In order to resolve a domain name one we must:
52-
53-
- Convert the Public Suffix List (PSL) into a structure usable in PHP
54-
- Resolve the domain name against the PSL rules
55-
56-
PSL Conversion is done using the `Pdp\Converter` class.
57-
58-
~~~php
59-
<?php
60-
61-
namespace Pdp;
62-
63-
final class Converter
64-
{
65-
public function convert(string $content): array
66-
}
67-
~~~
68-
69-
The `Pdp\Converter::convert` method expects the raw content of a PSL and returns its `array` representation.
70-
71-
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.
51+
The `Pdp\Rules` object is responsible for domain name resolution.
7252

7353
~~~php
7454
<?php
@@ -88,17 +68,17 @@ final class Rules
8868
}
8969
~~~
9070

91-
Starting with version 5.1.0, the following named constructors arre added to ease `Rules` instantiation.
71+
**NEW IN VERSION 5.1:**
9272

9373
- `Rules::createFromString` expects a string content which follows [the PSL format](https://publicsuffix.org/list/#list-format);
94-
9574
- `Rules::createFromPath` expects a valid path to a readable PSL. You can optionnally submit a context resource as defined in PHP's `fopen` function;
9675

9776
Both named constructors:
9877

9978
- uses internally a `Pdp\Converter` object to convert the raw content into a suitable array to instantiate a valid `Pdp\Rules`;
10079
- do not have any cache functionnality;
10180

81+
#### Usage
10282

10383
Domain name resolution is done using the `Pdp\Rules::resolve` method which expects at most two parameters:
10484

@@ -108,9 +88,7 @@ Domain name resolution is done using the `Pdp\Rules::resolve` method which expec
10888
- `Rules::ICANN_DOMAINS`, to validate against the PSL ICANN DOMAINS section only.
10989
- `Rules::PRIVATE_DOMAINS`, to validate against the PSL PRIVATE DOMAINS section only.
11090

111-
By default, the `$section` argument is equal to `Rules::ALL_DOMAINS`. If an unsupported section is submitted a `Pdp\Exception` exception will be thrown.
112-
113-
**WARNING: The `Pdp\Rules::resolve` does not validate the submitted host. You are require to use a host validator prior to using this library.**
91+
By default, the `$section` argument is equal to `Rules::ALL_DOMAINS`. If an unsupported section is submitted a `Pdp\Exception` exception will be thrown.
11492

11593
The `Pdp\Rules::resolve` returns a `Pdp\Domain` object.
11694

@@ -129,29 +107,16 @@ final class Domain implements JsonSerializable
129107
}
130108
~~~
131109

132-
The `Pdp\Domain` getter methods returns:
133-
134-
- the submitted domain name using `Pdp\Domain::getDomain`
135-
- the public suffix part normalized according to the domain using `Pdp\Domain::getPublicSuffix`
136-
- the registrable domain part using `Pdp\Domain::getRegistrableDomain`
137-
- the subdomain part using `Pdp\Domain::getSubDomain`.
138-
139-
If the domain name or some of its part are seriously malformed or unrecognized, the getter methods will return `null`.
140-
141-
**The Domain name status depends on the PSL section used to resolve it:**
142-
143-
- `Pdp\Domain::isKnown` returns `true` if the public suffix is found in the selected PSL;
144-
- `Pdp\Domain::isICANN` returns `true` if the public suffix is found in a selected PSL which includes the ICANN DOMAINS section;
145-
- `Pdp\Domain::isPrivate` returns `true` if the public suffix is found in a selected PSL which includes the PRIVATE DOMAINS section;
146-
147-
**THIS EXAMPLE ILLUSTRATES HOW EACH OBJECT IS USED BUT SHOULD BE AVOID IN PRODUCTON**
110+
**THIS EXAMPLE ILLUSTRATES HOW THE OBJECT WORK BUT SHOULD BE AVOIDED IN PRODUCTON**
148111

149112
~~~php
150113
<?php
151114

152115
use Pdp\Rules;
116+
use Pdp\Converter;
153117

154-
$rules = Rules::createFromPath('https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat');
118+
$pdp_url = 'https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat';
119+
$rules = Rules::createFromPath($pdp_url);
155120

156121
$domain = $rules->resolve('www.ulb.ac.be'); //using Rules::ALL_DOMAINS
157122
$domain->getDomain(); //returns 'www.ulb.ac.be'
@@ -189,11 +154,28 @@ echo json_encode($domain, JSON_PRETTY_PRINT);
189154
// }
190155
~~~
191156

157+
The `Pdp\Domain` getter methods returns:
158+
159+
- the submitted domain name using `Pdp\Domain::getDomain`
160+
- the public suffix part normalized according to the domain using `Pdp\Domain::getPublicSuffix`
161+
- the registrable domain part using `Pdp\Domain::getRegistrableDomain`
162+
- the subdomain part using `Pdp\Domain::getSubDomain`.
163+
164+
If the domain name or some of its part are seriously malformed or unrecognized, the getter methods will return `null`.
165+
166+
**The Domain name status depends on the PSL section used to resolve it:**
167+
168+
- `Pdp\Domain::isKnown` returns `true` if the public suffix is found in the selected PSL;
169+
- `Pdp\Domain::isICANN` returns `true` if the public suffix is found using a PSL which includes the ICANN DOMAINS section;
170+
- `Pdp\Domain::isPrivate` returns `true` if the public suffix is found using a PSL which includes the PRIVATE DOMAINS section;
171+
192172
**WARNING:**
193173

174+
**The `Pdp\Rules::resolve` does not validate the submitted host. You are require to use a host validator prior to using this library.**
175+
194176
**You should never use the library this way in production, without, at least, a caching mechanism to reduce PSL downloads.**
195177

196-
**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.**
178+
**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.**
197179

198180
### Public Suffix List Maintenance
199181

0 commit comments

Comments
 (0)