@@ -60,10 +60,12 @@ For the [Public Suffix List](http://publicsuffix.org/) you need to use the
60
60
~~~ php
61
61
<?php
62
62
use Pdp\Rules;
63
+ use Pdp\Domain;
63
64
64
65
$publicSuffixList = Rules::fromPath('/path/to/cache/public-suffix-list.dat');
66
+ $domain = Domain::fromIDNA2008('www.PreF.OkiNawA.jP');
65
67
66
- $result = $publicSuffixList->resolve('www.PreF.OkiNawA.jP' );
68
+ $result = $publicSuffixList->resolve($domain );
67
69
echo $result->domain()->toString(); //display 'www.pref.okinawa.jp';
68
70
echo $result->subDomain()->toString(); //display 'www';
69
71
echo $result->secondLevelDomain()->toString(); //display 'pref';
@@ -76,11 +78,15 @@ For the [IANA Top Level Domain List](https://www.iana.org/domains/root/files),
76
78
the ` Pdp\TopLevelDomains ` class is use instead:
77
79
78
80
~~~ php
81
+ <?php
82
+
83
+ use Pdp\Domain;
79
84
use Pdp\TopLevelDomains;
80
85
81
86
$topLevelDomains = TopLevelDomains::fromPath('/path/to/cache/tlds-alpha-by-domain.txt');
87
+ $domain = Domain::fromIDNA2008('www.PreF.OkiNawA.jP');
82
88
83
- $result = $topLevelDomains->resolve('www.PreF.OkiNawA.jP' );
89
+ $result = $topLevelDomains->resolve($domain );
84
90
echo $result->domain()->toString(); //display 'www.pref.okinawa.jp';
85
91
echo $result->suffix()->toString(); //display 'jp';
86
92
echo $result->secondLevelDomain()->toString(); //display 'okinawa';
@@ -109,31 +115,38 @@ These methods resolve the domain against their respective data source using
109
115
the same rules as the ` resolve ` method but will instead throw an exception
110
116
if no valid effective TLD is found or if the submitted domain is invalid.
111
117
118
+ ** All these methods expect as their sole argument a ` Pdp\Host ` implementing
119
+ object, but other types (ie: ` string ` , ` null ` and stringable objects) are
120
+ supported with predefined conditions as explained in the remaining document.**
121
+
112
122
~~~ php
113
- <?php
123
+ <?php
124
+
125
+ use Pdp\Domain;
114
126
use Pdp\Rules;
115
127
use Pdp\TopLevelDomains;
116
128
117
129
$publicSuffixList = Rules::fromPath('/path/to/cache/public-suffix-list.dat');
130
+ $domain = Domain::fromIDNA2008('qfdsf.unknownTLD');
118
131
119
- $publicSuffixList->getICANNDomain('qfdsf.unknownTLD' );
132
+ $publicSuffixList->getICANNDomain($domain );
120
133
// will throw because `.unknownTLD` is not part of the ICANN section
121
134
122
- $result = $publicSuffixList->getCookieDomain('qfdsf.unknownTLD' );
135
+ $result = $publicSuffixList->getCookieDomain($domain );
123
136
$result->suffix()->value(); // returns 'unknownTLD'
124
137
$result->suffix()->isKnown(); // returns false
125
138
// will not throw because the domain syntax is correct.
126
139
127
- $publicSuffixList->getCookieDomain('com');
140
+ $publicSuffixList->getCookieDomain(Domain::fromIDNA2008( 'com') );
128
141
// will not throw because the domain syntax is invalid (ie: does not support public suffix)
129
142
130
- $result = $publicSuffixList->resolve('com');
143
+ $result = $publicSuffixList->resolve(Domain::fromIDNA2008( 'com') );
131
144
$result->suffix()->value(); // returns null
132
145
$result->suffix()->isKnown(); // returns false
133
146
// will not throw but its public suffix value equal to NULL
134
147
135
148
$topLevelDomains = TopLevelDomains::fromPath('/path/to/cache/public-suffix-list.dat');
136
- $topLevelDomains->getIANADomain('com');
149
+ $topLevelDomains->getIANADomain(Domain::fromIDNA2008( 'com') );
137
150
// will not throw because the domain syntax is invalid (ie: does not support public suffix)
138
151
~~~
139
152
@@ -171,10 +184,12 @@ The `Pdp\ResolvedDomain` decorates the `Pdp\Domain` class resolved but also
171
184
gives access as separate methods to the domain different components.
172
185
173
186
~~~ php
187
+ use Pdp\Domain;
174
188
use Pdp\TopLevelDomains;
175
189
190
+ $domain = Domain::fromIDNA2008('www.PreF.OkiNawA.jP');
176
191
/** @var TopLevelDomains $topLevelDomains */
177
- $result = $topLevelDomains->resolve('www.PreF.OkiNawA.jP' );
192
+ $result = $topLevelDomains->resolve($domain );
178
193
echo $result->domain()->toString(); //display 'www.pref.okinawa.jp';
179
194
echo $result->suffix()->toString(); //display 'jp';
180
195
echo $result->secondLevelDomain()->toString(); //display 'okinawa';
@@ -188,14 +203,15 @@ You can modify the returned `Pdp\ResolvedDomain` instance using the following me
188
203
~~~ php
189
204
<?php
190
205
206
+ use Pdp\Domain;
191
207
use Pdp\Rules;
192
208
193
209
/** @var Rules $publicSuffixList */
194
- $result = $publicSuffixList->resolve('shop.example.com');
210
+ $result = $publicSuffixList->resolve(Domain::fromIDNA2008( 'shop.example.com') );
195
211
$altResult = $result
196
- ->withSubDomain('foo.bar')
197
- ->withSecondLevelDomain('test')
198
- ->withSuffix('example');
212
+ ->withSubDomain(Domain::fromIDNA2008( 'foo.bar') )
213
+ ->withSecondLevelDomain(Domain::fromIDNA2008( 'test') )
214
+ ->withSuffix(Domain::fromIDNA2008( 'example') );
199
215
200
216
echo $result->domain()->toString(); //display 'shop.example.com';
201
217
$result->suffix()->isKnown(); //return true;
@@ -217,10 +233,11 @@ origin.
217
233
218
234
~~~ php
219
235
<?php
236
+ use Pdp\Domain;
220
237
use Pdp\Rules;
221
238
222
239
/** @var Rules $publicSuffixList */
223
- $suffix = $publicSuffixList->resolve('example.github.io')->suffix();
240
+ $suffix = $publicSuffixList->resolve(Domain::fromIDNA2008( 'example.github.io') )->suffix();
224
241
225
242
echo $suffix->domain()->toString(); //display 'github.io';
226
243
$suffix->isICANN(); //will return false
@@ -274,11 +291,12 @@ manipulating domain labels. You can access the object using the following method
274
291
` Domain ` objects usage are explain in the next section.
275
292
276
293
~~~ php
277
- <?php
294
+ <?php
295
+ use Pdp\Domain;
278
296
use Pdp\Rules;
279
297
280
298
/** @var Rules $publicSuffixList */
281
- $result = $publicSuffixList->resolve('www.bbc.co.uk');
299
+ $result = $publicSuffixList->resolve(Domain::from2008( 'www.bbc.co.uk') );
282
300
$domain = $result->domain();
283
301
echo $domain->toString(); // display 'www.bbc.co.uk'
284
302
count($domain); // returns 4
@@ -303,10 +321,11 @@ following methods:
303
321
304
322
~~~ php
305
323
<?php
324
+ use Pdp\Domain;
306
325
use Pdp\Rules;
307
326
308
327
/** @var Rules $publicSuffixList */
309
- $domain = $publicSuffixList->resolve('www.ExAmpLE.cOM')->domain();
328
+ $domain = $publicSuffixList->resolve(Domain::from2008( 'www.ExAmpLE.cOM') )->domain();
310
329
311
330
$newDomain = $domain
312
331
->withLabel(1, 'com') //replace 'example' by 'com'
@@ -540,8 +559,9 @@ Testing
540
559
` pdp-domain-parser ` has:
541
560
542
561
- a [ PHPUnit] ( https://phpunit.de ) test suite
543
- - a coding style compliance test suite using [ PHP CS Fixer] ( http://cs.sensiolabs.org/ ) .
544
- - a code analysis compliance test suite using [ PHPStan] ( https://github.com/phpstan/phpstan ) .
562
+ - a code analysis compliance test suite using [ PHPStan] ( https://phpstan.org ) .
563
+ - a code analysis compliance test suite using [ Psalm] ( https://psalm.dev ) .
564
+ - a coding style compliance test suite using [ PHP CS Fixer] ( https://cs.symfony.com ) .
545
565
546
566
To run the tests, run the following command from the project folder.
547
567
@@ -570,10 +590,9 @@ The MIT License (MIT). Please see [License File](LICENSE) for more information.
570
590
Attribution
571
591
-------
572
592
573
- Portions of the ` Pdp\Converter ` and ` Pdp\ Rules` are derivative works of the PHP
593
+ Portions of the ` Pdp\Rules ` class are derivative works of the PHP
574
594
[ registered-domain-libs] ( https://github.com/usrflo/registered-domain-libs ) .
575
- Those parts of this codebase are heavily commented, and I've included a copy of
576
- the Apache Software Foundation License 2.0 in this project.
595
+ I've included a copy of the Apache Software Foundation License 2.0 in this project.
577
596
578
597
[ ico-github-actions-build ] : https://img.shields.io/github/workflow/status/jeremykendall/php-domain-parser/Build?style=flat-square
579
598
[ ico-packagist ] : https://img.shields.io/packagist/dt/jeremykendall/php-domain-parser.svg?style=flat-square
0 commit comments