예제 #1
0
 /**
  * Lint file contents
  *
  * If issues with the passed file are found the function will return an 
  * array with the found issues, and an empty array otherwise.
  * 
  * @param string $file 
  * @param string $contents 
  * @return array
  */
 public function lint($file, $contents)
 {
     $check = new pbsSystemProcess('/usr/bin/env');
     $check->argument('sievec');
     // Write contents into temporary file, since sievec is not able to read
     // from STDIN
     $tempFileName = tempnam(sys_get_temp_dir(), 'sieve');
     file_put_contents($tempFileName, stream_get_contents($contents));
     $check->argument($tempFileName);
     $check->execute();
     unlink($tempFileName);
     if ($check->stderrOutput !== '') {
         $message = str_replace(array($tempFileName, basename($tempFileName)), array($file, $file), $check->stderrOutput);
         return array(new pchIssue(E_ERROR, $file, null, $message));
     }
     return array();
 }
예제 #2
0
 /**
  * Lint file contents
  *
  * If issues with the passed file are found the function will return an 
  * array with the found issues, and an empty array otherwise.
  * 
  * @param string $file 
  * @param string $contents 
  * @return array
  */
 public function lint($file, $contents)
 {
     $check = new pbsSystemProcess('/usr/bin/env');
     $check->argument('php')->argument('-l');
     // Run process asynchronously to pipe file contents into it
     $pipes = $check->execute(true);
     fwrite($pipes[0], stream_get_contents($contents));
     fclose($pipes[0]);
     $output = stream_get_contents($pipes[1]);
     $errors = stream_get_contents($pipes[2]);
     if ($check->close()) {
         // An error occured, transform return contents except for the last
         // line into an issue object
         $message = implode("\n", array_slice(preg_split('(\\r\\n|\\r|\\n)', trim($output)), 0, -1));
         return array(new pchIssue(E_ERROR, $file, null, $message));
     }
     return array();
 }