[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/system/pear/scripts/ -> pearcmd.php (source)

   1  <?php
   2  //
   3  // +----------------------------------------------------------------------+
   4  // | PHP Version 5                                                        |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 1997-2004 The PHP Group                                |
   7  // +----------------------------------------------------------------------+
   8  // | This source file is subject to version 3.0 of the PHP license,       |
   9  // | that is bundled with this package in the file LICENSE, and is        |
  10  // | available through the world-wide-web at the following url:           |
  11  // | http://www.php.net/license/3_0.txt.                                  |
  12  // | If you did not receive a copy of the PHP license and are unable to   |
  13  // | obtain it through the world-wide-web, please send a note to          |
  14  // | license@php.net so we can mail you a copy immediately.               |
  15  // +----------------------------------------------------------------------+
  16  // | Authors: Stig Bakken <ssb@php.net>                                   |
  17  // |          Tomas V.V.Cox <cox@idecnet.com>                             |
  18  // |                                                                      |
  19  // +----------------------------------------------------------------------+
  20  //
  21  // $Id: pearcmd.php,v 1.33 2006/01/02 18:05:53 cellog Exp $
  22  
  23  ob_end_clean();
  24  if (!defined('PEAR_RUNTYPE')) {
  25      // this is defined in peclcmd.php as 'pecl'
  26      define('PEAR_RUNTYPE', 'pear');
  27  }
  28  define('PEAR_IGNORE_BACKTRACE', 1);
  29  if (!function_exists('file_get_contents')) {
  30      function file_get_contents($filename)
  31      {
  32          $fp = fopen($filename, 'rb');
  33          $ret = '';
  34          while (!feof($fp)) {
  35              $ret .= fread($fp, 8092);;
  36          }
  37          return $ret;
  38      }
  39  }
  40  /**
  41   * @nodep Gtk
  42   */
  43  if ('@include_path@' != '@'.'include_path'.'@') {
  44      ini_set('include_path', '@include_path@');
  45      $raw = false;
  46  } else {
  47      // this is a raw, uninstalled pear, either a cvs checkout, or php distro
  48      $raw = true;
  49  }
  50  @ini_set('allow_url_fopen', true);
  51  if (!ini_get('safe_mode')) {
  52      @set_time_limit(0);
  53  }
  54  ob_implicit_flush(true);
  55  @ini_set('track_errors', true);
  56  @ini_set('html_errors', false);
  57  @ini_set('magic_quotes_runtime', false);
  58  $_PEAR_PHPDIR = '#$%^&*';
  59  set_error_handler('error_handler');
  60  
  61  $pear_package_version = "@pear_version@";
  62  
  63  require_once  'PEAR.php';
  64  require_once 'PEAR/Frontend.php';
  65  require_once 'PEAR/Config.php';
  66  require_once 'PEAR/Command.php';
  67  require_once  'Console/Getopt.php';
  68  
  69  
  70  PEAR_Command::setFrontendType('CLI');
  71  $all_commands = PEAR_Command::getCommands();
  72  
  73  // remove this next part when we stop supporting that crap-ass PHP 4.2
  74  if (!isset($_SERVER['argv']) && !isset($argv) && !isset($HTTP_SERVER_VARS['argv'])) {
  75      die('ERROR: either use the CLI php executable, or set register_argc_argv=On in php.ini');
  76  }
  77  $argv = Console_Getopt::readPHPArgv();
  78  // fix CGI sapi oddity - the -- in pear.bat/pear is not removed
  79  if (php_sapi_name() != 'cli' && isset($argv[1]) && $argv[1] == '--') {
  80      unset($argv[1]);
  81      $argv = array_values($argv);
  82  }
  83  $progname = PEAR_RUNTYPE;
  84  if (in_array('getopt2', get_class_methods('Console_Getopt'))) {
  85      array_shift($argv);
  86      $options = Console_Getopt::getopt2($argv, "c:C:d:D:Gh?sSqu:vV");
  87  } else {
  88      $options = Console_Getopt::getopt($argv, "c:C:d:D:Gh?sSqu:vV");
  89  }
  90  if (PEAR::isError($options)) {
  91      usage($options);
  92  }
  93  
  94  $opts = $options[0];
  95  
  96  $fetype = 'CLI';
  97  if ($progname == 'gpear' || $progname == 'pear-gtk') {
  98      $fetype = 'Gtk';
  99  } else {
 100      foreach ($opts as $opt) {
 101          if ($opt[0] == 'G') {
 102              $fetype = 'Gtk';
 103          }
 104      }
 105  }
 106  //Check if Gtk and PHP >= 5.1.0
 107  if ($fetype == 'Gtk' && version_compare(phpversion(), '5.1.0', '>=')) {
 108      $fetype = 'Gtk2';
 109  }
 110  
 111  $pear_user_config = '';
 112  $pear_system_config = '';
 113  $store_user_config = false;
 114  $store_system_config = false;
 115  $verbose = 1;
 116  
 117  foreach ($opts as $opt) {
 118      switch ($opt[0]) {
 119          case 'c':
 120              $pear_user_config = $opt[1];
 121              break;
 122          case 'C':
 123              $pear_system_config = $opt[1];
 124              break;
 125      }
 126  }
 127  
 128  PEAR_Command::setFrontendType($fetype);
 129  $ui = &PEAR_Command::getFrontendObject();
 130  $config = &PEAR_Config::singleton($pear_user_config, $pear_system_config);
 131  
 132  if (PEAR::isError($config)) {
 133      $_file = '';
 134      if ($pear_user_config !== false) {
 135         $_file .= $pear_user_config;
 136      }
 137      if ($pear_system_config !== false) {
 138         $_file .= '/' . $pear_system_config;
 139      }
 140      if ($_file == '/') {
 141          $_file = 'The default config file';
 142      }
 143      $config->getMessage();
 144      $ui->outputData("ERROR: $_file is not a valid config file or is corrupted.");
 145      // We stop, we have no idea where we are :)
 146      exit();    
 147  }
 148  
 149  // this is used in the error handler to retrieve a relative path
 150  $_PEAR_PHPDIR = $config->get('php_dir');
 151  $ui->setConfig($config);
 152  PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError"));
 153  if (ini_get('safe_mode')) {
 154      $ui->outputData('WARNING: running in safe mode requires that all files created ' .
 155          'be the same uid as the current script.  PHP reports this script is uid: ' .
 156          @getmyuid() . ', and current user is: ' . @get_current_user());
 157  }
 158  
 159  $verbose = $config->get("verbose");
 160  $cmdopts = array();
 161  
 162  if ($raw) {
 163      if (!$config->isDefinedLayer('user') && !$config->isDefinedLayer('system')) {
 164          $found = false;
 165          foreach ($opts as $opt) {
 166              if ($opt[0] == 'd' || $opt[0] == 'D') {
 167                  $found = true; // the user knows what they are doing, and are setting config values
 168              }
 169          }
 170          if (!$found) {
 171              // no prior runs, try to install PEAR
 172              if (strpos(dirname(__FILE__), 'scripts')) {
 173                  $packagexml = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'package2.xml';
 174                  $pearbase = dirname(dirname(__FILE__));
 175              } else {
 176                  $packagexml = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'package2.xml';
 177                  $pearbase = dirname(__FILE__);
 178              }
 179              if (file_exists($packagexml)) {
 180                  $options[1] = array(
 181                      'install',
 182                      $packagexml
 183                  );
 184                  $config->set('php_dir', $pearbase . DIRECTORY_SEPARATOR . 'php');
 185                  $config->set('data_dir', $pearbase . DIRECTORY_SEPARATOR . 'data');
 186                  $config->set('doc_dir', $pearbase . DIRECTORY_SEPARATOR . 'docs');
 187                  $config->set('test_dir', $pearbase . DIRECTORY_SEPARATOR . 'tests');
 188                  $config->set('ext_dir', $pearbase . DIRECTORY_SEPARATOR . 'extensions');
 189                  $config->set('bin_dir', $pearbase);
 190                  $config->mergeConfigFile($pearbase . 'pear.ini', false);
 191                  $config->store();
 192                  $config->set('auto_discover', 1);
 193              }
 194          }
 195      }
 196  }
 197  foreach ($opts as $opt) {
 198      $param = !empty($opt[1]) ? $opt[1] : true;
 199      switch ($opt[0]) {
 200          case 'd':
 201              list($key, $value) = explode('=', $param);
 202              $config->set($key, $value, 'user');
 203              break;
 204          case 'D':
 205              list($key, $value) = explode('=', $param);
 206              $config->set($key, $value, 'system');
 207              break;
 208          case 's':
 209              $store_user_config = true;
 210              break;
 211          case 'S':
 212              $store_system_config = true;
 213              break;
 214          case 'u':
 215              $config->remove($param, 'user');
 216              break;
 217          case 'v':
 218              $config->set('verbose', $config->get('verbose') + 1);
 219              break;
 220          case 'q':
 221              $config->set('verbose', $config->get('verbose') - 1);
 222              break;
 223          case 'V':
 224              usage(null, 'version');
 225          case 'c':
 226          case 'C':
 227              break;
 228          default:
 229              // all non pear params goes to the command
 230              $cmdopts[$opt[0]] = $param;
 231              break;
 232      }
 233  }
 234  
 235  if ($store_system_config) {
 236      $config->store('system');
 237  }
 238  
 239  if ($store_user_config) {
 240      $config->store('user');
 241  }
 242  
 243  $command = (isset($options[1][0])) ? $options[1][0] : null;
 244  
 245  if (empty($command) && ($store_user_config || $store_system_config)) {
 246      exit;
 247  }
 248  
 249  if ($fetype == 'Gtk' || $fetype == 'Gtk2') {
 250      if (!$config->validConfiguration()) {
 251          PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' .
 252              "'$pear_user_config' or '$pear_system_config', please copy an existing configuration" .
 253              'file to one of these locations, or use the -c and -s options to create one');
 254      }
 255      Gtk::main();
 256  } else do {
 257      if ($command == 'help') {
 258          usage(null, @$options[1][1]);
 259      }
 260      if (!$config->validConfiguration()) {
 261          PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' .
 262              "'$pear_user_config' or '$pear_system_config', please copy an existing configuration" .
 263              'file to one of these locations, or use the -c and -s options to create one');
 264      }
 265  
 266      PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
 267      $cmd = PEAR_Command::factory($command, $config);
 268      PEAR::popErrorHandling();
 269      if (PEAR::isError($cmd)) {
 270          usage(null, @$options[1][0]);
 271      }
 272  
 273      $short_args = $long_args = null;
 274      PEAR_Command::getGetoptArgs($command, $short_args, $long_args);
 275      if (in_array('getopt2', get_class_methods('Console_Getopt'))) {
 276          array_shift($options[1]);
 277          $tmp = Console_Getopt::getopt2($options[1], $short_args, $long_args);
 278      } else {
 279          $tmp = Console_Getopt::getopt($options[1], $short_args, $long_args);
 280      }
 281      if (PEAR::isError($tmp)) {
 282          break;
 283      }
 284      list($tmpopt, $params) = $tmp;
 285      $opts = array();
 286      foreach ($tmpopt as $foo => $tmp2) {
 287          list($opt, $value) = $tmp2;
 288          if ($value === null) {
 289              $value = true; // options without args
 290          }
 291          if (strlen($opt) == 1) {
 292              $cmdoptions = $cmd->getOptions($command);
 293              foreach ($cmdoptions as $o => $d) {
 294                  if (@$d['shortopt'] == $opt) {
 295                      $opts[$o] = $value;
 296                  }
 297              }
 298          } else {
 299              if (substr($opt, 0, 2) == '--') {
 300                  $opts[substr($opt, 2)] = $value;
 301              }
 302          }
 303      }
 304      $ok = $cmd->run($command, $opts, $params);
 305      if ($ok === false) {
 306          PEAR::raiseError("unknown command `$command'");
 307      }
 308      if (PEAR::isError($ok)) {
 309          PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($ui, "displayFatalError"));
 310          PEAR::raiseError($ok);
 311      }
 312  } while (false);
 313  
 314  // {{{ usage()
 315  
 316  function usage($error = null, $helpsubject = null)
 317  {
 318      global $progname, $all_commands;
 319      $stderr = fopen('php://stderr', 'w');
 320      if (PEAR::isError($error)) {
 321          fputs($stderr, $error->getMessage() . "\n");
 322      } elseif ($error !== null) {
 323          fputs($stderr, "$error\n");
 324      }
 325      if ($helpsubject != null) {
 326          $put = cmdHelp($helpsubject);
 327      } else {
 328          $put =
 329              "Commands:\n";
 330          $maxlen = max(array_map("strlen", $all_commands));
 331          $formatstr = "%-{$maxlen}s  %s\n";
 332          ksort($all_commands);
 333          foreach ($all_commands as $cmd => $class) {
 334              $put .= sprintf($formatstr, $cmd, PEAR_Command::getDescription($cmd));
 335          }
 336          $put .=
 337              "Usage: $progname [options] command [command-options] <parameters>\n".
 338              "Type \"$progname help options\" to list all options.\n".
 339              "Type \"$progname help shortcuts\" to list all command shortcuts.\n".
 340              "Type \"$progname help <command>\" to get the help for the specified command.";
 341      }
 342      fputs($stderr, "$put\n");
 343      fclose($stderr);
 344      exit;
 345  }
 346  
 347  function cmdHelp($command)
 348  {
 349      global $progname, $all_commands, $config;
 350      if ($command == "options") {
 351          return
 352          "Options:\n".
 353          "     -v         increase verbosity level (default 1)\n".
 354          "     -q         be quiet, decrease verbosity level\n".
 355          "     -c file    find user configuration in `file'\n".
 356          "     -C file    find system configuration in `file'\n".
 357          "     -d foo=bar set user config variable `foo' to `bar'\n".
 358          "     -D foo=bar set system config variable `foo' to `bar'\n".
 359          "     -G         start in graphical (Gtk) mode\n".
 360          "     -s         store user configuration\n".
 361          "     -S         store system configuration\n".
 362          "     -u foo     unset `foo' in the user configuration\n".
 363          "     -h, -?     display help/usage (this message)\n".
 364          "     -V         version information\n";
 365      } elseif ($command == "shortcuts") {
 366          $sc = PEAR_Command::getShortcuts();
 367          $ret = "Shortcuts:\n";
 368          foreach ($sc as $s => $c) {
 369              $ret .= sprintf("     %-8s %s\n", $s, $c);
 370          }
 371          return $ret;
 372  
 373      } elseif ($command == "version") {
 374          return "PEAR Version: ".$GLOBALS['pear_package_version'].
 375                 "\nPHP Version: ".phpversion().
 376                 "\nZend Engine Version: ".zend_version().
 377                 "\nRunning on: ".php_uname();
 378  
 379      } elseif ($help = PEAR_Command::getHelp($command)) {
 380          if (is_string($help)) {
 381              return "$progname $command [options] $help\n";
 382          }
 383          if ($help[1] === null) {
 384              return "$progname $command $help[0]";
 385          } else {
 386              return "$progname $command [options] $help[0]\n$help[1]";
 387          }
 388      }
 389      return "Command '$command' is not valid, try 'pear help'";
 390  }
 391  
 392  // }}}
 393  
 394  function error_handler($errno, $errmsg, $file, $line, $vars) {
 395      if ((defined('E_STRICT') && $errno & E_STRICT) || !error_reporting()) {
 396          if (defined('E_STRICT') && $errno & E_STRICT) {
 397              return; // E_STRICT
 398          }
 399          if ($GLOBALS['config']->get('verbose') < 4) {
 400              return; // @silenced error, show all if debug is high enough
 401          }
 402      }
 403      $errortype = array (
 404          E_ERROR   =>  "Error",
 405          E_WARNING   =>  "Warning",
 406          E_PARSE   =>  "Parsing Error",
 407          E_NOTICE   =>  "Notice",
 408          E_CORE_ERROR  =>  "Core Error",
 409          E_CORE_WARNING  =>  "Core Warning",
 410          E_COMPILE_ERROR  =>  "Compile Error",
 411          E_COMPILE_WARNING =>  "Compile Warning",
 412          E_USER_ERROR =>  "User Error",
 413          E_USER_WARNING =>  "User Warning",
 414          E_USER_NOTICE =>  "User Notice"
 415      );
 416      $prefix = $errortype[$errno];
 417      global $_PEAR_PHPDIR;
 418      if (stristr($file, $_PEAR_PHPDIR)) {
 419          $file = substr($file, strlen($_PEAR_PHPDIR) + 1);
 420      } else {
 421          $file = basename($file);
 422      }
 423      print "\n$prefix: $errmsg in $file on line $line\n";
 424  }
 425  
 426  
 427  /*
 428   * Local variables:
 429   * tab-width: 4
 430   * c-basic-offset: 4
 431   * indent-tabs-mode: nil
 432   * mode: php
 433   * End:
 434   */
 435  // vim600:syn=php
 436  
 437  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics