Maurits van der Schee 5 years ago
parent
commit
5c8a09d99b
1 changed files with 49 additions and 0 deletions
  1. 49
    0
      patch.php

+ 49
- 0
patch.php View File

@@ -0,0 +1,49 @@
1
+<?php
2
+
3
+function runDir(string $base, string $dir): int
4
+{
5
+    $count = 0;
6
+    $entries = scandir($dir);
7
+    foreach ($entries as $entry) {
8
+        if ($entry === '.' || $entry === '..') {
9
+            continue;
10
+        }
11
+        $filename = "$base/$dir/$entry";
12
+        if (is_dir($filename)) {
13
+            $count += runDir($base, "$dir/$entry");
14
+        }
15
+    }
16
+    foreach ($entries as $entry) {
17
+        $filename = "$base/$dir/$entry";
18
+        if (is_file($filename)) {
19
+            if (substr($entry, -4) != '.php') {
20
+                continue;
21
+            }
22
+            $patched = $original = file_get_contents($filename);
23
+            $patched = preg_replace('/\):\s*(\?[a-zA-Z]+|void)\s*\n/', ") /*:$1*/\n", $patched);
24
+            $patched = preg_replace('/private const/', "/*private*/ const", $patched);
25
+            if ($patched && $patched != $original) {
26
+                echo "$filename\n";
27
+                file_put_contents($filename, $patched);
28
+                $count++;
29
+            }
30
+        }
31
+    }
32
+    return $count;
33
+}
34
+
35
+function run(string $base, array $dirs)
36
+{
37
+    $start = microtime(true);
38
+    $count = 0;
39
+    foreach ($dirs as $dir) {
40
+        $count += runDir($base, $dir);
41
+    }
42
+    $end = microtime(true);
43
+    $time = ($end - $start) * 1000;
44
+    if ($count) {
45
+        echo sprintf("%d files patched in %d ms\n", $count, $time);
46
+    }
47
+}
48
+
49
+run(__DIR__, ['vendor']);

Loading…
Cancel
Save