Skip to content

Commit

Permalink
Merge pull request #279 from jeremykendall/develop
Browse files Browse the repository at this point in the history
Prepare 5.7.0 release
  • Loading branch information
nyamsprod authored Aug 3, 2020
2 parents fc21003 + 61f50ec commit 5130bad
Show file tree
Hide file tree
Showing 37 changed files with 943 additions and 605 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ docs
build
.idea
.php_cs.cache
.phpunit.result.cache
111 changes: 55 additions & 56 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,63 @@
language: php

sudo: false

cache:
directories:
- $HOME/.composer/cache

env:
global:
- COMPOSER_ARGS="--no-interaction --prefer-source --no-suggest"

directories:
- "$HOME/.composer/cache"
matrix:
include:
- php: 7.0
env:
- VALIDATE_CODING_STYLE=false
- RUN_PHPSTAN=false
- IGNORE_PLATFORMS=false
- php: 7.1
env:
- VALIDATE_CODING_STYLE=false
- RUN_PHPSTAN=false
- IGNORE_PLATFORMS=false
- php: 7.2
env:
- VALIDATE_CODING_STYLE=true
- RUN_PHPSTAN=true
- IGNORE_PLATFORMS=false
- php: 7.3
env:
- VALIDATE_CODING_STYLE=false
- RUN_PHPSTAN=false
- IGNORE_PLATFORMS=true
- php: 7.4
env:
- COLLECT_COVERAGE=false
- VALIDATE_CODING_STYLE=false
- RUN_PHPSTAN=false
- IGNORE_PLATFORMS=true
- php: nightly
env:
- COLLECT_COVERAGE=false
- IGNORE_PLATFORMS=true
- RUN_PHPSTAN=false
- VALIDATE_CODING_STYLE=false
allow_failures:
- php: nightly
fast_finish: true

include:
- php: 7.2
env:
- COLLECT_COVERAGE=false
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source --prefer-lowest --prefer-stable"
- RUN_PHPSTAN=false
- VALIDATE_CODING_STYLE=false
- php: 7.2
env:
- COLLECT_COVERAGE=true
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source"
- RUN_PHPSTAN=true
- VALIDATE_CODING_STYLE=true
- php: 7.3
env:
- COLLECT_COVERAGE=false
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source --prefer-lowest --prefer-stable"
- RUN_PHPSTAN=false
- VALIDATE_CODING_STYLE=false
- php: 7.3
env:
- COLLECT_COVERAGE=true
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source"
- RUN_PHPSTAN=true
- VALIDATE_CODING_STYLE=true
- php: 7.4
env:
- COLLECT_COVERAGE=false
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source --prefer-lowest --prefer-stable"
- RUN_PHPSTAN=false
- VALIDATE_CODING_STYLE=false
- php: 7.4
env:
- COLLECT_COVERAGE=true
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source"
- RUN_PHPSTAN=true
- VALIDATE_CODING_STYLE=true
- php: nightly
env:
- COLLECT_COVERAGE=false
- COMPOSER_ARGS="--no-interaction --no-suggest --prefer-source --ignore-platform-reqs"
- RUN_PHPSTAN=false
- VALIDATE_CODING_STYLE=false
allow_failures:
- php: nightly
fast_finish: true
before_install:
- travis_retry composer self-update

- travis_retry composer self-update
install:
- if [ "$IGNORE_PLATFORMS" == "true" ]; then travis_retry composer update $COMPOSER_ARGS --ignore-platform-reqs; fi
- if [ "$IGNORE_PLATFORMS" == "false" ]; then travis_retry composer update $COMPOSER_ARGS; fi

- travis_retry composer update $COMPOSER_ARGS
script:
- if [ "$RUN_PHPSTAN" == "true" ]; then composer phpstan; fi
- if [ "$VALIDATE_CODING_STYLE" == "true" ]; then composer phpcs; fi
- composer phpunit

- if [ "$VALIDATE_CODING_STYLE" == "true" ]; then composer phpcs; fi
- if [ "$RUN_PHPSTAN" == "true" ]; then composer phpstan; fi
- composer phpunit
after_script:
- 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
- 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
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

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

## 5.7.0 - 2020-08-02

### Added

- `Rules::getCookieDomain`
- `Rules::getICANNDomain`
- `Rules::getPrivateDomain`
- `CouldNotResolvePublicSuffix::dueToUnresolvableDomain`

### Fixed

- Improve type hinting and return type by dropping EOL PHP versions support.
- Improve development environment by dropping EOL PHP versions support.

### Deprecated

- None

### Removed

- Support for PHP7.0 and PHP7.1
- 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.

## 5.6.0 - 2019-12-29

### Added
Expand Down
105 changes: 65 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ System Requirements

You need:

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

Dependencies
Expand All @@ -46,18 +46,63 @@ $ composer require jeremykendall/php-domain-parser
Usage
--------

### Domain part resolutions

The first objective of the library is using the [Public Suffix List](http://publicsuffix.org/) to easily resolve domain information.

~~~php
<?php
use Pdp\Rules;

use Pdp\Cache;
use Pdp\CurlHttpClient;
use Pdp\Manager;
$rules = Rules::createFromPath('/path/to/mozilla/public-suffix.dat');

echo $rules->getCookieDomain('www.ulb.ac.be'); // returns a Pdp\Domain object whose Public Suffix is 'ac.be';
echo $rules->getICANNDomain('www.ulb.ac.be'); // returns a Pdp\Domain object whose Public Suffix is 'ac.be';
echo $rules->getPrivateDomain('www.ulb.ac.be'); // returns a Pdp\Domain object whose Public Suffix is 'be';
~~~

**WARNING: If the Domain can not be resolved an exception is thrown.**

These methods are available since version `5.7.0` to ease the package usage. Prior to this version you could use the
`Rules::resolve` method with an optional `$section` argument to get the same results:

~~~php
use Pdp\Rules;

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

echo $rules->resolve('www.ulb.ac.be'); // returns a Pdp\Domain object whose Public Suffix is 'ac.be';
echo $rules->resolve('www.ulb.ac.be', Rules::ICANN_DOMAINS); // returns a Pdp\Domain object whose Public Suffix is 'ac.be';
echo $rules->resolve('www.ulb.ac.be', Rules::PRIVATE_DOMAINS); // returns a Pdp\Domain object whose Public Suffix is 'be';
~~~

**WARNING: If the Domain can not be resolved or in case of error a null `Pdp\Domain` is returned.**

### Top Level Domains resolution

While the [Public Suffix List](http://publicsuffix.org/) is a community based list. We can parse the Top Level domain
information given by the [IANA website](https://data.iana.org/TLD/tlds-alpha-by-domain.txt) to always resolve
top domain against the newly registered TLD.

$domain = $rules->resolve('www.ulb.ac.be'); //$domain is a Pdp\Domain object
~~~php
use Pdp\TopLevelDomains;

$rules = TopLevelDomains::createFromPath('/path/to/iana/tlds-alpha-by-domain.txt');

echo $rules->resolve('www.UlB.Ac.bE')->getPublicSuffix(); //display 'be';
~~~

If the Domain is not resolved or in case of error a null `Pdp\Domain` is returned.

### The Domain and Public Suffix objects.

~~~php
<?php

use Pdp\Rules;use Pdp\TopLevelDomains;

$rules = Rules::createFromPath('/path/to/mozilla/public-suffix.dat'); //$rules is a Pdp\Rules object

$domain = $rules->getICANNDomain('www.ulb.ac.be'); //$domain is a Pdp\Domain object
echo $domain->getContent(); // 'www.ulb.ac.be'
echo $domain->getPublicSuffix(); // 'ac.be'
echo $domain->getRegistrableDomain(); // 'ulb.ac.be'
Expand All @@ -67,24 +112,12 @@ $domain->isKnown(); // returns true
$domain->isICANN(); // returns true
$domain->isPrivate(); // returns false
$domain->labels(); // returns ['be', 'ac', 'ulb', 'www']
$publicSuffix = $rules->getPublicSuffix('mydomain.github.io', Rules::PRIVATE_DOMAINS); //$publicSuffix is a Pdp\PublicSuffix object
echo $publicSuffix->getContent(); // 'github.io'
$publicSuffix->isKnown(); // returns true
$publicSuffix->isICANN(); // returns false
$publicSuffix->isPrivate(); // returns true
$publicSuffix->labels(); // returns ['io', 'github']

$altSuffix = $rules->getPublicSuffix('mydomain.github.io', Rules::ICANN_DOMAINS);
echo $altSuffix->getContent(); // 'io'
$altSuffix->isKnown(); // returns true
$altSuffix->isICANN(); // returns true
$altSuffix->isPrivate(); // returns false

$tldList = $manager->getTLDs(); //$tldList is a Pdp\TopLevelDomains object

$tldList = TopLevelDomains::createFromPath('/path/to/IANA/RootZoneDatabase.txt'); //$tldList is a Pdp\TopLevelDomains object
$domain = $tldList->resolve('www.ulb.ac.be'); //$domain is a Pdp\Domain object
$tldList->contains('be'); //returns true
$tldList->contains('localhost'); //return false
foreach($tldList as $tld) {
foreach ($tldList as $tld) {
//$tld is a Pdp\PublisSuffix object
}
~~~
Expand All @@ -96,8 +129,7 @@ Using the above code you have parse, validate and resolve a domain name and its
**Before**

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

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

~~~php
$manager = new Manager(new Cache(), new CurlHttpClient());
$rules = $manager->getRules()
->withAsciiIDNAOption(IDNA_NONTRANSITIONAL_TO_ASCII)
->withUnicodeIDNAOption(IDNA_NONTRANSITIONAL_TO_UNICODE);

// or
//
// $rules = $manager->getRules(
// Manager::PSL_URL,
// null,
// IDNA_NONTRANSITIONAL_TO_ASCII,
// IDNA_NONTRANSITIONAL_TO_UNICODE
// );
$rules = Rules::createFromPath(
'/path/to/mozilla/public-suffix.dat',
null, // PHP resource context (see fopen context argument)
IDNA_NONTRANSITIONAL_TO_ASCII,
IDNA_NONTRANSITIONAL_TO_UNICODE
); //$rules is a Pdp\Rules object

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

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.
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.

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:

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

~~~php
$manager = new Pdp\Manager(new Pdp\Cache(), new Pdp\CurlHttpClient());
$tldCollection = $manager->getTLDs(self::RZD_URL);
$tldCollection = $manager->getTLDs(Pdp\Manager::RZD_URL);
$domain = $tldCollection->resolve('www.ulb.ac.be');
echo $domain->getPublicSuffix(); // print 'be'
~~~
Expand Down
36 changes: 30 additions & 6 deletions bin/update-psl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ use Pdp\Logger;
use Pdp\Installer;
use Pdp\Manager;

require dirname(__DIR__).'/vendor/autoload.php';
function get_vendor_path(): ?string
{
for ($i = 1; $i <= 5; $i++) {
$vendor = dirname(__DIR__, $i).'/vendor';
if (is_dir($vendor) && file_exists($vendor.'/autoload.php')) {
return $vendor;
}
}

return null;
}

function writeln(array $messages, $output): int
{
Expand All @@ -41,6 +51,20 @@ function fail(string $message, $output = STDERR): int
return writeln($messages, $output);
}

$vendor = get_vendor_path();
if (null === $vendor) {
$message = <<<TEXT
You must set up the project dependencies using composer
see https://getcomposer.org
TEXT;

fail($message);

die(1);
}

require $vendor.'/autoload.php';

/**
* CLI colors
*/
Expand Down Expand Up @@ -72,7 +96,7 @@ if (isset($arguments['help']) || isset($arguments['h'])) {
$helpText = <<<HELP
{$yellow}Usage:$reset
$script [options]
{$yellow}Options:$reset
$green --%s$reset refreshes the Public Suffix List cache
$green --%s=URL$reset set the URL to use to refresh the PSL cache ({$yellow}default:$reset %s)
Expand All @@ -84,15 +108,15 @@ if (isset($arguments['help']) || isset($arguments['h'])) {
{$yellow}Help:$reset
The {$green}update-psl$reset command updates your PDP local cache.
{$yellow}Examples:$reset
Refresh all caches using the default settings
$green$script$reset
Refresh only the PSL cache for a TTL of 3 DAY
Refresh only the PSL cache for a TTL of 3 DAY
$green$script --psl --ttl="3 DAYS"$reset
Refresh all caches using another cache directory
$green$script --cache-dir=/temp$reset
Expand Down
Loading

0 comments on commit 5130bad

Please sign in to comment.