2 require_once 'MTrack/Interface/CommitListener.php';
4 class MTrackCommitCheck_PhpLint implements IMTrackCommitListener
7 function vetoCommit($msg, $files, $actions, $checker)
9 // should only have a list of files which have been updated/added. (not deleted)
12 if (count($files) > 30) {
13 // to many files.. we can not check that amount without causing serious delays in commits
16 foreach ($files as $filename) {
17 $pi = pathinfo($filename);
19 if ( $pi['extension'] == 'php') {
20 $fp = $checker->bridge->getFileStream($filename);
21 $res = $this->checkPHP($filename, $fp);
25 $fp = null; // remove stream.
30 return $ret ? implode("\n", $ret) : true;
33 function postCommit($msg, $files, $actions)
37 function checkPHP($filename, $fp)
40 $proc = proc_open(MTrackConfig::get('tools', 'php') . " -l", array(
41 0 => array('pipe', 'r'),
42 1 => array('pipe', 'w'),
43 2 => array('pipe', 'w')
47 stream_copy_to_stream($fp, $pipes[0]);
51 $output = stream_get_contents($pipes[1]);
52 $output .= stream_get_contents($pipes[2]);
53 $st = proc_get_status($proc);
55 proc_terminate($proc);
57 $st = proc_get_status($proc);
59 if ($st['exitcode'] != 0) {
60 return "$filename: $output";