PHP_CompatInfo
[ class tree: PHP_CompatInfo ] [ index: PHP_CompatInfo ] [ all elements ]

Source for file Csv.php

Documentation is available at Csv.php

  1. <?php
  2. /**
  3.  * Copyright (c) 2008, Laurent Laville <pear@laurent-laville.org>
  4.  *
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  *     * Redistributions of source code must retain the above copyright
  12.  *       notice, this list of conditions and the following disclaimer.
  13.  *     * Redistributions in binary form must reproduce the above copyright
  14.  *       notice, this list of conditions and the following disclaimer in the
  15.  *       documentation and/or other materials provided with the distribution.
  16.  *     * Neither the name of the authors nor the names of its contributors
  17.  *       may be used to endorse or promote products derived from this software
  18.  *       without specific prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  24.  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30.  * POSSIBILITY OF SUCH DAMAGE.
  31.  *
  32.  * PHP versions 4 and 5
  33.  *
  34.  * @category PHP
  35.  * @package  PHP_CompatInfo
  36.  * @author   Laurent Laville <pear@laurent-laville.org>
  37.  * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
  38.  * @version  CVS: $Id: Csv.php,v 1.4 2008/07/22 20:26:19 farell Exp $
  39.  * @link     http://pear.php.net/package/PHP_CompatInfo
  40.  * @since    File available since Release 1.8.0b3
  41.  */
  42.  
  43. /**
  44.  * Csv renderer for PHP_CompatInfo component.
  45.  *
  46.  * The PHP_CompatInfo_Renderer_Csv class is a concrete implementation
  47.  * of PHP_CompatInfo_Renderer abstract class. It simply output informations
  48.  * in Comma Seperated Value style.
  49.  *
  50.  * @category PHP
  51.  * @package  PHP_CompatInfo
  52.  * @author   Laurent Laville <pear@laurent-laville.org>
  53.  * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
  54.  * @version  Release: 1.8.0
  55.  * @link     http://pear.php.net/package/PHP_CompatInfo
  56.  * @since    Class available since Release 1.8.0b4
  57.  */
  58. {
  59.     /**
  60.      * Csv Renderer Class constructor (ZE1) for PHP4
  61.      *
  62.      * @param object &$parser Instance of the parser (model of MVC pattern)
  63.      * @param array  $conf    A hash containing any additional configuration
  64.      *
  65.      * @access public
  66.      * @since  version 1.8.0b4 (2008-06-18)
  67.      */
  68.     function PHP_CompatInfo_Renderer_Csv(&$parser$conf)
  69.     {
  70.         $this->__construct($parser$conf);
  71.     }
  72.  
  73.     /**
  74.      * Csv Renderer Class constructor (ZE2) for PHP5+
  75.      *
  76.      * @param object &$parser Instance of the parser (model of MVC pattern)
  77.      * @param array  $conf    A hash containing any additional configuration
  78.      *
  79.      * @access public
  80.      * @since  version 1.8.0b4 (2008-06-18)
  81.      */
  82.     function __construct(&$parser$conf)
  83.     {
  84.         $defaults = array('fields-values-separated-by' => ',',
  85.                           'fields-terminated-by' => ';',
  86.                           'fields-enclosed-by' => '"',
  87.                           'lines-terminated-by' => PHP_EOL);
  88.         $conf     array_merge($defaults$conf);
  89.  
  90.         parent::PHP_CompatInfo_Renderer($parser$conf);
  91.     }
  92.  
  93.     /**
  94.      * Display final results
  95.      *
  96.      * Display final results, when data source parsing is over.
  97.      *
  98.      * @access public
  99.      * @return void 
  100.      * @since  version 1.8.0b4 (2008-06-18)
  101.      */
  102.     function display()
  103.     {
  104.         $fvsb $this->conf['fields-values-separated-by'];
  105.         $o    $this->args['output-level'];
  106.         $info $this->parseData;
  107.         $hdr  = array();
  108.         $src  $this->_parser->dataSource;
  109.  
  110.         if ($info === false{
  111.             // invalid data source
  112.             return;
  113.         }
  114.  
  115.         $options $this->_parser->options;
  116.  
  117.         if (isset($this->args['dir'])) {
  118.             $dir   $this->args['dir'];
  119.             $hdr['Files';
  120.         elseif (isset($this->args['file'])) {
  121.             $file  $this->args['file'];
  122.             $hdr['File';
  123.         elseif (isset($this->args['string'])) {
  124.             $string $this->args['string'];
  125.             $hdr[]  'Source code';
  126.         elseif ($src['dataType'== 'directory'{
  127.             $dir   $src['dataSource'];
  128.             $hdr['Files';
  129.         elseif ($src['dataType'== 'file'{
  130.             $file  $src['dataSource'];
  131.             $hdr['File';
  132.         else {
  133.             if ($options['is_string'== true{
  134.                 $string $src['dataSource'];
  135.                 $hdr[]  'Source code';
  136.             else {
  137.                 $dir   $src['dataSource'];
  138.                 $hdr['Files';
  139.             }
  140.         }
  141.  
  142.         if ($o 16{
  143.             $hdr['Version';
  144.         }
  145.         if ($o 1{
  146.             $hdr['C';
  147.         }
  148.         if ($o 2{
  149.             $hdr['Extensions';
  150.         }
  151.         if ($o 4{
  152.             if ($o 8{
  153.                 $hdr['Constants/Tokens';
  154.             else {
  155.                 $hdr['Constants';
  156.             }
  157.         else {
  158.             if ($o 8{
  159.                 $hdr['Tokens';
  160.             }
  161.         }
  162.         // print headers
  163.         $this->_printf($hdr);
  164.  
  165.         $ext   implode($fvsb$info['extensions']);
  166.         $const implode($fvsbarray_merge($info['constants']$info['tokens']));
  167.         if (isset($dir)) {
  168.             $ds = DIRECTORY_SEPARATOR;
  169.             if (is_array($dir)) {
  170.                 $data = array(dirname($dir[0]));
  171.             else {
  172.                 $dir  str_replace(array('\\''/')$ds$dir);
  173.                 $data = array($dir);
  174.             }
  175.         elseif (isset($file)) {
  176.             $data = array($file);
  177.         else {
  178.             $data = array('<?php ... ?>');
  179.         }
  180.  
  181.         if ($o 16{
  182.             if (empty($info['max_version'])) {
  183.                 $data[$info['version'];
  184.             else {
  185.                 $data[implode($fvsbarray($info['version'],
  186.                                                $info['max_version']));
  187.             }
  188.         }
  189.         if ($o 1{
  190.             $data[$info['cond_code'][0];
  191.         }
  192.         if ($o 2{
  193.             $data[$ext;
  194.         }
  195.         if ($o 4{
  196.             if ($o 8{
  197.                 $data[$const;
  198.             else {
  199.                 $data[implode($fvsb$info['constants']);
  200.             }
  201.         else {
  202.             if ($o 8{
  203.                 $data[implode($fvsb$info['tokens']);
  204.             }
  205.         }
  206.  
  207.         $this->_printf($data);
  208.  
  209.         // summarize : print only summary for directory without files details
  210.         if ($this->args['summarize'=== false && isset($dir)) {
  211.  
  212.             unset($info['max_version']);
  213.             unset($info['version']);
  214.             unset($info['functions']);
  215.             unset($info['extensions']);
  216.             unset($info['constants']);
  217.             unset($info['tokens']);
  218.             unset($info['cond_code']);
  219.  
  220.             $ignored $info['ignored_files'];
  221.  
  222.             unset($info['ignored_files']);
  223.             unset($info['ignored_functions']);
  224.             unset($info['ignored_extensions']);
  225.             unset($info['ignored_constants']);
  226.  
  227.             foreach ($info as $file => $info{
  228.                 if ($info === false{
  229.                     continue;  // skip this (invalid) file
  230.                 }
  231.                 $ext   implode($fvsb$info['extensions']);
  232.                 $const implode($fvsbarray_merge($info['constants'],
  233.                                                     $info['tokens']));
  234.  
  235.                 $file str_replace(array('\\''/')$ds$file);
  236.  
  237.                 $data = array($file);
  238.                 if ($o 16{
  239.                     if (empty($info['max_version'])) {
  240.                         $data[$info['version'];
  241.                     else {
  242.                         $data[implode($fvsbarray($info['version'],
  243.                                                        $info['max_version']));
  244.                     }
  245.                 }
  246.                 if ($o 1{
  247.                     $data[$info['cond_code'][0];
  248.                 }
  249.                 if ($o 2{
  250.                     $data[$ext;
  251.                 }
  252.                 if ($o 4{
  253.                     if ($o 8{
  254.                         $data[$const;
  255.                     else {
  256.                         $data[implode($fvsb$info['constants']);
  257.                     }
  258.                 else {
  259.                     if ($o 8{
  260.                         $data[implode($fvsb$info['tokens']);
  261.                     }
  262.                 }
  263.  
  264.                 $this->_printf($data);
  265.             }
  266.         }
  267.     }
  268.  
  269.     /**
  270.      * Print a single line of CSV report
  271.      *
  272.      * @param array $data Data list to print
  273.      *
  274.      * @return void 
  275.      * @access private
  276.      * @since  1.8.0b4 (2008-06-18)
  277.      */
  278.     function _printf($data)
  279.     {
  280.         $string '';
  281.  
  282.         foreach ($data as $i => $d{
  283.             if ($i > 0{
  284.                 $string .= $this->conf['fields-terminated-by'];
  285.             }
  286.             $string .= $this->conf['fields-enclosed-by'$d .
  287.                        $this->conf['fields-enclosed-by'];
  288.         }
  289.         $string .= $this->conf['lines-terminated-by'];
  290.  
  291.         echo $string;
  292.     }
  293. }
  294. ?>

Documentation generated on Fri, 01 Aug 2008 11:30:24 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.