/** * Produce dependencies for extensions using PEAR PHP_CompatInfo package. */ function extdeps($files) { require_once 'PHP/CompatInfo.php'; $info = new PHP_CompatInfo('null'); $res = $info->parseData($files); // minimum php version we accept // "%define php_min_version 5.1.2" in spec to minimum version to be 5.1.2 $version = max(PHP_MIN_VERSION, $res['version']); if (version_compare($version, '5.0.0', 'ge')) { # force php-<name> only deps when php5 # XXX what about php-pecl-<name> virtual provides? $fmt = 'php-%s'; $epoch = 4; } else { $fmt = 'php(%s)'; $epoch = 3; } echo "php-common >= ", $epoch, ":", $version, "\n"; // process extensions foreach ($res['extensions'] as $ext) { // bz2 ext is in php-bzip2 package if ($ext == 'bz2') { $ext = 'bzip2'; } // libxml ext is in php-xml package if ($ext == 'libxml') { $ext = 'xml'; } // these need to be lowercased if (in_array($ext, array('SPL', 'PDO', 'SQLite', 'Reflection', 'SimpleXML'))) { $ext = strtolower($ext); } printf("{$fmt}\n", $ext); } }
/** * Parse the given file or directory and determine the * minimum PHP version needed to execute the code. */ function execute() { // We render in text mode. We configure 40/12/40 columns for // filename/extension/constant rendering. $driverOptions = array('silent' => false, 'progress' => 'bar', 'colwidth' => array('f' => 50, 'e' => 12, 'c' => 40)); $info = new PHP_CompatInfo('text', $driverOptions); $info->parseData($this->input_file); }
/** * Run the CLI version * * Run the CLI version of PHP_CompatInfo * * @return void * @access public * @since version 0.8.0 (2004-04-22) */ function run() { $args =& Console_Getargs::factory($this->opts); if (PEAR::isError($args)) { if ($args->getCode() === CONSOLE_GETARGS_HELP) { $error = ''; } else { $error = $args->getMessage(); } $this->_printUsage($error); return; } // default parser options $this->options = array('file_ext' => array('php', 'php4', 'inc', 'phtml'), 'recurse_dir' => true, 'debug' => false, 'is_string' => false, 'ignore_files' => array(), 'ignore_dirs' => array()); // version $V = $args->getValue('V'); if (isset($V)) { $error = 'PHP_CompatInfo (cli) version 1.8.1' . ' (http://pear.php.net/package/PHP_CompatInfo)'; echo $error; return; } // debug if ($args->isDefined('v')) { $v = $args->getValue('v'); if ($v > 3) { $this->options['debug'] = true; } } // no-recurse if ($args->isDefined('n')) { $this->options['recurse_dir'] = false; } // dir if ($args->isDefined('d')) { $d = $args->getValue('d'); if (file_exists($d)) { if ($d[strlen($d) - 1] == '/' || $d[strlen($d) - 1] == '\\') { $d = substr($d, 0, -1); } $this->dataSource = realpath($d); } else { $error = 'Failed opening directory "' . $d . '". Please check your spelling and try again.'; $this->_printUsage($error); return; } } // file if ($args->isDefined('f')) { $f = $args->getValue('f'); if (file_exists($f)) { $this->dataSource = $f; } else { $error = 'Failed opening file "' . $f . '". Please check your spelling and try again.'; $this->_printUsage($error); return; } } // string if ($args->isDefined('s')) { $s = $args->getValue('s'); if (!empty($s)) { $this->dataSource = sprintf("<?php %s ?>", $s); $this->options['is_string'] = true; } else { $error = 'Failed opening string "' . $s . '". Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-files $if = $args->getValue('if'); if (isset($if)) { if (file_exists($if)) { $options = $this->_parseParamFile($if); $this->options['ignore_files'] = $options['std']; } else { $error = 'Failed opening file "' . $if . '" (ignore-files option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-dirs $id = $args->getValue('id'); if (isset($id)) { if (file_exists($id)) { $options = $this->_parseParamFile($id); $this->options['ignore_dirs'] = $options['std']; } else { $error = 'Failed opening file "' . $id . '" (ignore-dirs option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-functions $in = $args->getValue('in'); if (isset($in)) { if (file_exists($in)) { $options = $this->_parseParamFile($in); $this->options['ignore_functions'] = $options['std']; } else { $error = 'Failed opening file "' . $in . '" (ignore-functions option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-constants $ic = $args->getValue('ic'); if (isset($ic)) { if (file_exists($ic)) { $options = $this->_parseParamFile($ic); $this->options['ignore_constants'] = $options['std']; } else { $error = 'Failed opening file "' . $ic . '" (ignore-constants option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-extensions $ie = $args->getValue('ie'); if (isset($ie)) { if (file_exists($ie)) { $options = $this->_parseParamFile($ie); $this->options['ignore_extensions'] = $options['std']; } else { $error = 'Failed opening file "' . $ie . '" (ignore-extensions option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-versions $iv = $args->getValue('iv'); if (isset($iv)) { if (!is_array($iv)) { $iv = array($iv); } $this->options['ignore_versions'] = $iv; } // ignore-functions-match $inm = $args->getValue('inm'); if (isset($inm)) { if (file_exists($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); return; } 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']); } } else { $error = 'Failed opening file "' . $inm . '" (ignore-functions-match option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-extensions-match $iem = $args->getValue('iem'); if (isset($iem)) { if (file_exists($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); return; } 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']); } } else { $error = 'Failed opening file "' . $iem . '" (ignore-extensions-match option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // ignore-constants-match $icm = $args->getValue('icm'); if (isset($icm)) { if (file_exists($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); return; } 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']); } } else { $error = 'Failed opening file "' . $icm . '" (ignore-constants-match option). ' . 'Please check your spelling and try again.'; $this->_printUsage($error); return; } } // file-ext if ($args->isDefined('d') && $args->isDefined('fe')) { $fe = $args->getValue('fe'); if (is_string($fe)) { $this->options['file_ext'] = explode(',', $fe); } else { $error = 'No valid file extensions provided "' . '". Please check your spelling and try again.'; $this->_printUsage($error); return; } } // 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); return; } if ($args->isDefined('r')) { $report = $args->getValue('r'); } else { $report = 'text'; } if ($args->isDefined('t')) { $defs = array('f' => 29, 'e' => 12, 'c' => 20); $tabs = $args->getValue('t'); $tabs = explode(',', $tabs); for ($t = 0; $t < 3; $t++) { if (isset($tabs[$t])) { if ($t == 0) { $defs['f'] = (int) $tabs[$t]; } elseif ($t == 1) { $defs['e'] = (int) $tabs[$t]; } else { $defs['c'] = (int) $tabs[$t]; } } } $conf = array('colwidth' => $defs); } else { $conf = array(); } $conf = array_merge($conf, array('args' => $args->getValues())); $compatInfo = new PHP_CompatInfo($report, $conf); // dir 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); return; } } $compatInfo->parseData($this->dataSource, $this->options); }