| [ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 require_once 'phing/Task.php'; 3 4 /** 5 * A PHP lint task. Checking syntax of one or more PHP source file. 6 * 7 * @author Knut Urdalen <knut.urdalen@telio.no> 8 * @package phing.tasks.ext 9 */ 10 class PhpLintTask extends Task { 11 12 protected $file; // the source file (from xml attribute) 13 protected $filesets = array(); // all fileset objects assigned to this task 14 15 /** 16 * File to be performed syntax check on 17 * @param PhingFile $file 18 */ 19 public function setFile(PhingFile $file) { 20 $this->file = $file; 21 } 22 23 /** 24 * Nested creator, creates a FileSet for this task 25 * 26 * @return FileSet The created fileset object 27 */ 28 function createFileSet() { 29 $num = array_push($this->filesets, new FileSet()); 30 return $this->filesets[$num-1]; 31 } 32 33 /** 34 * Execute lint check against PhingFile or a FileSet 35 */ 36 public function main() { 37 if(!isset($this->file) and count($this->filesets) == 0) { 38 throw new BuildException("Missing either a nested fileset or attribute 'file' set"); 39 } 40 41 if($this->file instanceof PhingFile) { 42 $this->lint($this->file->getPath()); 43 } else { // process filesets 44 $project = $this->getProject(); 45 foreach($this->filesets as $fs) { 46 $ds = $fs->getDirectoryScanner($project); 47 $files = $ds->getIncludedFiles(); 48 $dir = $fs->getDir($this->project)->getPath(); 49 foreach($files as $file) { 50 $this->lint($dir.DIRECTORY_SEPARATOR.$file); 51 } 52 } 53 } 54 } 55 56 /** 57 * Performs the actual syntax check 58 * 59 * @param string $file 60 * @return void 61 */ 62 protected function lint($file) { 63 $command = 'php -l '; 64 if(file_exists($file)) { 65 if(is_readable($file)) { 66 $message = array(); 67 exec($command.$file, $message); 68 if(!preg_match('/^No syntax errors detected/', $message[0])) { 69 $this->log($message[1], PROJECT_MSG_ERR); 70 } else { 71 $this->log($file.': No syntax errors detected', PROJECT_MSG_INFO); 72 } 73 } else { 74 throw new BuildException('Permission denied: '.$file); 75 } 76 } else { 77 throw new BuildException('File not found: '.$file); 78 } 79 } 80 } 81 82 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |