-
Notifications
You must be signed in to change notification settings - Fork 1
/
format-all.php
executable file
·40 lines (35 loc) · 1.1 KB
/
format-all.php
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
#!/usr/bin/env php
<?php
//pre-commit checks
//execute a command and check for return values
function setup_exec($cmd, $return_out = false) {
$ret = 0;
$out = array();
$cmd .= " 2>&1";
printf("Launching %s\n", $cmd);
exec($cmd, $out, $ret);
if ($ret != 0) {
echo "-----\n" . implode("\n", $out) . "\n-----\n";
printf("'%s' failed. Aborting hook.\n", $cmd);
throw new Exception("");
}
if ($return_out)
return $out;
}
//always use the same basedir
$scriptloc = realpath(dirname(__FILE__)) . "/";
//format and check code
$exit = 0;
try {
$files = array();
$ret = setup_exec("find " . escapeshellarg($scriptloc) . " -maxdepth 1 -type f -name \"*.php\"", true);
$files = array_merge($files, $ret);
$ret = setup_exec("find " . escapeshellarg($scriptloc . "ftpfs/") . " -maxdepth 1 -type f -name \"*.php\"", true);
$files = array_merge($files, $ret);
foreach ($files as $file)
setup_exec("cd " . escapeshellarg($scriptloc) . " && ./format.php " . escapeshellarg($file));
}
catch (Exception $e) {
$exit = 1;
}
exit($exit);