Skip to content

Commit 2fb624a

Browse files
committed
update documentation
1 parent ca50d50 commit 2fb624a

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

Diff for: README.md

+44-44
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Documentation
4747

4848
### Domain name resolution
4949

50-
The `Pdp\Rules` object is responsible for domain name resolution.
50+
The `Pdp\Rules` object is responsible for public suffix resolution for a given domain.
5151

5252
~~~php
5353
<?php
@@ -68,23 +68,9 @@ final class Rules
6868
}
6969
~~~
7070

71-
**NEW IN VERSION 5.2:**
72-
73-
- `Rules::getPublicSuffix` returns a `PublicSuffix` object determined from the `Rules` object;
74-
75-
**NEW IN VERSION 5.1:**
76-
77-
- `Rules::createFromString` expects a string content which follows [the PSL format](https://publicsuffix.org/list/#list-format);
78-
- `Rules::createFromPath` expects a valid path to a readable PSL. You can optionnally submit a context resource as defined in PHP's `fopen` function;
79-
80-
Both named constructors:
81-
82-
- uses internally a `Pdp\Converter` object to convert the raw content into a suitable array to instantiate a valid `Pdp\Rules`;
83-
- do not have any cache functionnality;
84-
8571
#### Usage
8672

87-
Domain name resolution is done using the `Pdp\Rules::resolve` method which expects at most two parameters:
73+
Public suffix resolution is done using the `Pdp\Rules::resolve` method which expects at most two parameters:
8874

8975
- `$domain` a domain name as a string
9076
- `$section` a string which specifies which section of the PSL you want to validate the given domain against. The possible values are:
@@ -96,29 +82,37 @@ By default, the `$section` argument is equal to `Rules::ALL_DOMAINS`. If an unsu
9682

9783
The `Pdp\Rules::resolve` returns a `Pdp\Domain` object.
9884

85+
The `Pdp\Domain` implements the `Pdp\DomainInterface`
86+
9987
~~~php
10088
<?php
10189

102-
final class Domain implements JsonSerializable
90+
interface DomainInterface extends Countable, IteratorAggregate
91+
{
92+
public function getContent(): ?string
93+
public function getLabel(int $offset): ?string
94+
public function keys(string $label): int[]
95+
public function toUnicode(): static;
96+
public function toAscii(): static;
97+
}
98+
~~~
99+
100+
But also enable returns informations about the domain parts and its public suffix status.
101+
102+
~~~php
103+
<?php
104+
105+
final class Domain implements DomainInterface, JsonSerializable
103106
{
104-
public function getDomain(): ?string
105107
public function getPublicSuffix(): ?string
106108
public function getRegistrableDomain(): ?string
107109
public function getSubDomain(); ?string
108110
public function isKnown(): bool;
109111
public function isICANN(): bool;
110112
public function isPrivate(): bool;
111-
public function toUnicode(): self;
112-
public function toAscii(): self;
113113
}
114114
~~~
115115

116-
**NEW IN VERSION 5.2:**
117-
118-
- `Domain::toUnicode` returns an instance with the domain converted to its unicode representation;
119-
- `Domain::toAscii` returns an instance with the domain converted to its ascii representation;
120-
- `Domain::getDomain` will lowercase the domain name to normalize its content;
121-
122116
**THIS EXAMPLE ILLUSTRATES HOW THE OBJECT WORK BUT SHOULD BE AVOIDED IN PRODUCTON**
123117

124118
~~~php
@@ -131,13 +125,25 @@ $pdp_url = 'https://raw.githubusercontent.com/publicsuffix/list/master/public_su
131125
$rules = Rules::createFromPath($pdp_url);
132126

133127
$domain = $rules->resolve('www.Ulb.AC.be'); //using Rules::ALL_DOMAINS
134-
$domain->getDomain(); //returns 'www.ulb.ac.be'
128+
$domain->getContent(); //returns 'www.ulb.ac.be'
135129
$domain->getPublicSuffix(); //returns 'ac.be'
136130
$domain->getRegistrableDomain(); //returns 'ulb.ac.be'
137131
$domain->getSubDomain(); //returns 'www'
132+
$domain->getLabel(0) //returns 'be'
133+
$domain->getLabel(-1) //returns 'www'
134+
$domain->keys('ulb') //returns [2]
138135
$domain->isKnown(); //returns true
139136
$domain->isICANN(); //returns true
140137
$domain->isPrivate(); //returns false
138+
echo json_encode(iterator_to_array($domain), JSON_PRETTY_PRINT);
139+
// returns
140+
// [
141+
// 'be',
142+
// 'ac',
143+
// 'ulb',
144+
// 'www'
145+
// ]
146+
141147
echo json_encode($domain, JSON_PRETTY_PRINT);
142148
// returns
143149
// {
@@ -166,16 +172,9 @@ echo json_encode($domain, JSON_PRETTY_PRINT);
166172
// }
167173
~~~
168174

169-
The `Pdp\Domain` getter methods returns:
170-
171-
- the submitted domain name using `Pdp\Domain::getDomain`
172-
- the public suffix part normalized according to the domain using `Pdp\Domain::getPublicSuffix`
173-
- the registrable domain part using `Pdp\Domain::getRegistrableDomain`
174-
- the subdomain part using `Pdp\Domain::getSubDomain`.
175+
- All `Pdp\Domain` getter methods returns normalized and lowercased domain labels or `null` if no value was found for a particular domain part.
175176

176-
If the domain name or some of its part are seriously malformed or unrecognized, the getter methods will return `null`.
177-
178-
**The Domain name status depends on the PSL section used to resolve it:**
177+
**The domain public suffix status depends on the PSL section used to resolve it:**
179178

180179
- `Pdp\Domain::isKnown` returns `true` if the public suffix is found in the selected PSL;
181180
- `Pdp\Domain::isICANN` returns `true` if the public suffix is found using a PSL which includes the ICANN DOMAINS section;
@@ -186,26 +185,22 @@ The `Rules::getPublicSuffix` method expects the same arguments as `Rules::resolv
186185
~~~php
187186
<?php
188187

189-
final class PublicSuffix implements Countable, JsonSerializable
188+
final class PublicSuffix implements DomainInterface, JsonSerializable
190189
{
191-
public function getContent(): ?string
192190
public function isKnown(): bool;
193191
public function isICANN(): bool;
194192
public function isPrivate(): bool;
195-
public function toUnicode(): self;
196-
public function toAscii(): self;
197193
}
198194
~~~
199195

200196
While `Rules::resolve` will only throws an exception if the section value is invalid, the `Rules::getPublicSuffix` is more restrictive and will additionnally throw if:
201197

202198
- The domain name is invalid or seriously malformed
203-
- The public suffix can not be normalized and converted using the domain encoding.
199+
- No public suffix can be match against the submitted domain.
200+
- The public suffix can not be normalized using the domain encoding.
204201

205202
**WARNING:**
206203

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

211206
**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.**
@@ -375,7 +370,7 @@ For example, below I'm using the `Manager` with
375370

376371
Of course you can add more setups depending on your usage.
377372

378-
<p class="message-notice">Be sure to adapt the following code to your own framework/situation. The following code is given as an example without warranty of it working out of the box.</p>
373+
**Be sure to adapt the following code to your own framework/situation. The following code is given as an example without warranty of it working out of the box.**
379374

380375
~~~php
381376
<?php
@@ -422,6 +417,11 @@ $domain->getSubDomain(); //returns 'nl.shop'
422417
$domain->isKnown(); //returns false
423418
~~~
424419

420+
Changelog
421+
-------
422+
423+
Please see [CHANGELOG](CHANGELOG.md) for more information about what has been changed since version **5.0.0** was released.
424+
425425
Contributing
426426
-------
427427

0 commit comments

Comments
 (0)