Source for file pearcmd.php
Documentation is available at pearcmd.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2004 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 3.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at the following url: |
// | http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Stig Bakken <ssb@php.net> |
// | Tomas V.V.Cox <cox@idecnet.com> |
// +----------------------------------------------------------------------+
// $Id: pearcmd.php,v 1.37 2007/01/08 05:14:01 cellog Exp $
// this is defined in peclcmd.php as 'pecl'
define('PEAR_RUNTYPE', 'pear');
define('PEAR_IGNORE_BACKTRACE', 1 );
if ('@include_path@' != '@'. 'include_path'. '@') {
ini_set('include_path', '@include_path@');
// this is a raw, uninstalled pear, either a cvs checkout, or php distro
@ini_set('magic_quotes_runtime', false );
$_PEAR_PHPDIR = '#$%^&*';
$pear_package_version = "@pear_version@";
require_once 'PEAR/Frontend.php';
require_once 'PEAR/Config.php';
require_once 'PEAR/Command.php';
require_once 'Console/Getopt.php';
// remove this next part when we stop supporting that crap-ass PHP 4.2
if (!isset ($_SERVER['argv']) && !isset ($argv) && !isset ($HTTP_SERVER_VARS['argv'])) {
echo 'ERROR: either use the CLI php executable, or set register_argc_argv=On in php.ini';
$argv = Console_Getopt ::readPHPArgv ();
// fix CGI sapi oddity - the -- in pear.bat/pear is not removed
if (php_sapi_name() != 'cli' && isset ($argv[1 ]) && $argv[1 ] == '--') {
$options = Console_Getopt ::getopt2 ($argv, "c:C:d:D:Gh?sSqu:vV");
$options = Console_Getopt ::getopt ($argv, "c:C:d:D:Gh?sSqu:vV");
if ($progname == 'gpear' || $progname == 'pear-gtk') {
foreach ($opts as $opt) {
//Check if Gtk and PHP >= 5.1.0
$pear_system_config = '';
$store_user_config = false;
$store_system_config = false;
foreach ($opts as $opt) {
$pear_user_config = $opt[1 ];
$pear_system_config = $opt[1 ];
if ($pear_user_config !== false ) {
$_file .= $pear_user_config;
if ($pear_system_config !== false ) {
$_file .= '/' . $pear_system_config;
$_file = 'The default config file';
$ui->outputData (" ERROR: $_file is not a valid config file or is corrupted." );
// We stop, we have no idea where we are :)
// this is used in the error handler to retrieve a relative path
$_PEAR_PHPDIR = $config->get ('php_dir');
$ui->outputData ('WARNING: running in safe mode requires that all files created ' .
'be the same uid as the current script. PHP reports this script is uid: ' .
$verbose = $config->get ("verbose");
if (!$config->isDefinedLayer ('user') && !$config->isDefinedLayer ('system')) {
foreach ($opts as $opt) {
if ($opt[0 ] == 'd' || $opt[0 ] == 'D') {
$found = true; // the user knows what they are doing, and are setting config values
// no prior runs, try to install PEAR
$packagexml = dirname(dirname(__FILE__ )) . DIRECTORY_SEPARATOR . 'package2.xml';
$packagexml = dirname(__FILE__ ) . DIRECTORY_SEPARATOR . 'package2.xml';
$config->set ('php_dir', $pearbase . DIRECTORY_SEPARATOR . 'php');
$config->set ('data_dir', $pearbase . DIRECTORY_SEPARATOR . 'data');
$config->set ('doc_dir', $pearbase . DIRECTORY_SEPARATOR . 'docs');
$config->set ('test_dir', $pearbase . DIRECTORY_SEPARATOR . 'tests');
$config->set ('ext_dir', $pearbase . DIRECTORY_SEPARATOR . 'extensions');
$config->set ('bin_dir', $pearbase);
$config->mergeConfigFile ($pearbase . 'pear.ini', false );
$config->set ('auto_discover', 1 );
foreach ($opts as $opt) {
$param = !empty ($opt[1 ]) ? $opt[1 ] : true;
die ('Invalid usage of "-d" option, expected -d config_value=value, ' .
if (count($possible) != 2 ) {
die ('Invalid usage of "-d" option, expected -d config_value=value, received "' .
list ($key, $value) = explode('=', $param);
$config->set ($key, $value, 'user');
die ('Invalid usage of "-d" option, expected -d config_value=value, ' .
if (count($possible) != 2 ) {
die ('Invalid usage of "-d" option, expected -d config_value=value, received "' .
list ($key, $value) = explode('=', $param);
$config->set ($key, $value, 'system');
$store_user_config = true;
$store_system_config = true;
$config->remove ($param, 'user');
$config->set ('verbose', $config->get ('verbose') + 1 );
$config->set ('verbose', $config->get ('verbose') - 1 );
// all non pear params goes to the command
$cmdopts[$opt[0 ]] = $param;
if ($store_system_config) {
$config->store ('system');
if ($store_user_config) {
$command = (isset ($options[1 ][0 ])) ? $options[1 ][0 ] : null;
if (empty ($command) && ($store_user_config || $store_system_config)) {
if ($fetype == 'Gtk' || $fetype == 'Gtk2') {
if (!$config->validConfiguration ()) {
PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' .
" '$pear_user_config' or '$pear_system_config', please copy an existing configuration" .
'file to one of these locations, or use the -c and -s options to create one');
if ($command == 'help') {
usage(null , @$options[1 ][1 ]);
if (!$config->validConfiguration ()) {
PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' .
" '$pear_user_config' or '$pear_system_config', please copy an existing configuration" .
'file to one of these locations, or use the -c and -s options to create one');
usage(null , @$options[1 ][0 ]);
$short_args = $long_args = null;
$tmp = Console_Getopt ::getopt2 ($options[1 ], $short_args, $long_args);
$tmp = Console_Getopt ::getopt ($options[1 ], $short_args, $long_args);
list ($tmpopt, $params) = $tmp;
foreach ($tmpopt as $foo => $tmp2) {
list ($opt, $value) = $tmp2;
$value = true; // options without args
$cmdoptions = $cmd->getOptions ($command);
foreach ($cmdoptions as $o => $d) {
if (@$d['shortopt'] == $opt) {
if (substr($opt, 0 , 2 ) == '--') {
$opts[substr($opt, 2 )] = $value;
$ok = $cmd->run ($command, $opts, $params);
function usage($error = null , $helpsubject = null )
global $progname, $all_commands;
$stderr = fopen('php://stderr', 'w');
fputs($stderr, $error->getMessage () . "\n");
} elseif ($error !== null ) {
fputs($stderr, " $error\n" );
if ($helpsubject != null ) {
$formatstr = " %-{$maxlen}s %s\n";
foreach ($all_commands as $cmd => $class) {
" Usage: $progname [options] command [command-options] <parameters>\n".
" Type \"$progname help options\" to list all options.\n".
" Type \"$progname help shortcuts\" to list all command shortcuts.\n".
" Type \"$progname help <command>\" to get the help for the specified command.";
fputs($stderr, " $put\n" );
global $progname, $all_commands, $config;
if ($command == "options") {
" -v increase verbosity level (default 1)\n".
" -q be quiet, decrease verbosity level\n".
" -c file find user configuration in `file'\n".
" -C file find system configuration in `file'\n".
" -d foo=bar set user config variable `foo' to `bar'\n".
" -D foo=bar set system config variable `foo' to `bar'\n".
" -G start in graphical (Gtk) mode\n".
" -s store user configuration\n".
" -S store system configuration\n".
" -u foo unset `foo' in the user configuration\n".
" -h, -? display help/usage (this message)\n".
" -V version information\n";
} elseif ($command == "shortcuts") {
foreach ($sc as $s => $c) {
$ret .= sprintf(" %-8s %s\n", $s, $c);
} elseif ($command == "version") {
return "PEAR Version: ". $GLOBALS['pear_package_version'].
return " $progname $command [options] $help\n";
return " $progname $command $help[0]";
return " $progname $command [options] $help[0]\n$help[1]";
return " Command '$command' is not valid, try 'pear help'";
if (defined('E_STRICT') && $errno & E_STRICT ) {
if ($GLOBALS['config']->get ('verbose') < 4 ) {
return false; // @silenced error, show all if debug is high enough
E_PARSE => "Parsing Error",
E_CORE_ERROR => "Core Error",
E_CORE_WARNING => "Core Warning",
E_COMPILE_ERROR => "Compile Error",
E_COMPILE_WARNING => "Compile Warning",
E_USER_ERROR => "User Error",
E_USER_WARNING => "User Warning",
E_USER_NOTICE => "User Notice"
$prefix = $errortype[$errno];
if (stristr($file, $_PEAR_PHPDIR)) {
print " \n$prefix: $errmsg in $file on line $line\n";
Documentation generated on Mon, 11 Mar 2019 15:09:37 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|