You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the above code you can parse and get public suffix informations about any valid domain name.
72
85
73
-
Public suffix resolution is done using the `Pdp\Rules::resolve` method which expects at most two parameters:
86
+
### Manipulating the domain name
74
87
75
-
-`$domain` a domain name as a string
76
-
-`$section` a string which specifies which section of the PSL you want to validate the given domain against. The possible values are:
77
-
-`Rules::ALL_DOMAINS`, to validate against the full PSL.
78
-
-`Rules::ICANN_DOMAINS`, to validate against the PSL ICANN DOMAINS section only.
79
-
-`Rules::PRIVATE_DOMAINS`, to validate against the PSL PRIVATE DOMAINS section only.
88
+
The `Pdp\Domain` returned by the `Pdp\Rules::resolve` method is an immutable value object representing a valid domain name. This object let's you access all the domain name properties as well as the public suffix informations attached to it using the following methods.
80
89
81
-
By default, the `$section` argument is equal to `Rules::ALL_DOMAINS`. If an unsupported section is submitted a `Pdp\Exception` exception will be thrown.
90
+
~~~php
91
+
public function Domain::getLabel(int $key): ?string
92
+
public function Domain::keys(?string $label): int[]
93
+
public function Domain::getContent(): ?string
94
+
public function Domain::getPublicSuffix(): ?string
95
+
public function Domain::getRegistrableDomain(): ?string
96
+
public function Domain::getSubDomain(); ?string
97
+
public function Domain::isKnown(): bool;
98
+
public function Domain::isICANN(): bool;
99
+
public function Domain::isPrivate(): bool;
100
+
~~~
82
101
83
-
The `Pdp\Rules::resolve`returns a `Pdp\Domain` object.
102
+
*The getter methods returns normalized and lowercased domain labels or `null` if no value was found for a particular domain part.*
84
103
85
-
The `Pdp\Domain` implements the `Pdp\DomainInterface`
104
+
The `Pdp\Domain`object also implements PHP's `Countable` and `IteratorAggregate` interfaces to ease counting and iterating over the domain labels as well as PHP's `JsonSerializable` interfaces to output a JSON array with all the useful informations regarding the domain name.
86
105
87
-
~~~php
88
-
<?php
106
+
Once you have a `Pdp\Domain` object can also modify its content using the following methods:
The `Pdp\Rules` object is responsible for public suffix resolution for a given domain. Public suffix resolution is done using the `Pdp\Rules::resolve` or `Pdp\Rules::getPublicSuffix` methods which expects at most two parameters:
157
+
158
+
-`$domain` a domain name as a string
159
+
-`$section` a string which specifies which section of the PSL you want to validate the given domain against. The possible values are:
160
+
-`Rules::ALL_DOMAINS`, to validate against the full PSL.
161
+
-`Rules::ICANN_DOMAINS`, to validate against the PSL ICANN DOMAINS section only.
162
+
-`Rules::PRIVATE_DOMAINS`, to validate against the PSL PRIVATE DOMAINS section only.
163
+
164
+
By default, the `$section` argument is equal to `Rules::ALL_DOMAINS`. If an unsupported section is submitted a `Pdp\Exception` exception will be thrown.
165
+
166
+
While the `Pdp\Rules::resolve` returns a `Pdp\Domain` object, the `Pdp\Rules::getPublicSuffix` returns a `Pdp\PublicSuffix` object.
167
+
118
168
**THIS EXAMPLE ILLUSTRATES HOW THE OBJECT WORK BUT SHOULD BE AVOIDED IN PRODUCTON**
- All `Pdp\Domain` getter methods returns normalized and lowercased domain labels or `null` if no value was found for a particular domain part.
178
-
179
208
**The domain public suffix status depends on the PSL section used to resolve it:**
180
209
181
210
-`Pdp\Domain::isKnown` returns `true` if the public suffix is found in the selected PSL;
182
211
-`Pdp\Domain::isICANN` returns `true` if the public suffix is found using a PSL which includes the ICANN DOMAINS section;
183
212
-`Pdp\Domain::isPrivate` returns `true` if the public suffix is found using a PSL which includes the PRIVATE DOMAINS section;
184
213
185
-
The `Rules::getPublicSuffix` method expects the same arguments as `Rules::resolve` but returns a `Pdp\PublicSuffix` object instead.
186
-
187
-
~~~php
188
-
<?php
189
-
190
-
final class PublicSuffix implements DomainInterface, JsonSerializable
191
-
{
192
-
public function __construct($publicSuffix = null)
193
-
public function isKnown(): bool;
194
-
public function isICANN(): bool;
195
-
public function isPrivate(): bool;
196
-
}
197
-
~~~
198
-
199
-
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:
200
-
201
-
- The domain name is invalid or seriously malformed
202
-
- No public suffix can be match against the submitted domain.
203
-
- The public suffix can not be normalized using the domain encoding.
204
-
205
214
**WARNING:**
206
215
207
216
**You should never use the library this way in production, without, at least, a caching mechanism to reduce PSL downloads.**
0 commit comments