Skip to content

Commit 6315245

Browse files
committed
#249 improving the update-psl script
1 parent 6ee23b3 commit 6315245

9 files changed

+494
-82
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+
;

bin/update-psl

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,125 @@
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+
$script = basename(__FILE__);
54+
$helpText = <<<HELP
55+
$yellow
56+
Pdp\Installer v1.0 $reset
57+
58+
The following script updates your local cache to ease library usage.
59+
=====
60+
61+
Usage: $yellow$script [OPTIONS]$reset
62+
63+
$green--%s$reset refreshes the Public Suffix List cache
64+
$green--%s$reset set the URL to use to refresh the PSL cache ({$yellow}default:$reset %s)
65+
$green--%s$reset refreshes the IANA Root Zone Database cache
66+
$green--%s$reset set the URL to use to refresh the RZD cache ({$yellow}default:$reset %s)
67+
$green--%s$reset set the TTL for the cache ({$yellow}default:$reset '1 DAY')
68+
$green--%s$reset set the cache root directory
69+
$green-h, --help$reset show the following help message
70+
71+
Examples:
72+
73+
Refresh all caches using the default settings
74+
$yellow$script$reset
75+
76+
Refresh the PSL cache for a TTL of 3 DAY
77+
$yellow$script --psl --ttl="3 DAYS"$reset
78+
79+
Refresh the cache located in another cache directory
80+
$yellow$script --cache-dir=/temp$reset
81+
HELP;
82+
83+
$helpText = sprintf($helpText,
84+
Installer::REFRESH_PSL_KEY,
85+
Installer::REFRESH_PSL_URL_KEY,
86+
Manager::PSL_URL,
87+
Installer::REFRESH_RZD_KEY,
88+
Installer::REFRESH_RZD_URL_KEY,
89+
Manager::RZD_URL,
90+
Installer::TTL_KEY,
91+
Installer::CACHE_DIR_KEY
92+
);
93+
94+
$arguments = array_replace([
95+
Installer::CACHE_DIR_KEY => '',
96+
Installer::REFRESH_PSL_KEY => false,
97+
Installer::REFRESH_RZD_KEY => false,
98+
Installer::TTL_KEY => '1 DAY',
99+
], getopt('h::', [
100+
'h',
101+
'help',
102+
Installer::CACHE_DIR_KEY.':',
103+
Installer::REFRESH_PSL_KEY,
104+
Installer::REFRESH_PSL_URL_KEY.':',
105+
Installer::REFRESH_RZD_KEY,
106+
Installer::REFRESH_RZD_URL_KEY.':',
107+
Installer::TTL_KEY.':',
108+
]));
109+
110+
if (isset($arguments['help']) || isset($arguments['h'])) {
111+
success($helpText);
112+
113+
die(0);
114+
}
115+
116+
if (!extension_loaded('curl')) {
117+
fail("$redbg The PHP cURL extension is missing. $reset");
118+
119+
die(1);
120+
}
121+
122+
$installer = Installer::createFromCacheDir(new Logger( STDOUT, STDERR), $arguments[Installer::CACHE_DIR_KEY]);
123+
$retVal = $installer->refresh($arguments);
124+
125+
die($retVal);

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 -v --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 source code static analysis",
87+
"phpstan-test": "Runs test suite static analysis",
88+
"phpunit": "Runs unit and functional testing",
89+
"test": "Runs full 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)