Skip to content

Commit 100ca00

Browse files
authored
Merge pull request #250 from jeremykendall/feature/poc-new-installer
#249 improving the update-psl script
2 parents f6502aa + c7704e6 commit 100ca00

10 files changed

+536
-68
lines changed

.php_cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ file that was distributed with this source code.
1212
EOF;
1313

1414
$finder = PhpCsFixer\Finder::create()
15+
->in(__DIR__.'/bin')
1516
->in(__DIR__.'/src')
1617
->in(__DIR__.'/tests')
1718
;
@@ -55,4 +56,4 @@ return PhpCsFixer\Config::create()
5556
'whitespace_after_comma_in_array' => true,
5657
])
5758
->setFinder($finder)
58-
;
59+
;

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ matrix:
4242
env:
4343
- COLLECT_COVERAGE=false
4444
- IGNORE_PLATFORMS=true
45-
- RUN_PHPSTAN=true
45+
- RUN_PHPSTAN=false
4646
- VALIDATE_CODING_STYLE=false
4747
allow_failures:
4848
- php: 7.4snapshot
@@ -66,4 +66,4 @@ script:
6666
- composer phpunit
6767

6868
after_script:
69-
- 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
69+
- 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

bin/update-psl

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,135 @@
11
#!/usr/bin/env php
22
<?php
33

4-
require dirname(__DIR__).'/src/Installer.php';
4+
/**
5+
* PHP Domain Parser: Public Suffix List based URL parsing.
6+
*
7+
* @see http://github.com/jeremykendall/php-domain-parser for the canonical source repository
8+
*
9+
* @copyright Copyright (c) 2017 Jeremy Kendall (http://jeremykendall.net)
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
514

6-
Pdp\Installer::updateLocalCache();
15+
declare(strict_types=1);
16+
17+
use Pdp\Logger;
18+
use Pdp\Installer;
19+
use Pdp\Manager;
20+
21+
require dirname(__DIR__).'/vendor/autoload.php';
22+
23+
function writeln(array $messages, $output): int
24+
{
25+
$message = implode(PHP_EOL, $messages). PHP_EOL;
26+
27+
return fwrite($output, $message);
28+
}
29+
30+
function success(string $message, $output = STDOUT): int
31+
{
32+
$messages = (array) $message;
33+
34+
return writeln($messages, $output);
35+
}
36+
37+
function fail(string $message, $output = STDERR): int
38+
{
39+
$messages = (array) $message;
40+
41+
return writeln($messages, $output);
42+
}
43+
44+
/**
45+
* CLI colors
46+
*/
47+
$cyan = chr(27)."[36m";
48+
$green = chr(27)."[32m";
49+
$reset = chr(27)."[0m";
50+
$redbg = chr(27)."[41m";
51+
$yellow = chr(27)."[33m";
52+
53+
$arguments = array_replace([
54+
Installer::CACHE_DIR_KEY => '',
55+
Installer::REFRESH_PSL_KEY => false,
56+
Installer::REFRESH_RZD_KEY => false,
57+
Installer::TTL_KEY => '1 DAY',
58+
], getopt('h::', [
59+
'h',
60+
'help',
61+
Installer::CACHE_DIR_KEY.':',
62+
Installer::REFRESH_PSL_KEY,
63+
Installer::REFRESH_PSL_URL_KEY.':',
64+
Installer::REFRESH_RZD_KEY,
65+
Installer::REFRESH_RZD_URL_KEY.':',
66+
Installer::TTL_KEY.':',
67+
]));
68+
69+
if (isset($arguments['help']) || isset($arguments['h'])) {
70+
$default_cache_dir = dirname(__DIR__).'/data';
71+
$script = basename(__FILE__);
72+
$helpText = <<<HELP
73+
{$yellow}Usage:$reset
74+
$script [options]
75+
76+
{$yellow}Options:$reset
77+
$green --%s$reset refreshes the Public Suffix List cache
78+
$green --%s=URL$reset set the URL to use to refresh the PSL cache ({$yellow}default:$reset %s)
79+
$green --%s$reset refreshes the IANA Root Zone Database cache
80+
$green --%s=URL$reset set the URL to use to refresh the RZD cache ({$yellow}default:$reset %s)
81+
$green --%s=TTL$reset set the TTL for the cache ({$yellow}default:$reset '1 DAY')
82+
$green --%s=CACHE-DIR$reset set the cache root directory ({$yellow}default:$reset $default_cache_dir')
83+
$green-h, --help$reset show the following help message
84+
85+
{$yellow}Help:$reset
86+
The {$green}update-psl$reset command updates your PDP local cache.
87+
88+
{$yellow}Examples:$reset
89+
90+
Refresh all caches using the default settings
91+
$green$script$reset
92+
93+
Refresh only the PSL cache for a TTL of 3 DAY
94+
$green$script --psl --ttl="3 DAYS"$reset
95+
96+
Refresh all caches using another cache directory
97+
$green$script --cache-dir=/temp$reset
98+
99+
Read more at https://github.com/jeremykendall/php-domain-parser/
100+
101+
HELP;
102+
103+
$helpText = sprintf($helpText,
104+
Installer::REFRESH_PSL_KEY,
105+
Installer::REFRESH_PSL_URL_KEY,
106+
Manager::PSL_URL,
107+
Installer::REFRESH_RZD_KEY,
108+
Installer::REFRESH_RZD_URL_KEY,
109+
Manager::RZD_URL,
110+
Installer::TTL_KEY,
111+
Installer::CACHE_DIR_KEY
112+
);
113+
114+
success($helpText);
115+
116+
die(0);
117+
}
118+
119+
if (!extension_loaded('curl')) {
120+
fail("$redbg The required PHP cURL extension is missing. $reset");
121+
122+
die(1);
123+
}
124+
125+
$installer = Installer::createFromCacheDir(new Logger( STDOUT, STDERR), $arguments[Installer::CACHE_DIR_KEY]);
126+
success("$yellow Updating your Pdp local cache.$reset");
127+
if ($installer->refresh($arguments)) {
128+
success("$green Pdp local cache successfully updated. $reset");
129+
130+
die(0);
131+
}
132+
133+
fail("$redbg The command failed to update Pdp local cache successfully. $reset");
134+
135+
die(1);

composer.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@
3636
"require": {
3737
"php": ">=7.0",
3838
"ext-intl": "*",
39+
"psr/log": "^1.1",
3940
"psr/simple-cache": "^1.0.1"
4041
},
4142
"require-dev": {
4243
"composer/composer": "^1.6",
4344
"friendsofphp/php-cs-fixer": "^2.7",
44-
"mikey179/vfsStream": "^1.6",
45+
"mikey179/vfsstream": "^1.6",
4546
"phpstan/phpstan": "^0.9.2",
4647
"phpstan/phpstan-phpunit": "^0.9.4",
4748
"phpstan/phpstan-strict-rules": "^0.9.0",
@@ -63,9 +64,9 @@
6364
}
6465
},
6566
"scripts": {
66-
"phpcs": "php-cs-fixer fix -vv --diff --dry-run --allow-risky=yes",
67-
"phpstan-src": "phpstan analyse -l max -c phpstan.src.neon src",
68-
"phpstan-tests": "phpstan analyse -l max -c phpstan.tests.neon tests",
67+
"phpcs": "php-cs-fixer fix -vvv --diff --dry-run --allow-risky=yes --ansi",
68+
"phpstan-src": "phpstan analyse -l max -c phpstan.src.neon src --ansi",
69+
"phpstan-tests": "phpstan analyse -l max -c phpstan.tests.neon tests --ansi",
6970
"phpstan": [
7071
"@phpstan-src",
7172
"@phpstan-tests"
@@ -79,6 +80,14 @@
7980
"@phpunit"
8081
]
8182
},
83+
"scripts-descriptions": {
84+
"phpcs": "Runs coding style test suite",
85+
"phpstan": "Runs complete codebase static analysis",
86+
"phpstan-src": "Runs PHP stan on the source code",
87+
"phpstan-test": "Runs PHP stan on the test suite",
88+
"phpunit": "Runs unit and functional testing",
89+
"test": "Runs the complete test suite"
90+
},
8291
"extra": {
8392
"branch-alias": {
8493
"dev-master": "5.x-dev"

data/pdp-PSL_FULL_5a3cc7f81795bb2e48e848af42d287b4.cache

100755100644
Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

data/pdp-RZD_FULL_f18a70477d29d525b9220612e2115345.cache

100755100644
Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

phpunit.xml.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
<whitelist>
2222
<directory suffix=".php">src</directory>
2323
<exclude>
24-
<directory suffix="Installer.php">src</directory>
2524
<directory suffix="include.php">src</directory>
2625
</exclude>
2726
<exclude>src/Installer</exclude>

0 commit comments

Comments
 (0)