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
+ $ 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 );
0 commit comments