Skip to content

Commit 2309d81

Browse files
committed
update documentation
1 parent 63dc577 commit 2309d81

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,25 @@ final class Rules
8181
const ICANN_DOMAINS = 'ICANN_DOMAINS';
8282
const PRIVATE_DOMAINS = 'PRIVATE_DOMAINS';
8383

84+
public static function createFromPath(string $path, $context = null): self
85+
public static function createFromString(string $content): self
8486
public function __construct(array $rules)
8587
public function resolve(string $domain = null, string $section = self::ALL_DOMAINS): Domain
8688
}
8789
~~~
8890

91+
Starting with version 5.1.0, the following named constructors arre added to ease `Rules` instantiation.
92+
93+
- `Rules::createFromString` expects a string content which follows [the PSL format](https://publicsuffix.org/list/#list-format);
94+
95+
- `Rules::createFromPath` expects a valid path to a readable PSL. You can optionnally submit a context resource as defined in PHP's `fopen` function;
96+
97+
Both named constructors:
98+
99+
- uses internally a `Pdp\Converter` object to convert the raw content into a suitable array to instantiate a valid `Pdp\Rules`;
100+
- do not have any cache functionnality;
101+
102+
89103
Domain name resolution is done using the `Pdp\Rules::resolve` method which expects at most two parameters:
90104

91105
- `$domain` a domain name as a string
@@ -135,12 +149,9 @@ If the domain name or some of its part are seriously malformed or unrecognized,
135149
~~~php
136150
<?php
137151

138-
use Pdp\Converter;
139152
use Pdp\Rules;
140153

141-
$content = file_get_contents('https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat');
142-
$arr_rules = (new Converter())->convert($content);
143-
$rules = new Rules($arr_rules);
154+
$rules = Rules::createFromPath('https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat');
144155

145156
$domain = $rules->resolve('www.ulb.ac.be'); //using Rules::ALL_DOMAINS
146157
$domain->getDomain(); //returns 'www.ulb.ac.be'

0 commit comments

Comments
 (0)