12
12
13
13
error_reporting (E_ALL );
14
14
15
- function processDirectory (string $ dir ) {
15
+ function processDirectory (string $ dir, bool $ forceRegeneration ) {
16
16
$ it = new RecursiveIteratorIterator (
17
17
new RecursiveDirectoryIterator ($ dir ),
18
18
RecursiveIteratorIterator::LEAVES_ONLY
19
19
);
20
20
foreach ($ it as $ file ) {
21
21
$ pathName = $ file ->getPathName ();
22
22
if (preg_match ('/\.stub\.php$/ ' , $ pathName )) {
23
- processStubFile ($ pathName );
23
+ processStubFile ($ pathName, $ forceRegeneration );
24
24
}
25
25
}
26
26
}
27
27
28
- function processStubFile (string $ stubFile ) {
28
+ function processStubFile (string $ stubFile, bool $ forceRegeneration ) {
29
29
try {
30
30
if (!file_exists ($ stubFile )) {
31
31
throw new Exception ("File $ stubFile does not exist " );
@@ -35,7 +35,7 @@ function processStubFile(string $stubFile) {
35
35
$ stubCode = file_get_contents ($ stubFile );
36
36
$ stubHash = computeStubHash ($ stubCode );
37
37
$ oldStubHash = extractStubHash ($ arginfoFile );
38
- if ($ stubHash === $ oldStubHash ) {
38
+ if ($ stubHash === $ oldStubHash && $ forceRegeneration === false ) {
39
39
/* Stub file did not change, do not regenerate. */
40
40
return ;
41
41
}
@@ -1093,17 +1093,17 @@ function initPhpParser() {
1093
1093
});
1094
1094
}
1095
1095
1096
- if ( $ argc >= 2 ) {
1097
- if ( is_file ( $ argv [ 1 ])) {
1098
- // Generate single file.
1099
- processStubFile ( $ argv [1 ]) ;
1100
- } else if ( is_dir ( $ argv [ 1 ])) {
1101
- processDirectory ( $ argv [ 1 ]);
1102
- } else {
1103
- echo " $ argv [ 1 ] is neither a file nor a directory. \n" ;
1104
- exit ( 1 );
1105
- }
1096
+ $ optind = null ;
1097
+ $ options = getopt ( " f " , [ " force-regeneration " ], $ optind );
1098
+ $ forceRegeneration = isset ( $ options [ " f " ]) || isset ( $ options [ " force-regeneration " ]);
1099
+ $ location = $ argv [$ optind + 1 ] ?? " . " ;
1100
+
1101
+ if ( is_file ( $ location )) {
1102
+ // Generate single file.
1103
+ processStubFile ( $ location , $ forceRegeneration ) ;
1104
+ } else if ( is_dir ( $ location )) {
1105
+ processDirectory ( $ location , $ forceRegeneration );
1106
1106
} else {
1107
- // Regenerate all stub files we can find.
1108
- processDirectory ( ' . ' );
1107
+ echo " $ location is neither a file nor a directory. \n" ;
1108
+ exit ( 1 );
1109
1109
}
0 commit comments