Changeset 23

Show
Ignore:
Timestamp:
02/14/06 16:12:46 (3 years ago)
Author:
mrook
Message:

Improve the Echo task with file output functionality like Ant's Echo task

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/classes/phing/tasks/system/EchoTask.php

    r1 r23  
    2323 
    2424/** 
    25  *  Echos a message to all output devices 
     25 *  Echos a message to the logging system or to a file 
    2626 * 
     27 *  @author   Michiel Rook <michiel@trendserver.nl> 
    2728 *  @author   Andreas Aderhold, andi@binarycloud.com 
    2829 *  @version  $Revision: 1.5 $ $Date: 2003/12/24 13:02:09 $ 
     
    3132 
    3233class EchoTask extends Task { 
     34         
     35    protected $msg = ""; 
     36     
     37    protected $file = ""; 
     38     
     39    protected $append = false; 
     40     
     41    protected $level = "warning"; 
    3342 
    34     protected $msg; 
     43    function main() {            
     44                switch ($this->level) 
     45                { 
     46                        case "error": $loglevel = PROJECT_MSG_ERR; break; 
     47                        case "warning": $loglevel = PROJECT_MSG_WARN; break; 
     48                        case "info": $loglevel = PROJECT_MSG_INFO; break; 
     49                        case "verbose": $loglevel = PROJECT_MSG_VERBOSE; break; 
     50                        case "debug": $loglevel = PROJECT_MSG_DEBUG; break; 
     51                } 
     52                 
     53                if (empty($this->file)) 
     54                { 
     55                $this->log($this->msg, $loglevel); 
     56                } 
     57                else 
     58                { 
     59                        if ($this->append) 
     60                        { 
     61                                $handle = fopen($this->file, "a"); 
     62                        } 
     63                        else 
     64                        { 
     65                                $handle = fopen($this->file, "w"); 
     66                        } 
     67                         
     68                        fwrite($handle, $this->msg); 
     69                         
     70                        fclose($handle); 
     71                } 
     72    } 
     73     
     74    /** setter for file */ 
     75    function setFile($file) 
     76    { 
     77                $this->file = (string) $file; 
     78        } 
    3579 
    36     function main() { 
    37         $this->log($this->msg); 
    38     } 
     80    /** setter for level */ 
     81    function setLevel($level) 
     82    { 
     83                $this->level = (string) $level; 
     84        } 
     85 
     86    /** setter for append */ 
     87    function setAppend($append) 
     88    { 
     89                $this->append = $append; 
     90        } 
    3991 
    4092    /** setter for message */