forked from SimpleMachines/BuildTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-php-syntax.php
More file actions
executable file
·67 lines (56 loc) · 1.79 KB
/
check-php-syntax.php
File metadata and controls
executable file
·67 lines (56 loc) · 1.79 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2021 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 2.1 RC3
*/
// Stuff we will ignore.
$ignoreFiles = array(
);
/* This is mostly meant for local usage.
To add additional PHP Binaries, create a check-php-syntax-binaries.txt
Add in this in each line the binary file, i.e: /usr/bin/php
*/
$addditionalPHPBinaries = array();
if (file_exists(dirname(__FILE__) . '/check-php-syntax-binaries.txt'))
$addditionalPHPBinaries = file(dirname(__FILE__) . '/check-php-syntax-binaries.txt');
$curDir = '.';
if (isset($_SERVER['argv'], $_SERVER['argv'][1]))
$curDir = $_SERVER['argv'][1];
$foundBad = false;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($curDir, FilesystemIterator::UNIX_PATHS)) as $currentFile => $fileInfo)
{
// Only check PHP
if ($fileInfo->getExtension() !== 'php')
continue;
foreach ($ignoreFiles as $if)
if (preg_match('~' . $if . '~i', $currentFile))
continue 2;
# Always check against the base.
$result = trim(shell_exec('php -l ' . $currentFile));
if (!preg_match('~No syntax errors detected in ' . $currentFile . '~', $result))
{
$foundBad = true;
fwrite(STDERR, 'PHP via $PATH: ' . $result . "\n");
continue;
}
// We have additional binaries we want to test against?
foreach ($addditionalPHPBinaries as $binary)
{
$binary = trim($binary);
$result = trim(shell_exec($binary . ' -l ' . $currentFile));
if (!preg_match('~No syntax errors detected in ' . $currentFile . '~', $result))
{
$foundBad = true;
fwrite(STDERR, 'PHP via ' . $binary . ': ' . $result . "\n");
continue 2;
}
}
}
if (!empty($foundBad))
exit(1);