home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / phing / tasks / ext / pdo / PlainPDOResultFormatter.php < prev    next >
Encoding:
PHP Script  |  2007-10-23  |  3.0 KB  |  131 lines

  1. <?php
  2. /**
  3.  * $Id: FormatterElement.php 148 2007-02-13 11:15:53Z mrook $
  4.  *
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the LGPL. For more information please see
  19.  * <http://phing.info>.
  20.  */
  21.  
  22. require_once 'phing/system/io/PhingFile.php';
  23. require_once 'phing/tasks/ext/pdo/PDOResultFormatter.php';
  24.  
  25. /**
  26.  * Plain text formatter for PDO results. 
  27.  *
  28.  * @author Hans Lellelid <hans@xmpl.org>
  29.  * @package phing.tasks.ext.pdo
  30.  * @since 2.3.0
  31.  */
  32. class PlainPDOResultFormatter extends PDOResultFormatter
  33. {
  34.     /**
  35.      * Have column headers been printed?
  36.      * @var boolean
  37.      */
  38.     private $colsprinted = false;
  39.  
  40.     /**
  41.      * Whether to show headers.
  42.      * @var boolean
  43.      */
  44.     private $showheaders = true;
  45.  
  46.     /**
  47.      * Column delimiter.
  48.      * Defaults to ','
  49.      * @var string
  50.      */
  51.     private $coldelimiter = ",";
  52.  
  53.     /**
  54.      * Row delimiter.
  55.      * Defaults to PHP_EOL.
  56.      * @var string 
  57.      */
  58.     private $rowdelimiter = PHP_EOL;
  59.  
  60.     /**
  61.      * Set the showheaders attribute.
  62.      * @param boolean $v
  63.      */
  64.     public function setShowheaders($v) {
  65.         $this->showheaders = StringHelper::booleanValue($v);
  66.     }
  67.  
  68.     /**
  69.      * Sets the column delimiter.
  70.      * @param string $v
  71.      */
  72.     public function setColdelim($v) {
  73.         $this->coldelimiter = $v;
  74.     }
  75.  
  76.     /**
  77.      * Sets the row delimiter.
  78.      * @param string $v
  79.      */
  80.     public function setRowdelim($v) {
  81.         $this->rowdelimiter = $v;
  82.     }
  83.  
  84.     /**
  85.      * Processes a specific row from PDO result set.
  86.      *
  87.      * @param array $row Row of PDO result set.
  88.      */
  89.     public function processRow($row) {
  90.  
  91.         if (!$this->colsprinted && $this->showheaders) {
  92.             $first = true;
  93.             foreach($row as $fieldName => $ignore) {
  94.                 if ($first) $first = false; else $line .= ",";
  95.                 $line .= $fieldName;
  96.             }
  97.  
  98.             $this->out->write($line);
  99.             $this->out->write(PHP_EOL);
  100.  
  101.             $line = "";
  102.             $colsprinted = true;
  103.         } // if show headers
  104.  
  105.         $first = true;
  106.         foreach($row as $columnValue) {
  107.  
  108.             if ($columnValue != null) {
  109.                 $columnValue = trim($columnValue);
  110.             }
  111.  
  112.             if ($first) {
  113.                 $first = false;
  114.             } else {
  115.                 $line .= $this->coldelimiter;
  116.             }
  117.             $line .= $columnValue;
  118.         }
  119.         
  120.         $this->out->write($line);
  121.         $this->out->write($this->rowdelimiter);
  122.  
  123.     }
  124.  
  125.     public function getPreferredOutfile()
  126.     {
  127.         return new PhingFile('results.txt');
  128.     }
  129.     
  130. }
  131. ?>