Source for file Text.php
Documentation is available at Text.php
* Copyright (c) 2008, Laurent Laville <pear@laurent-laville.org>
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the authors nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* @package PHP_CompatInfo
* @author Laurent Laville <pear@laurent-laville.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version CVS: $Id: Text.php,v 1.11 2008/07/27 14:17:44 farell Exp $
* @link http://pear.php.net/package/PHP_CompatInfo
* @since File available since Release 1.8.0b3
require_once 'Console/Table.php';
* Text renderer for PHP_CompatInfo component.
* The PHP_CompatInfo_Renderer_Text class is a concrete implementation
* of PHP_CompatInfo_Renderer abstract class. It simply display results
* for the command line interface with help of PEAR::Console_Table
* @package PHP_CompatInfo
* @author Laurent Laville <pear@laurent-laville.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version Release: 1.8.0
* @link http://pear.php.net/package/PHP_CompatInfo
* @since Class available since Release 1.8.0b3
* Text Renderer Class constructor (ZE1) for PHP4
* @param object &$parser Instance of the parser (model of MVC pattern)
* @param array $conf A hash containing any additional configuration
* @since version 1.8.0b3 (2008-06-07)
* Text Renderer Class constructor (ZE2) for PHP5+
* @param object &$parser Instance of the parser (model of MVC pattern)
* @param array $conf A hash containing any additional configuration
* @since version 1.8.0b3 (2008-06-07)
$defaults = array ('colwidth' => array ('f' => 29 , 'e' => 12 , 'c' => 20 ));
* Display final results, when data source parsing is over.
* @since version 1.8.0b3 (2008-06-07)
$o = $this->args['output-level'];
$src = $this->_parser->dataSource;
if (isset ($this->args['dir'])) {
$dir = $this->args['dir'];
} elseif (isset ($this->args['file'])) {
$file = $this->args['file'];
} elseif (isset ($this->args['string'])) {
$string = $this->args['string'];
} elseif ($src['dataType'] == 'directory') {
$dir = $src['dataSource'];
} elseif ($src['dataType'] == 'file') {
$file = $src['dataSource'];
$string = $src['dataSource'];
$table = new Console_Table ();
$filter2 = array (&$this, '_splitExtname');
$table->addFilter ($f+1 , $filter2);
$hdr[] = 'Constants/Tokens';
$table->setHeaders ($hdr);
$filter0 = array (&$this, '_splitFilename');
$table->addFilter (0 , $filter0);
if ($o > 3 && $o < 16 || $o > 19 ) {
$filter3 = array (&$this, '_splitConstant');
$table->addFilter ($f, $filter3);
$ext = implode("\r\n", $info['extensions']);
$ds = DIRECTORY_SEPARATOR;
$data = array ($dir . $ds . '*');
} elseif (isset ($file)) {
$data = array ('<?php ... ?>');
if (empty ($info['max_version'])) {
$data[] = $info['version'];
$data[] = implode("\r\n", array ($info['version'],
$data[] = $info['cond_code'][0 ];
$data[] = implode("\r\n", $info['constants']);
$data[] = implode("\r\n", $info['tokens']);
unset ($info['max_version']);
unset ($info['functions']);
unset ($info['extensions']);
unset ($info['constants']);
unset ($info['cond_code']);
$ignored = $info['ignored_files'];
$all_functions = array ();
unset ($info['ignored_files']);
unset ($info['ignored_functions']);
unset ($info['ignored_extensions']);
unset ($info['ignored_constants']);
// summarize : print only summary for directory without files details
if ($this->args['summarize'] === false && isset ($dir)) {
foreach ($info as $file => $info) {
// extra information available only when debug mode is on
$all_functions[$file] = $info;
continue; // skip this (invalid) file
$ext = implode("\r\n", $info['extensions']);
if (empty ($info['max_version'])) {
$data[] = $info['version'];
$data[] = implode("\r\n", array ($info['version'],
$data[] = $info['cond_code'][0 ];
$data[] = implode("\r\n", $info['constants']);
$data[] = implode("\r\n", $info['tokens']);
foreach ($info as $file => $info) {
// extra information available only when debug mode is on
$all_functions[$file] = $info;
$output = $table->getTable ();
$v = isset ($this->args['verbose']) ? $this->args['verbose'] : 0;
$output .= "\nCommand Line resume :\n\n";
$table = new Console_Table ();
$table->setHeaders (array ('Option', 'Value'));
$filter0 = array (&$this, '_splitOption');
$table->addFilter (0 , $filter0);
$filter1 = array (&$this, '_splitValue');
$table->addFilter (1 , $filter1);
foreach ($this->args as $key => $raw) {
if ($key == 'summarize') {
$raw = ($raw === true ) ? 'TRUE' : 'FALSE';
$contents = array ($key, $raw);
$table->addRow ($contents);
$output .= $table->getTable ();
$output .= "\nParser options :\n\n";
$table = new Console_Table ();
$table->setHeaders (array ('Option', 'Value'));
$filter0 = array (&$this, '_splitOption');
$table->addFilter (0 , $filter0);
$filter1 = array (&$this, '_splitValue');
$table->addFilter (1 , $filter1);
$opts = $this->_parser->options;
foreach ($opts as $key => $raw) {
|| $key == 'is_string') {
$raw = ($raw === true ) ? 'TRUE' : 'FALSE';
if (substr($key, -6 ) == '_match') {
$contents = array ($key, $raw);
$table->addRow ($contents);
$output .= $table->getTable ();
$output .= "\nDebug:\n\n";
$table = new Console_Table ();
$table->setHeaders (array ('Version', 'Function', 'Extension', 'PECL'));
foreach ($all_functions as $version => $functions) {
foreach ($functions as $func) {
$table->addRow (array ($version,
$func['function'], $func['extension'],
(($func['pecl'] === true ) ? 'yes' : 'no') : '')));
$output .= $table->getTable ();
* The Console_Table filter callback limits table output to 80 columns,
* and Path column to 29 characters
* (27 + 1 blank margin left + 1 blank margin right).
* @param string $data Content of filename column (0)
function _splitFilename ($data)
$w = $this->conf['colwidth']['f'] - 2;
* The Console_Table filter callback limits table output to 80 columns,
* and Extensions column to 12 characters
* (10 + 1 blank margin left + 1 blank margin right).
* @param string $data Content of extensions column
function _splitExtname ($data)
$szlim = $this->conf['colwidth']['e'] - 2;
foreach ($extArr as $ext) {
$str .= '...' . substr($ext, (strlen($ext) - ($szlim - 3 )));
$str = rtrim($str, "\r\n");
* The Console_Table filter callback limits table output to 80 columns,
* and Constants/Tokens column to 20 characters
* (18 + 1 blank margin left + 1 blank margin right)
* @param string $data Content of constants/tokens column
function _splitConstant ($data)
$szlim = $this->conf['colwidth']['c'] - 2;
foreach ($cstArr as $cst) {
$str .= '...' . substr($cst, (strlen($cst) - ($szlim - 3 )));
$str = rtrim($str, "\r\n");
* The Console_Table filter callback limits table output to 80 columns,
* and Command line Option column to 25 characters
* (23 + 1 blank margin left + 1 blank margin right).
* @param string $data Content of option column (0)
function _splitOption ($data)
* The Console_Table filter callback limits table output to 80 columns,
* and Command line Value column to 51 characters
* (49 + 1 blank margin left + 1 blank margin right)
* @param string $data Content of value column (1)
function _splitValue ($data)
foreach ($cstArr as $cst) {
$str = rtrim($str, "\r\n");
Documentation generated on Fri, 01 Aug 2008 11:30:33 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|