Changeset 118

Show
Ignore:
Timestamp:
09/14/06 19:54:52 (2 years ago)
Author:
mrook
Message:

Add filterchain ability (contributed by Andrew Eddie)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/classes/phing/tasks/ext/CreoleSQLExecTask.php

    r115 r118  
    7171 
    7272    /** 
     73     * all filterchains objects assigned to this task 
     74     */ 
     75    private $filterChains  = array(); 
     76 
     77    /** 
    7378     * SQL statement 
    7479     */ 
     
    153158    public function addFileset(FileSet $set) { 
    154159        $this->filesets[] = $set; 
     160    } 
     161 
     162    /** 
     163     * Creates a filterchain 
     164     * 
     165     * @access public 
     166     * @return  object  The created filterchain object 
     167     */ 
     168    function createFilterChain() { 
     169        $num = array_push($this->filterChains, new FilterChain($this->project)); 
     170        return $this->filterChains[$num-1]; 
    155171    } 
    156172 
     
    358374        $sql = ""; 
    359375        $line = ""; 
    360         $in = new BufferedReader($reader); 
     376 
     377                $buffer = ''; 
     378 
     379        if ((is_array($this->filterChains)) && (!empty($this->filterChains))) {     
     380            $in = FileUtils::getChainedReader(new BufferedReader($reader), $this->filterChains, $this->getProject()); 
     381                        while(-1 !== ($read = $in->read())) { // -1 indicates EOF 
     382                                   $buffer .= $read; 
     383            } 
     384            $lines = explode("\n", $buffer); 
     385        } else { 
     386                $in = new BufferedReader($reader); 
     387 
     388            while (($line = $in->readLine()) !== null) { 
     389                                $lines[] = $line; 
     390                        } 
     391                } 
     392 
    361393        try { 
    362             while (($line = $in->readLine()) !== null) { 
     394                       foreach ($lines as $line) { 
    363395                $line = trim($line); 
    364396                $line = ProjectConfigurator::replaceProperties($this->project, $line, 
     
    391423                        && $line == $this->delimiter) { 
    392424                    $this->log("SQL: " . $sql, PROJECT_MSG_VERBOSE); 
    393                     $this->execSQL(StringHelper::substring($sql, 0, strlen($sql) - strlen($this->delimiter) - 1), $out); 
     425                    $this->execSQL(StringHelper::substring($sql, 0, strlen($sql) - strlen($this->delimiter)), $out); 
    394426                    $sql = ""; 
    395427                } 
     
    547579            $this->parent->log("Executing file: " . $this->tSrcFile->getAbsolutePath(), 
    548580                PROJECT_MSG_INFO); 
     581 
    549582            $reader = new FileReader($this->tSrcFile); 
     583 
    550584            $this->parent->runStatements($reader, $out); 
    551585            $reader->close();