-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp_syntax_checker.php
More file actions
46 lines (41 loc) · 890 Bytes
/
Copy pathphp_syntax_checker.php
File metadata and controls
46 lines (41 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* @param string $pDir
* @param callable $callback
* @param array $exceptions
* @return void
*/
function rscanr_callback(string $pDir = ".", callable $callback, array $exceptions = []): void
{
foreach ($exceptions as &$exception) {
$exception = realpath($exception);
}
unset($exception);
$s = scandir($pDir);
unset($s[0], $s[1]);
foreach ($s as $v) {
$v = realpath($pDir."/".$v);
if (!in_array($v, $exceptions)) {
$callback($v);
if (is_dir($v)) {
rscanr_callback($v, $callback);
}
}
}
}
rscanr_callback(__DIR__, function (string $f) {
if (strtolower(substr($f, -4)) === ".php") {
$time = time();
$sh = shell_exec("php -l ".escapeshellarg($f)." || echo std_error_{$time}");
if (preg_match("/std_error_{$time}/", $sh)) {
print "\n\nSyntax Error Detected\n";
exit(1);
} else {
print $sh;
}
}
},
[
__DIR__."/vendor"
]
);