PEAR
[ class tree: PEAR ] [ index: PEAR ] [ all elements ]

Source for file pearcmd.php

Documentation is available at pearcmd.php

  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.24 2005/03/21 14:59:31 cellog Exp $
  22.  
  23. if (!defined('PEAR_RUNTYPE')) {
  24.     // this is defined in peclcmd.php as 'pecl'
  25.     define('PEAR_RUNTYPE''pear');
  26. }
  27. define('PEAR_IGNORE_BACKTRACE'1);
  28. /**
  29.  * @nodep Gtk
  30.  */
  31. if ('@include_path@' != '@'.'include_path'.'@'{
  32.     ini_set('include_path''@include_path@');
  33.     $raw = false;
  34. else {
  35.     // this is a raw, uninstalled pear, either a cvs checkout, or php distro
  36.     $raw = true;
  37. }
  38. @ini_set('allow_url_fopen'true);
  39. if (!ini_get('safe_mode')) {
  40.     @set_time_limit(0);
  41. }
  42. @ini_set('track_errors'true);
  43. @ini_set('html_errors'false);
  44. @ini_set('magic_quotes_runtime'false);
  45. $_PEAR_PHPDIR '#$%^&*';
  46. set_error_handler('error_handler');
  47.  
  48. $pear_package_version "@pear_version@";
  49.  
  50. require_once 'PEAR.php';
  51. require_once 'PEAR/Frontend.php';
  52. require_once 'PEAR/Config.php';
  53. require_once 'PEAR/Command.php';
  54. require_once 'Console/Getopt.php';
  55.  
  56.  
  57. $all_commands PEAR_Command::getCommands();
  58.  
  59. $argv = Console_Getopt::readPHPArgv();
  60. $progname PEAR_RUNTYPE;
  61. if (in_array('getopt2'get_class_methods('Console_Getopt'))) {
  62.     array_shift($argv);
  63.     $options = Console_Getopt::getopt2($argv"c:C:d:D:Gh?sSqu:vV");
  64. else {
  65.     $options = Console_Getopt::getopt($argv"c:C:d:D:Gh?sSqu:vV");
  66. }
  67. if (PEAR::isError($options)) {
  68.     usage($options);
  69. }
  70.  
  71. $opts $options[0];
  72.  
  73. $fetype 'CLI';
  74. if ($progname == 'gpear' || $progname == 'pear-gtk'{
  75.     $fetype 'Gtk';
  76. else {
  77.     foreach ($opts as $opt{
  78.         if ($opt[0== 'G'{
  79.             $fetype 'Gtk';
  80.         }
  81.     }
  82. }
  83. $pear_user_config '';
  84. $pear_system_config '';
  85. $store_user_config = false;
  86. $store_system_config = false;
  87. $verbose = 1;
  88.  
  89. foreach ($opts as $opt{
  90.     switch ($opt[0]{
  91.         case 'c':
  92.             $pear_user_config $opt[1];
  93.             break;
  94.         case 'C':
  95.             $pear_system_config $opt[1];
  96.             break;
  97.     }
  98. }
  99.  
  100. $config &PEAR_Config::singleton($pear_user_config$pear_system_config);
  101. // this is used in the error handler to retrieve a relative path
  102. $_PEAR_PHPDIR $config->get('php_dir');
  103. $ui->setConfig($config);
  104. PEAR::setErrorHandling(PEAR_ERROR_CALLBACKarray($ui"displayFatalError"));
  105. if (ini_get('safe_mode')) {
  106.     $ui->outputData('WARNING: running in safe mode requires that all files created ' .
  107.         'be the same uid as the current script.  PHP reports this script is uid: ' .
  108.         @getmyuid(', and current user is: ' @get_current_user());
  109. }
  110.  
  111. $verbose $config->get("verbose");
  112. $cmdopts = array();
  113.  
  114. if ($raw{
  115.     if (!$config->isDefinedLayer('user'&& !$config->isDefinedLayer('system')) {
  116.         $found = false;
  117.         foreach ($opts as $opt{
  118.             if ($opt[0== 'd' || $opt[0== 'D'{
  119.                 $found = true; // the user knows what they are doing, and are setting config values
  120.             }
  121.         }
  122.         if (!$found{
  123.             // no prior runs, try to install PEAR
  124.             if (strpos(dirname(__FILE__)'scripts')) {
  125.                 $packagexml dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'package2.xml';
  126.                 $pearbase dirname(dirname(__FILE__));
  127.             else {
  128.                 $packagexml dirname(__FILE__. DIRECTORY_SEPARATOR . 'package2.xml';
  129.                 $pearbase dirname(__FILE__);
  130.             }
  131.             if (file_exists($packagexml)) {
  132.                 $options[1= array(
  133.                     'install',
  134.                     $packagexml
  135.                 );
  136.                 $config->set('php_dir'$pearbase . DIRECTORY_SEPARATOR . 'php');
  137.                 $config->set('data_dir'$pearbase . DIRECTORY_SEPARATOR . 'data');
  138.                 $config->set('doc_dir'$pearbase . DIRECTORY_SEPARATOR . 'docs');
  139.                 $config->set('test_dir'$pearbase . DIRECTORY_SEPARATOR . 'tests');
  140.                 $config->set('ext_dir'$pearbase . DIRECTORY_SEPARATOR . 'extensions');
  141.                 $config->set('bin_dir'$pearbase);
  142.                 $config->mergeConfigFile($pearbase 'pear.ini'false);
  143.                 $config->store();
  144.                 $config->set('auto_discover'1);
  145.             }
  146.         }
  147.     }
  148. }
  149. foreach ($opts as $opt{
  150.     $param !empty($opt[1]$opt[1: true;
  151.     switch ($opt[0]{
  152.         case 'd':
  153.             list($key$valueexplode('='$param);
  154.             $config->set($key$value'user');
  155.             break;
  156.         case 'D':
  157.             list($key$valueexplode('='$param);
  158.             $config->set($key$value'system');
  159.             break;
  160.         case 's':
  161.             $store_user_config = true;
  162.             break;
  163.         case 'S':
  164.             $store_system_config = true;
  165.             break;
  166.         case 'u':
  167.             $config->remove($param'user');
  168.             break;
  169.         case 'v':
  170.             $config->set('verbose'$config->get('verbose'+ 1);
  171.             break;
  172.         case 'q':
  173.             $config->set('verbose'$config->get('verbose'- 1);
  174.             break;
  175.         case 'V':
  176.             usage(null'version');
  177.         case 'c':
  178.         case 'C':
  179.             break;
  180.         default:
  181.             // all non pear params goes to the command
  182.             $cmdopts[$opt[0]] $param;
  183.             break;
  184.     }
  185. }
  186.  
  187. if ($store_system_config{
  188.     $config->store('system');
  189. }
  190.  
  191. if ($store_user_config{
  192.     $config->store('user');
  193. }
  194.  
  195. $command (isset($options[1][0])) $options[1][0: null;
  196.  
  197. if (empty($command&& ($store_user_config || $store_system_config)) {
  198.     exit;
  199. }
  200.  
  201. if ($fetype == 'Gtk'{
  202.     if (!$config->validConfiguration()) {
  203.         PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' .
  204.             "'$pear_user_config' or '$pear_system_config', please copy an existing configuration" .
  205.             'file to one of these locations, or use the -c and -s options to create one');
  206.     }
  207.     Gtk::main();
  208. else do {
  209.     if ($command == 'help'{
  210.         usage(null@$options[1][1]);
  211.     }
  212.     if (!$config->validConfiguration()) {
  213.         PEAR::raiseError('CRITICAL ERROR: no existing valid configuration files found in files ' .
  214.             "'$pear_user_config' or '$pear_system_config', please copy an existing configuration" .
  215.             'file to one of these locations, or use the -c and -s options to create one');
  216.     }
  217.  
  218.     $cmd PEAR_Command::factory($command$config);
  219.     if (PEAR::isError($cmd)) {
  220.         usage(null@$options[1][0]);
  221.     }
  222.  
  223.     $short_args $long_args = null;
  224.     PEAR_Command::getGetoptArgs($command$short_args$long_args);
  225.     if (in_array('getopt2'get_class_methods('Console_Getopt'))) {
  226.         array_shift($options[1]);
  227.         $tmp = Console_Getopt::getopt2($options[1]$short_args$long_args);
  228.     else {
  229.         $tmp = Console_Getopt::getopt($options[1]$short_args$long_args);
  230.     }
  231.     if (PEAR::isError($tmp)) {
  232.         break;
  233.     }
  234.     list($tmpopt$params$tmp;
  235.     $opts = array();
  236.     foreach ($tmpopt as $foo => $tmp2{
  237.         list($opt$value$tmp2;
  238.         if ($value === null{
  239.             $value = true; // options without args
  240.         }
  241.         if (strlen($opt== 1{
  242.             $cmdoptions $cmd->getOptions($command);
  243.             foreach ($cmdoptions as $o => $d{
  244.                 if (@$d['shortopt'== $opt{
  245.                     $opts[$o$value;
  246.                 }
  247.             }
  248.         else {
  249.             if (substr($opt02== '--'{
  250.                 $opts[substr($opt2)$value;
  251.             }
  252.         }
  253.     }
  254.     $ok $cmd->run($command$opts$params);
  255.     if ($ok === false{
  256.         PEAR::raiseError("unknown command `$command'");
  257.     }
  258. while (false);
  259.  
  260. // {{{ usage()
  261.  
  262. function usage($error = null$helpsubject = null)
  263. {
  264.     global $progname$all_commands;
  265.     $stderr fopen('php://stderr''w');
  266.     if (PEAR::isError($error)) {
  267.         fputs($stderr$error->getMessage("\n");
  268.     elseif ($error !== null{
  269.         fputs($stderr"$error\n");
  270.     }
  271.     if ($helpsubject != null{
  272.         $put cmdHelp($helpsubject);
  273.     else {
  274.         $put =
  275.             "Commands:\n";
  276.         $maxlen max(array_map("strlen"$all_commands));
  277.         $formatstr = "%-{$maxlen}s  %s\n";
  278.         ksort($all_commands);
  279.         foreach ($all_commands as $cmd => $class{
  280.             $put .= sprintf($formatstr$cmdPEAR_Command::getDescription($cmd));
  281.         }
  282.         $put .=
  283.             "Usage: $progname [options] command [command-options] <parameters>\n".
  284.             "Type \"$progname help options\" to list all options.\n".
  285.             "Type \"$progname help shortcuts\" to list all command shortcuts.\n".
  286.             "Type \"$progname help <command>\" to get the help for the specified command.";
  287.     }
  288.     fputs($stderr"$put\n");
  289.     fclose($stderr);
  290.     exit;
  291. }
  292.  
  293. function cmdHelp($command)
  294. {
  295.     global $progname$all_commands$config;
  296.     if ($command == "options"{
  297.         return
  298.         "Options:\n".
  299.         "     -v         increase verbosity level (default 1)\n".
  300.         "     -q         be quiet, decrease verbosity level\n".
  301.         "     -c file    find user configuration in `file'\n".
  302.         "     -C file    find system configuration in `file'\n".
  303.         "     -d foo=bar set user config variable `foo' to `bar'\n".
  304.         "     -D foo=bar set system config variable `foo' to `bar'\n".
  305.         "     -G         start in graphical (Gtk) mode\n".
  306.         "     -s         store user configuration\n".
  307.         "     -S         store system configuration\n".
  308.         "     -u foo     unset `foo' in the user configuration\n".
  309.         "     -h, -?     display help/usage (this message)\n".
  310.         "     -V         version information\n";
  311.     elseif ($command == "shortcuts"{
  312.         $sc PEAR_Command::getShortcuts();
  313.         $ret "Shortcuts:\n";
  314.         foreach ($sc as $s => $c{
  315.             $ret .= sprintf("     %-8s %s\n"$s$c);
  316.         }
  317.         return $ret;
  318.  
  319.     elseif ($command == "version"{
  320.         return "PEAR Version: ".$GLOBALS['pear_package_version'].
  321.                "\nPHP Version: ".phpversion().
  322.                "\nZend Engine Version: ".zend_version().
  323.                "\nRunning on: ".php_uname();
  324.  
  325.     elseif ($help PEAR_Command::getHelp($command)) {
  326.         if (is_string($help)) {
  327.             return "$progname $command [options] $help\n";
  328.         }
  329.         if ($help[1=== null{
  330.             return "$progname $command $help[0]";
  331.         else {
  332.             return "$progname $command [options] $help[0]\n$help[1]";
  333.         }
  334.     }
  335.     return "Command '$command' is not valid, try 'pear help'";
  336. }
  337.  
  338. // }}}
  339.  
  340. function error_handler($errno$errmsg$file$line$vars{
  341.     if ((defined('E_STRICT'&& $errno E_STRICT|| !error_reporting()) {
  342.         return// @silenced error
  343.     }
  344.     $errortype = array (
  345.         E_ERROR   =>  "Error",
  346.         E_WARNING   =>  "Warning",
  347.         E_PARSE   =>  "Parsing Error",
  348.         E_NOTICE   =>  "Notice",
  349.         E_CORE_ERROR  =>  "Core Error",
  350.         E_CORE_WARNING  =>  "Core Warning",
  351.         E_COMPILE_ERROR  =>  "Compile Error",
  352.         E_COMPILE_WARNING =>  "Compile Warning",
  353.         E_USER_ERROR =>  "User Error",
  354.         E_USER_WARNING =>  "User Warning",
  355.         E_USER_NOTICE =>  "User Notice"
  356.     );
  357.     $prefix $errortype[$errno];
  358.     $file basename($file);
  359.     if (function_exists('debug_backtrace')) {
  360.         $trace debug_backtrace();
  361.         if (isset($trace[1]&& isset($trace[1]['file'])) {
  362.             $dir $trace[1]['file'];
  363.             global $_PEAR_PHPDIR;
  364.             if (stristr($dir$_PEAR_PHPDIR)) {
  365.                 $file substr($dirstrlen($_PEAR_PHPDIR+ 1);
  366.             }
  367.         }
  368.     }
  369.     print "\n$prefix$errmsg in $file on line $line\n";
  370. }
  371.  
  372.  
  373. /*
  374.  * Local variables:
  375.  * tab-width: 4
  376.  * c-basic-offset: 4
  377.  * indent-tabs-mode: nil
  378.  * mode: php
  379.  * End:
  380.  */
  381. // vim600:syn=php
  382.  
  383. ?>

Documentation generated on Mon, 11 Mar 2019 14:15:33 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.