@@ -31,8 +31,9 @@ function processStubFile(string $stubFile, Context $context) {
31
31
throw new Exception ("File $ stubFile does not exist " );
32
32
}
33
33
34
- $ arginfoFile = str_replace ('.stub.php ' , '' , $ stubFile )
35
- . ($ context ->legacy ? '_legacy ' : '' ) . '_arginfo.h ' ;
34
+ $ arginfoFile = str_replace ('.stub.php ' , '_arginfo.h ' , $ stubFile );
35
+ $ legacyFile = str_replace ('.stub.php ' , '_legacy_arginfo.h ' , $ stubFile );
36
+
36
37
$ stubCode = file_get_contents ($ stubFile );
37
38
$ stubHash = computeStubHash ($ stubCode );
38
39
$ oldStubHash = extractStubHash ($ arginfoFile );
@@ -43,14 +44,20 @@ function processStubFile(string $stubFile, Context $context) {
43
44
44
45
initPhpParser ();
45
46
$ fileInfo = parseStubFile ($ stubCode );
46
- if ($ context ->legacy ) {
47
+ $ arginfoCode = generateArgInfoCode ($ fileInfo , $ stubHash );
48
+ if (file_put_contents ($ arginfoFile , $ arginfoCode )) {
49
+ echo "Saved $ arginfoFile \n" ;
50
+ }
51
+
52
+ if (file_exists ($ legacyFile )) {
47
53
foreach ($ fileInfo ->getAllFuncInfos () as $ funcInfo ) {
48
54
$ funcInfo ->discardInfoForOldPhpVersions ();
49
55
}
50
- }
51
-
52
- $ arginfoCode = generateArgInfoCode ($ fileInfo , $ stubHash );
53
- file_put_contents ($ arginfoFile , $ arginfoCode );
56
+ $ arginfoCode = generateArgInfoCode ($ fileInfo , $ stubHash );
57
+ if (file_put_contents ($ legacyFile , $ arginfoCode )) {
58
+ echo "Saved $ legacyFile \n" ;
59
+ }
60
+ }
54
61
55
62
// Collect parameter name statistics.
56
63
foreach ($ fileInfo ->getAllFuncInfos () as $ funcInfo ) {
@@ -1220,14 +1227,17 @@ function initPhpParser() {
1220
1227
}
1221
1228
1222
1229
$ optind = null ;
1223
- $ options = getopt ("f " , ["force-regeneration " , "parameter-stats " , "legacy " ], $ optind );
1230
+ $ options = getopt ("fh " , ["force-regeneration " , "parameter-stats " , "help " ], $ optind );
1224
1231
1225
1232
$ context = new Context ;
1226
1233
$ printParameterStats = isset ($ options ["parameter-stats " ]);
1227
- $ context ->legacy = isset ($ options ["legacy " ]);
1228
1234
$ context ->forceRegeneration =
1229
1235
isset ($ options ["f " ]) || isset ($ options ["force-regeneration " ]) || $ printParameterStats ;
1230
1236
1237
+ if (isset ($ options ["h " ]) || isset ($ options ["help " ])) {
1238
+ die ("\nusage: gen-stub.php [ -f | --force-regeneration ] [ --parameter-stats ] [ -h | --help ] [ name.stub.php | directory ] \n\n" );
1239
+ }
1240
+
1231
1241
$ location = $ argv [$ optind ] ?? ". " ;
1232
1242
if (is_file ($ location )) {
1233
1243
// Generate single file.
0 commit comments