26
26
exit (1 );
27
27
}
28
28
29
- $ newFileContent = []; // new file content
30
- $ insertDone = false ; // becomes 'true' when we find start of $validTlds declaration
31
- $ insertFinish = false ; // becomes 'true' when we find end of $validTlds declaration
32
- $ checkOnly = isset ($ argv [1 ]) ? $ argv [1 ] === '--check-only ' : false ;
33
-
34
- $ response = getOfficialTLDs ();
35
-
36
- $ ianaVersion = getVersionFromString ('Version ' , strtok ($ response ->getBody (), "\n" ));
29
+ $ newFileContent = []; // new file content
30
+ $ insertDone = false ; // becomes 'true' when we find start of $validTlds declaration
31
+ $ insertFinish = false ; // becomes 'true' when we find end of $validTlds declaration
32
+ $ checkOnly = isset ($ argv [1 ]) ? $ argv [1 ] === '--check-only ' : false ;
33
+ $ response = getOfficialTLDs ();
34
+ $ ianaVersion = getVersionFromString ('Version ' , strtok ($ response ->getBody (), "\n" ));
37
35
$ validatorVersion = getVersionFromString ('IanaVersion ' , file_get_contents (ZF2_HOSTNAME_VALIDATOR_FILE ));
38
36
39
- if ($ ianaVersion > $ validatorVersion && $ checkOnly ) {
40
- printf ('TLDs must be updated, please run `php bin/update_hostname_validator.php` and push your changes%s ' , PHP_EOL );
37
+ if ($ checkOnly && $ ianaVersion > $ validatorVersion ) {
38
+ printf (
39
+ 'TLDs must be updated, please run `php bin/update_hostname_validator.php` and push your changes%s ' ,
40
+ PHP_EOL
41
+ );
41
42
exit (1 );
42
43
}
43
44
44
45
if ($ checkOnly ) {
45
- printf ('TLDs are up to date%s ' , PHP_EOL );
46
+ printf ('TLDs are up-to- date%s ' , PHP_EOL );
46
47
exit (0 );
47
48
}
48
49
55
56
56
57
if ($ insertDone === $ insertFinish ) {
57
58
// Outside of $validTlds definition; keep line as-is
58
- $ newFileContent [] = $ line ;
59
+ $ newFileContent[] = $ line ;
59
60
}
60
61
61
62
if ($ insertFinish ) {
65
66
if ($ insertDone ) {
66
67
// Detect where the $validTlds declaration ends
67
68
if (preg_match ('/^\s+\];\s*$/ ' , $ line )) {
68
- $ newFileContent [] = $ line ;
69
- $ insertFinish = true ;
69
+ $ newFileContent[] = $ line ;
70
+ $ insertFinish = true ;
70
71
}
71
72
72
73
continue ;
75
76
// Detect where the $validTlds declaration begins
76
77
if (preg_match ('/^\s+protected\s+\$validTlds\s+=\s+\[\s*$/ ' , $ line )) {
77
78
$ newFileContent = array_merge ($ newFileContent , getNewValidTlds ($ response ->getBody ()));
78
- $ insertDone = true ;
79
+ $ insertDone = true ;
79
80
}
80
81
}
81
82
82
83
if (! $ insertDone ) {
83
- printf (" Error: cannot find line with ' protected \ $validTlds'%s " , PHP_EOL );
84
+ printf (' Error: cannot find line with " protected $validTlds"%s ' , PHP_EOL );
84
85
exit (1 );
85
86
}
86
87
87
88
if (!$ insertFinish ) {
88
- printf (" Error: cannot find end of \ $validTlds declaration%s " , PHP_EOL );
89
+ printf (' Error: cannot find end of $validTlds declaration%s ' , PHP_EOL );
89
90
exit (1 );
90
91
}
91
92
92
93
if (false === @file_put_contents (ZF2_HOSTNAME_VALIDATOR_FILE , $ newFileContent )) {
93
- printf (" Error: cannot write info file '%s'%s " , ZF2_HOSTNAME_VALIDATOR_FILE , PHP_EOL );
94
+ printf (' Error: cannot write info file "%s"%s ' , ZF2_HOSTNAME_VALIDATOR_FILE , PHP_EOL );
94
95
exit (1 );
95
96
}
96
97
@@ -111,6 +112,7 @@ function getOfficialTLDs()
111
112
]);
112
113
$ client ->setUri (IANA_URL );
113
114
$ client ->setMethod ('GET ' );
115
+
114
116
$ response = $ client ->send ();
115
117
if (! $ response ->isSuccess ()) {
116
118
throw new \Exception (sprintf ("Error: cannot get '%s'%s " , IANA_URL , PHP_EOL ));
@@ -130,8 +132,8 @@ function getOfficialTLDs()
130
132
function getVersionFromString ($ prefix , $ string )
131
133
{
132
134
$ matches = [];
133
- if (!preg_match (sprintf ('/%s\s+((\d+)?)/ ' , $ prefix ), $ string , $ matches )) {
134
- throw new \ Exception ('Error: cannot get last update date ' );
135
+ if (! preg_match (sprintf ('/%s\s+((\d+)?)/ ' , $ prefix ), $ string , $ matches )) {
136
+ throw new Exception ('Error: cannot get last update date ' );
135
137
}
136
138
137
139
return $ matches [1 ];
@@ -179,13 +181,13 @@ function getPunycodeDecoder()
179
181
}
180
182
181
183
$ hostnameValidator = new Hostname ();
182
- $ reflection = new ReflectionClass (get_class ($ hostnameValidator ));
183
- $ method = $ reflection ->getMethod ('decodePunycode ' );
184
- $ method ->setAccessible (true );
184
+ $ reflection = new ReflectionClass (get_class ($ hostnameValidator ));
185
+ $ decodePunyCode = $ reflection ->getMethod ('decodePunycode ' );
186
+ $ decodePunyCode ->setAccessible (true );
185
187
186
- return function ($ encode ) use ($ hostnameValidator , $ method ) {
188
+ return function ($ encode ) use ($ hostnameValidator , $ decodePunyCode ) {
187
189
if (strpos ($ encode , 'xn-- ' ) === 0 ) {
188
- return $ method ->invokeArgs ($ hostnameValidator , [substr ($ encode , 4 )]);
190
+ return $ decodePunyCode ->invokeArgs ($ hostnameValidator , [substr ($ encode , 4 )]);
189
191
}
190
192
return $ encode ;
191
193
};
0 commit comments