Source for file Cli.php
Documentation is available at Cli.php
* Copyright (c) 2004-2008, Davey Shafik <davey@php.net>
* 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 Davey Shafik <davey@php.net>
* @author Laurent Laville <pear@laurent-laville.org>
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version CVS: $Id: Cli.php,v 1.74 2008/07/22 20:26:19 farell Exp $
* @link http://pear.php.net/package/PHP_CompatInfo
* @since File available since Release 0.8.0
require_once 'PHP/CompatInfo.php';
require_once 'Console/Getargs.php';
* CLI Script to Check Compatibility of chunk of PHP code
* require_once 'PHP/CompatInfo/Cli.php';
* $cli = new PHP_CompatInfo_Cli();
* @package PHP_CompatInfo
* @author Davey Shafik <davey@php.net>
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2003 Davey Shafik and Synaptic Media. All Rights Reserved.
* @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 0.8.0
* @var array Current CLI Flags
* Unified data source reference
* @var string Directory, File or String to be processed
* @var array Current parser options
* Command-Line Class constructor
* Command-Line Class constructor (ZE2) for PHP5+
* @since version 0.8.0 (2004-04-22)
'desc' => 'Parse DIR to get its compatibility info',
'min' => 0 , 'max' => 1 ),
'desc' => 'Parse FILE to get its compatibility info',
'min' => 0 , 'max' => 1 ),
'desc' => 'Parse STRING to get its compatibility info',
'min' => 0 , 'max' => 1 ),
'desc' => 'Set the verbose level',
'min' => 0 , 'max' => 1 ),
'desc' => 'Do not recursively parse files when using --dir',
'desc' => 'Data file name which contains a list of '
'default' => 'files.txt',
'min' => 0 , 'max' => 1 ),
'desc' => 'Data file name which contains a list of '
'min' => 0 , 'max' => 1 ),
'desc' => 'Data file name which contains a list of '
. 'php function to ignore',
'default' => 'functions.txt',
'min' => 0 , 'max' => 1 ),
'desc' => 'Data file name which contains a list of '
. 'php constant to ignore',
'default' => 'constants.txt',
'min' => 0 , 'max' => 1 ),
'desc' => 'Data file name which contains a list of '
. 'php extension to ignore',
'default' => 'extensions.txt',
'min' => 0 , 'max' => 1 ),
'desc' => 'PHP versions - functions to exclude '
. 'when parsing source code',
'min' => 0 , 'max' => 2 ),
'ignore-functions-match' =>
'desc' => 'Data file name which contains a list of '
. 'php function pattern to ignore',
'default' => 'functions-match.txt',
'min' => 0 , 'max' => 1 ),
'ignore-extensions-match' =>
'desc' => 'Data file name which contains a list of '
. 'php extension pattern to ignore',
'default' => 'extensions-match.txt',
'min' => 0 , 'max' => 1 ),
'ignore-constants-match' =>
'desc' => 'Data file name which contains a list of '
. 'php constant pattern to ignore',
'default' => 'constants-match.txt',
'min' => 0 , 'max' => 1 ),
'desc' => 'A comma separated list of file extensions '
. 'to parse (only valid if parsing a directory)',
'default' => 'php, php4, inc, phtml',
'min' => 0 , 'max' => 1 ),
'desc' => 'Print either "xml" or "csv" report',
'min' => 0 , 'max' => 1 ),
'desc' => 'Print Path/File + Version with additional data',
'min' => 0 , 'max' => 1 ),
'desc' => 'Columns width',
'min' => 0 , 'max' => 1 ),
'desc' => 'Show a wait message [text] or a progress bar [bar]',
'min' => 0 , 'max' => 1 ),
'desc' => 'Print only summary when parsing directory',
'desc' => 'Print version information',
'desc' => 'Show this help',
* Command-Line Class constructor
* Command-Line Class constructor (ZE1) for PHP4
* @since version 0.8.0 (2004-04-22)
* Run the CLI version of PHP_CompatInfo
* @since version 0.8.0 (2004-04-22)
$args = & Console_Getargs ::factory ($this->opts);
if (PEAR ::isError ($args)) {
if ($args->getCode () === CONSOLE_GETARGS_HELP ) {
$error = $args->getMessage ();
$this->_printUsage ($error);
// default parser options
'file_ext' => array ('php', 'php4', 'inc', 'phtml'),
'ignore_files' => array (),
$V = $args->getValue ('V');
$error = 'PHP_CompatInfo (cli) version 1.8.0'
. ' (http://pear.php.net/package/PHP_CompatInfo)';
if ($args->isDefined ('v')) {
$v = $args->getValue ('v');
if ($args->isDefined ('n')) {
$this->options['recurse_dir'] = false;
if ($args->isDefined ('d')) {
$d = $args->getValue ('d');
$error = 'Failed opening directory "' . $d
. '". Please check your spelling and try again.';
$this->_printUsage ($error);
if ($args->isDefined ('f')) {
$f = $args->getValue ('f');
$error = 'Failed opening file "' . $f
. '". Please check your spelling and try again.';
$this->_printUsage ($error);
if ($args->isDefined ('s')) {
$s = $args->getValue ('s');
$this->options['is_string'] = true;
$error = 'Failed opening string "' . $s
. '". Please check your spelling and try again.';
$this->_printUsage ($error);
$if = $args->getValue ('if');
$options = $this->_parseParamFile ($if);
$this->options['ignore_files'] = $options['std'];
$error = 'Failed opening file "' . $if
. '" (ignore-files option). '
. 'Please check your spelling and try again.';
$this->_printUsage ($error);
$id = $args->getValue ('id');
$options = $this->_parseParamFile ($id);
$this->options['ignore_dirs'] = $options['std'];
$error = 'Failed opening file "' . $id
. '" (ignore-dirs option). '
. 'Please check your spelling and try again.';
$this->_printUsage ($error);
$in = $args->getValue ('in');
$options = $this->_parseParamFile ($in);
$this->options['ignore_functions'] = $options['std'];
$error = 'Failed opening file "' . $in
. '" (ignore-functions option). '
. 'Please check your spelling and try again.';
$this->_printUsage ($error);
$ic = $args->getValue ('ic');
$options = $this->_parseParamFile ($ic);
$this->options['ignore_constants'] = $options['std'];
$error = 'Failed opening file "' . $ic
. '" (ignore-constants option). '
. 'Please check your spelling and try again.';
$this->_printUsage ($error);
$ie = $args->getValue ('ie');
$options = $this->_parseParamFile ($ie);
$this->options['ignore_extensions'] = $options['std'];
$error = 'Failed opening file "' . $ie
. '" (ignore-extensions option). '
. 'Please check your spelling and try again.';
$this->_printUsage ($error);
$iv = $args->getValue ('iv');
$this->options['ignore_versions'] = $iv;
// ignore-functions-match
$inm = $args->getValue ('inm');
$patterns = $this->_parseParamFile ($inm, true );
if (count($patterns['std']) > 0
&& count($patterns['reg']) > 0 ) {
$error = 'Mixed "function_exists" and '
. '"preg_match" conditions are not allowed. '
. 'Please check your spelling and try again.';
$this->_printUsage ($error);
} elseif (count($patterns['std']) > 0 ) {
$this->options['ignore_functions_match']
= array ('function_exists', $patterns['std']);
} elseif (count($patterns['reg']) > 0 ) {
$this->options['ignore_functions_match']
= array ('preg_match', $patterns['reg']);
$error = 'Failed opening file "' . $inm
. '" (ignore-functions-match option). '
. 'Please check your spelling and try again.';
$this->_printUsage ($error);
// ignore-extensions-match
$iem = $args->getValue ('iem');
$patterns = $this->_parseParamFile ($iem, true );
if (count($patterns['std']) > 0
&& count($patterns['reg']) > 0 ) {
$error = 'Mixed "extension_loaded" and '
. '"preg_match" conditions are not allowed. '
. 'Please check your spelling and try again.';
$this->_printUsage ($error);
} elseif (count($patterns['std']) > 0 ) {
$this->options['ignore_extensions_match']
= array ('extension_loaded', $patterns['std']);
} elseif (count($patterns['reg']) > 0 ) {
$this->options['ignore_extensions_match']
= array ('preg_match', $patterns['reg']);
$error = 'Failed opening file "' . $iem
. '" (ignore-extensions-match option). '
. 'Please check your spelling and try again.';
$this->_printUsage ($error);
// ignore-constants-match
$icm = $args->getValue ('icm');
$patterns = $this->_parseParamFile ($icm, true );
if (count($patterns['std']) > 0
&& count($patterns['reg']) > 0 ) {
$error = 'Mixed "defined" and '
. '"preg_match" conditions are not allowed. '
. 'Please check your spelling and try again.';
$this->_printUsage ($error);
} elseif (count($patterns['std']) > 0 ) {
$this->options['ignore_constants_match']
= array ('defined', $patterns['std']);
} elseif (count($patterns['reg']) > 0 ) {
$this->options['ignore_constants_match']
= array ('preg_match', $patterns['reg']);
$error = 'Failed opening file "' . $icm
. '" (ignore-constants-match option). '
. 'Please check your spelling and try again.';
$this->_printUsage ($error);
if ($args->isDefined ('d') && $args->isDefined ('fe')) {
$fe = $args->getValue ('fe');
$error = 'No valid file extensions provided "'
. '". Please check your spelling and try again.';
$this->_printUsage ($error);
// file or directory options are minimum required to work
if (!$args->isDefined ('f')
&& !$args->isDefined ('d')
&& !$args->isDefined ('s')) {
$error = 'ERROR: You must supply at least '
. 'one string, file or directory to process';
$this->_printUsage ($error);
if ($args->isDefined ('r')) {
$report = $args->getValue ('r');
if ($args->isDefined ('t')) {
$defs = array ('f' => 29 , 'e' => 12 , 'c' => 20 );
$tabs = $args->getValue ('t');
for ($t = 0; $t < 3; $t++ ) {
$defs['f'] = (int) $tabs[$t];
$defs['e'] = (int) $tabs[$t];
$defs['c'] = (int) $tabs[$t];
$conf = array ('colwidth' => $defs);
$conf = array_merge($conf, array ('args' => $args->getValues ()));
if ($args->isDefined ('d')) {
$d = $args->getValue ('d');
$files = $compatInfo->parser ->getFilelist ($d, $this->options);
if (count($files) == 0 ) {
$error = 'No valid files into directory "'. $d
. '". Please check your spelling and try again.';
$this->_printUsage ($error);
* Parse content of parameter files
* Parse content of parameter files used by switches
* <li>ignore-functions-match
* <li>ignore-extensions-match
* <li>ignore-constants-match
* @param string $fn Parameter file name
* @param bool $withPattern TRUE if the file may contain regular expression
* @since version 1.7.0b4 (2008-04-03)
function _parseParamFile ($fn, $withPattern = false )
$patterns = array ('std' => array (), 'reg' => array ());
foreach ($lines as $line) {
$line = rtrim($line); // remove line ending
continue; // skip empty lines
continue; // skip this pattern: consider as comment line
list ($p, $s) = explode('=', $line);
$patterns['reg'][] = '/'. $s. '/';
if ($withPattern === true ) {
$patterns['std'][] = '/'. $line. '/';
$patterns['std'][] = $line;
* Show full help information
* @param string $footer (optional) page footer content
* @since version 0.8.0 (2004-04-22)
function _printUsage ($footer = '')
. basename($_SERVER['SCRIPT_NAME']) . " [options]\n\n";
echo Console_Getargs ::getHelp ($this->opts, $header,
" \n$footer\n" , 78 , 2 ). "\n";
Documentation generated on Fri, 01 Aug 2008 11:30:22 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|