|
@@ -9,27 +9,12 @@ function removeIgnored(string $dir, array &$entries, array $ignore)
|
9
|
9
|
}
|
10
|
10
|
}
|
11
|
11
|
|
12
|
|
-function prioritySort(string $dir, array &$entries)
|
13
|
|
-{
|
14
|
|
- $first = array();
|
15
|
|
- foreach ($entries as $i => $entry) {
|
16
|
|
- if (isset($priority[$dir . '/' . $entry])) {
|
17
|
|
- array_push($first, $entry);
|
18
|
|
- unset($entries[$i]);
|
19
|
|
- }
|
20
|
|
- }
|
21
|
|
- sort($entries);
|
22
|
|
- foreach ($first as $entry) {
|
23
|
|
- array_unshift($entries, $entry);
|
24
|
|
- }
|
25
|
|
-}
|
26
|
|
-
|
27
|
12
|
function runDir(string $base, string $dir, array &$lines, array $ignore): int
|
28
|
13
|
{
|
29
|
14
|
$count = 0;
|
30
|
15
|
$entries = scandir($dir);
|
31
|
16
|
removeIgnored($dir, $entries, $ignore);
|
32
|
|
- prioritySort($dir, $entries);
|
|
17
|
+ sort($entries);
|
33
|
18
|
foreach ($entries as $entry) {
|
34
|
19
|
if ($entry === '.' || $entry === '..') {
|
35
|
20
|
continue;
|
|
@@ -46,13 +31,20 @@ function runDir(string $base, string $dir, array &$lines, array $ignore): int
|
46
|
31
|
continue;
|
47
|
32
|
}
|
48
|
33
|
$data = file_get_contents($filename);
|
49
|
|
- $data = preg_replace('|/\*\*.*?\*/|s', '', $data);
|
|
34
|
+ $data = trim(preg_replace('/\s*<\?php\s+/s', '', $data, 1));
|
50
|
35
|
array_push($lines, "// file: $dir/$entry");
|
51
|
36
|
foreach (explode("\n", $data) as $line) {
|
52
|
|
- if (!preg_match('/^<\?php|^namespace |^use |vendor\/autoload|declare\s*\(\s*strict_types\s*=\s*1|^\s*\/\//', $line)) {
|
53
|
|
- array_push($lines, $line);
|
|
37
|
+ if (preg_match('/vendor\/autoload|declare\s*\(\s*strict_types\s*=\s*1/', $line)) {
|
|
38
|
+ continue;
|
|
39
|
+ }
|
|
40
|
+ if ($line) {
|
|
41
|
+ $line = ' ' . $line;
|
54
|
42
|
}
|
|
43
|
+ $line = preg_replace('/^\s*(namespace[^;]+);/', '\1 {', $line);
|
|
44
|
+ array_push($lines, $line);
|
55
|
45
|
}
|
|
46
|
+ array_push($lines, '}');
|
|
47
|
+ array_push($lines, '');
|
56
|
48
|
$count++;
|
57
|
49
|
}
|
58
|
50
|
}
|
|
@@ -75,8 +67,6 @@ function addHeader(array &$lines)
|
75
|
67
|
* https://github.com/Nyholm
|
76
|
68
|
**/
|
77
|
69
|
|
78
|
|
-namespace Tqdev\PhpCrudApi;
|
79
|
|
-
|
80
|
70
|
EOF;
|
81
|
71
|
foreach (explode("\n", $head) as $line) {
|
82
|
72
|
array_push($lines, $line);
|