1
1
#!/usr/bin/env php
2
2
<?php
3
3
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
+ */
5
14
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 );
0 commit comments