Skip to content

Commit 5130bad

Browse files
authored
Merge pull request #279 from jeremykendall/develop
Prepare 5.7.0 release
2 parents fc21003 + 61f50ec commit 5130bad

37 files changed

+943
-605
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ docs
77
build
88
.idea
99
.php_cs.cache
10+
.phpunit.result.cache

.travis.yml

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,63 @@
11
language: php
2-
32
sudo: false
4-
53
cache:
6-
directories:
7-
- $HOME/.composer/cache
8-
9-
env:
10-
global:
11-
- COMPOSER_ARGS="--no-interaction --prefer-source --no-suggest"
12-
4+
directories:
5+
- "$HOME/.composer/cache"
136
matrix:
14-
include:
15-
- php: 7.0
16-
env:
17-
- VALIDATE_CODING_STYLE=false
18-
- RUN_PHPSTAN=false
19-
- IGNORE_PLATFORMS=false
20-
- php: 7.1
21-
env:
22-
- VALIDATE_CODING_STYLE=false
23-
- RUN_PHPSTAN=false
24-
- IGNORE_PLATFORMS=false
25-
- php: 7.2
26-
env:
27-
- VALIDATE_CODING_STYLE=true
28-
- RUN_PHPSTAN=true
29-
- IGNORE_PLATFORMS=false
30-
- php: 7.3
31-
env:
32-
- VALIDATE_CODING_STYLE=false
33-
- RUN_PHPSTAN=false
34-
- IGNORE_PLATFORMS=true
35-
- php: 7.4
36-
env:
37-
- COLLECT_COVERAGE=false
38-
- VALIDATE_CODING_STYLE=false
39-
- RUN_PHPSTAN=false
40-
- IGNORE_PLATFORMS=true
41-
- php: nightly
42-
env:
43-
- COLLECT_COVERAGE=false
44-
- IGNORE_PLATFORMS=true
45-
- RUN_PHPSTAN=false
46-
- VALIDATE_CODING_STYLE=false
47-
allow_failures:
48-
- php: nightly
49-
fast_finish: true
50-
7+
include:
8+
- php: 7.2
9+
env:
10+
- COLLECT_COVERAGE=false
11+
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source --prefer-lowest --prefer-stable"
12+
- RUN_PHPSTAN=false
13+
- VALIDATE_CODING_STYLE=false
14+
- php: 7.2
15+
env:
16+
- COLLECT_COVERAGE=true
17+
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source"
18+
- RUN_PHPSTAN=true
19+
- VALIDATE_CODING_STYLE=true
20+
- php: 7.3
21+
env:
22+
- COLLECT_COVERAGE=false
23+
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source --prefer-lowest --prefer-stable"
24+
- RUN_PHPSTAN=false
25+
- VALIDATE_CODING_STYLE=false
26+
- php: 7.3
27+
env:
28+
- COLLECT_COVERAGE=true
29+
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source"
30+
- RUN_PHPSTAN=true
31+
- VALIDATE_CODING_STYLE=true
32+
- php: 7.4
33+
env:
34+
- COLLECT_COVERAGE=false
35+
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source --prefer-lowest --prefer-stable"
36+
- RUN_PHPSTAN=false
37+
- VALIDATE_CODING_STYLE=false
38+
- php: 7.4
39+
env:
40+
- COLLECT_COVERAGE=true
41+
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source"
42+
- RUN_PHPSTAN=true
43+
- VALIDATE_CODING_STYLE=true
44+
- php: nightly
45+
env:
46+
- COLLECT_COVERAGE=false
47+
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source --ignore-platform-reqs"
48+
- RUN_PHPSTAN=false
49+
- VALIDATE_CODING_STYLE=false
50+
allow_failures:
51+
- php: nightly
52+
fast_finish: true
5153
before_install:
52-
- travis_retry composer self-update
53-
54+
- travis_retry composer self-update
5455
install:
55-
- if [ "$IGNORE_PLATFORMS" == "true" ]; then travis_retry composer update $COMPOSER_ARGS --ignore-platform-reqs; fi
56-
- if [ "$IGNORE_PLATFORMS" == "false" ]; then travis_retry composer update $COMPOSER_ARGS; fi
57-
56+
- travis_retry composer update $COMPOSER_ARGS
5857
script:
59-
- if [ "$RUN_PHPSTAN" == "true" ]; then composer phpstan; fi
60-
- if [ "$VALIDATE_CODING_STYLE" == "true" ]; then composer phpcs; fi
61-
- composer phpunit
62-
58+
- if [ "$VALIDATE_CODING_STYLE" == "true" ]; then composer phpcs; fi
59+
- if [ "$RUN_PHPSTAN" == "true" ]; then composer phpstan; fi
60+
- composer phpunit
6361
after_script:
64-
- if [ "$COLLECT_COVERAGE" == "true" ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/clover.xml; fi
62+
- if [ "$COLLECT_COVERAGE" == "true" ]; then wget https://scrutinizer-ci.com/ocular.phar
63+
&& php ocular.phar code-coverage:upload --format=php-clover build/clover.xml; fi

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22

33
All Notable changes to `PHP Domain Parser` **5.x** series will be documented in this file
44

5+
## 5.7.0 - 2020-08-02
6+
7+
### Added
8+
9+
- `Rules::getCookieDomain`
10+
- `Rules::getICANNDomain`
11+
- `Rules::getPrivateDomain`
12+
- `CouldNotResolvePublicSuffix::dueToUnresolvableDomain`
13+
14+
### Fixed
15+
16+
- Improve type hinting and return type by dropping EOL PHP versions support.
17+
- Improve development environment by dropping EOL PHP versions support.
18+
19+
### Deprecated
20+
21+
- None
22+
23+
### Removed
24+
25+
- Support for PHP7.0 and PHP7.1
26+
- The external data from IANA and mozilla is no longer part of the package and will be downloaded only on demand on composer update/install.
27+
528
## 5.6.0 - 2019-12-29
629

730
### Added

README.md

Lines changed: 65 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ System Requirements
2727

2828
You need:
2929

30-
- **PHP >= 7.0** but the latest stable version of PHP is recommended
30+
- **PHP >= 7.2.5** but the latest stable version of PHP is recommended
3131
- the `intl` extension
3232

3333
Dependencies
@@ -46,18 +46,63 @@ $ composer require jeremykendall/php-domain-parser
4646
Usage
4747
--------
4848

49+
### Domain part resolutions
50+
51+
The first objective of the library is using the [Public Suffix List](http://publicsuffix.org/) to easily resolve domain information.
52+
4953
~~~php
50-
<?php
54+
use Pdp\Rules;
5155

52-
use Pdp\Cache;
53-
use Pdp\CurlHttpClient;
54-
use Pdp\Manager;
56+
$rules = Rules::createFromPath('/path/to/mozilla/public-suffix.dat');
57+
58+
echo $rules->getCookieDomain('www.ulb.ac.be'); // returns a Pdp\Domain object whose Public Suffix is 'ac.be';
59+
echo $rules->getICANNDomain('www.ulb.ac.be'); // returns a Pdp\Domain object whose Public Suffix is 'ac.be';
60+
echo $rules->getPrivateDomain('www.ulb.ac.be'); // returns a Pdp\Domain object whose Public Suffix is 'be';
61+
~~~
62+
63+
**WARNING: If the Domain can not be resolved an exception is thrown.**
64+
65+
These methods are available since version `5.7.0` to ease the package usage. Prior to this version you could use the
66+
`Rules::resolve` method with an optional `$section` argument to get the same results:
67+
68+
~~~php
5569
use Pdp\Rules;
5670

57-
$manager = new Manager(new Cache(), new CurlHttpClient());
58-
$rules = $manager->getRules(); //$rules is a Pdp\Rules object
71+
$rules = Rules::createFromPath('/path/to/mozilla/public-suffix.dat');
72+
73+
echo $rules->resolve('www.ulb.ac.be'); // returns a Pdp\Domain object whose Public Suffix is 'ac.be';
74+
echo $rules->resolve('www.ulb.ac.be', Rules::ICANN_DOMAINS); // returns a Pdp\Domain object whose Public Suffix is 'ac.be';
75+
echo $rules->resolve('www.ulb.ac.be', Rules::PRIVATE_DOMAINS); // returns a Pdp\Domain object whose Public Suffix is 'be';
76+
~~~
77+
78+
**WARNING: If the Domain can not be resolved or in case of error a null `Pdp\Domain` is returned.**
79+
80+
### Top Level Domains resolution
81+
82+
While the [Public Suffix List](http://publicsuffix.org/) is a community based list. We can parse the Top Level domain
83+
information given by the [IANA website](https://data.iana.org/TLD/tlds-alpha-by-domain.txt) to always resolve
84+
top domain against the newly registered TLD.
5985

60-
$domain = $rules->resolve('www.ulb.ac.be'); //$domain is a Pdp\Domain object
86+
~~~php
87+
use Pdp\TopLevelDomains;
88+
89+
$rules = TopLevelDomains::createFromPath('/path/to/iana/tlds-alpha-by-domain.txt');
90+
91+
echo $rules->resolve('www.UlB.Ac.bE')->getPublicSuffix(); //display 'be';
92+
~~~
93+
94+
If the Domain is not resolved or in case of error a null `Pdp\Domain` is returned.
95+
96+
### The Domain and Public Suffix objects.
97+
98+
~~~php
99+
<?php
100+
101+
use Pdp\Rules;use Pdp\TopLevelDomains;
102+
103+
$rules = Rules::createFromPath('/path/to/mozilla/public-suffix.dat'); //$rules is a Pdp\Rules object
104+
105+
$domain = $rules->getICANNDomain('www.ulb.ac.be'); //$domain is a Pdp\Domain object
61106
echo $domain->getContent(); // 'www.ulb.ac.be'
62107
echo $domain->getPublicSuffix(); // 'ac.be'
63108
echo $domain->getRegistrableDomain(); // 'ulb.ac.be'
@@ -67,24 +112,12 @@ $domain->isKnown(); // returns true
67112
$domain->isICANN(); // returns true
68113
$domain->isPrivate(); // returns false
69114
$domain->labels(); // returns ['be', 'ac', 'ulb', 'www']
70-
$publicSuffix = $rules->getPublicSuffix('mydomain.github.io', Rules::PRIVATE_DOMAINS); //$publicSuffix is a Pdp\PublicSuffix object
71-
echo $publicSuffix->getContent(); // 'github.io'
72-
$publicSuffix->isKnown(); // returns true
73-
$publicSuffix->isICANN(); // returns false
74-
$publicSuffix->isPrivate(); // returns true
75-
$publicSuffix->labels(); // returns ['io', 'github']
76-
77-
$altSuffix = $rules->getPublicSuffix('mydomain.github.io', Rules::ICANN_DOMAINS);
78-
echo $altSuffix->getContent(); // 'io'
79-
$altSuffix->isKnown(); // returns true
80-
$altSuffix->isICANN(); // returns true
81-
$altSuffix->isPrivate(); // returns false
82-
83-
$tldList = $manager->getTLDs(); //$tldList is a Pdp\TopLevelDomains object
115+
116+
$tldList = TopLevelDomains::createFromPath('/path/to/IANA/RootZoneDatabase.txt'); //$tldList is a Pdp\TopLevelDomains object
84117
$domain = $tldList->resolve('www.ulb.ac.be'); //$domain is a Pdp\Domain object
85118
$tldList->contains('be'); //returns true
86119
$tldList->contains('localhost'); //return false
87-
foreach($tldList as $tld) {
120+
foreach ($tldList as $tld) {
88121
//$tld is a Pdp\PublisSuffix object
89122
}
90123
~~~
@@ -96,8 +129,7 @@ Using the above code you have parse, validate and resolve a domain name and its
96129
**Before**
97130

98131
~~~php
99-
$manager = new Manager(new Cache(), new CurlHttpClient());
100-
$rules = $manager->getRules();
132+
$rules = Rules::createFromPath('/path/to/mozilla/public-suffix.dat'); //$rules is a Pdp\Rules object
101133

102134
$domain = $rules->resolve('faß.test.de');
103135
echo $domain->toAscii()->getContent(); // 'fass.test.de'
@@ -106,19 +138,12 @@ echo $domain->toAscii()->getContent(); // 'fass.test.de'
106138
**After**
107139

108140
~~~php
109-
$manager = new Manager(new Cache(), new CurlHttpClient());
110-
$rules = $manager->getRules()
111-
->withAsciiIDNAOption(IDNA_NONTRANSITIONAL_TO_ASCII)
112-
->withUnicodeIDNAOption(IDNA_NONTRANSITIONAL_TO_UNICODE);
113-
114-
// or
115-
//
116-
// $rules = $manager->getRules(
117-
// Manager::PSL_URL,
118-
// null,
119-
// IDNA_NONTRANSITIONAL_TO_ASCII,
120-
// IDNA_NONTRANSITIONAL_TO_UNICODE
121-
// );
141+
$rules = Rules::createFromPath(
142+
'/path/to/mozilla/public-suffix.dat',
143+
null, // PHP resource context (see fopen context argument)
144+
IDNA_NONTRANSITIONAL_TO_ASCII,
145+
IDNA_NONTRANSITIONAL_TO_UNICODE
146+
); //$rules is a Pdp\Rules object
122147

123148
$domain = $rules->resolve('faß.test.de');
124149
echo $domain->toAscii()->getContent(); // 'xn--fa-hia.test.de'
@@ -514,7 +539,7 @@ public Manager::getTLDs(
514539
): TopLevelDomains
515540
~~~
516541

517-
These methods returns a `Pdp\Rules` or `Pdp\TopLevelDomains` objects seeded with their corresponding data fetch from the cache or from the external resources depending on the submitted `$ttl` argument.
542+
These methods return a `Pdp\Rules` or `Pdp\TopLevelDomains` objects seeded with their corresponding data fetch from the cache or from the external resources depending on the submitted `$ttl` argument.
518543

519544
These methods take an optional `$url` argument which specifies the PSL source URL. If no local cache exists for the submitted source URL, the method will:
520545

@@ -538,7 +563,7 @@ They are used when instantiated the returned object.
538563

539564
~~~php
540565
$manager = new Pdp\Manager(new Pdp\Cache(), new Pdp\CurlHttpClient());
541-
$tldCollection = $manager->getTLDs(self::RZD_URL);
566+
$tldCollection = $manager->getTLDs(Pdp\Manager::RZD_URL);
542567
$domain = $tldCollection->resolve('www.ulb.ac.be');
543568
echo $domain->getPublicSuffix(); // print 'be'
544569
~~~

bin/update-psl

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@ use Pdp\Logger;
1818
use Pdp\Installer;
1919
use Pdp\Manager;
2020

21-
require dirname(__DIR__).'/vendor/autoload.php';
21+
function get_vendor_path(): ?string
22+
{
23+
for ($i = 1; $i <= 5; $i++) {
24+
$vendor = dirname(__DIR__, $i).'/vendor';
25+
if (is_dir($vendor) && file_exists($vendor.'/autoload.php')) {
26+
return $vendor;
27+
}
28+
}
29+
30+
return null;
31+
}
2232

2333
function writeln(array $messages, $output): int
2434
{
@@ -41,6 +51,20 @@ function fail(string $message, $output = STDERR): int
4151
return writeln($messages, $output);
4252
}
4353

54+
$vendor = get_vendor_path();
55+
if (null === $vendor) {
56+
$message = <<<TEXT
57+
You must set up the project dependencies using composer
58+
see https://getcomposer.org
59+
TEXT;
60+
61+
fail($message);
62+
63+
die(1);
64+
}
65+
66+
require $vendor.'/autoload.php';
67+
4468
/**
4569
* CLI colors
4670
*/
@@ -72,7 +96,7 @@ if (isset($arguments['help']) || isset($arguments['h'])) {
7296
$helpText = <<<HELP
7397
{$yellow}Usage:$reset
7498
$script [options]
75-
99+
76100
{$yellow}Options:$reset
77101
$green --%s$reset refreshes the Public Suffix List cache
78102
$green --%s=URL$reset set the URL to use to refresh the PSL cache ({$yellow}default:$reset %s)
@@ -84,15 +108,15 @@ if (isset($arguments['help']) || isset($arguments['h'])) {
84108
85109
{$yellow}Help:$reset
86110
The {$green}update-psl$reset command updates your PDP local cache.
87-
111+
88112
{$yellow}Examples:$reset
89113
90114
Refresh all caches using the default settings
91115
$green$script$reset
92-
93-
Refresh only the PSL cache for a TTL of 3 DAY
116+
117+
Refresh only the PSL cache for a TTL of 3 DAY
94118
$green$script --psl --ttl="3 DAYS"$reset
95-
119+
96120
Refresh all caches using another cache directory
97121
$green$script --cache-dir=/temp$reset
98122

0 commit comments

Comments
 (0)