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.13.2.2 2004/12/30 05:43:18 cellog Exp $
  22.  
  23. /**
  24.  * @nodep Gtk
  25.  */
  26. if ('@include_path@' != '@'.'include_path'.'@'{
  27.     ini_set('include_path''@include_path@');
  28. }
  29. ini_set('allow_url_fopen'true);
  30. if (!ini_get('safe_mode')) {
  31.     @set_time_limit(0);
  32. }
  33. ini_set('track_errors'true);
  34. ini_set('html_errors'false);
  35. ini_set('magic_quotes_runtime'false);
  36. set_error_handler('error_handler');
  37.  
  38. $pear_package_version "@pear_version@";
  39.  
  40. require_once 'PEAR.php';
  41. require_once 'PEAR/Config.php';
  42. require_once 'PEAR/Command.php';
  43. require_once 'Console/Getopt.php';
  44.  
  45. PEAR_Command::setFrontendType('CLI');
  46. $all_commands = PEAR_Command::getCommands();
  47.  
  48. $argv = Console_Getopt::readPHPArgv();
  49. /* $progname = basename($argv[0]); */
  50. $progname 'pear';
  51. if (in_array('getopt2'get_class_methods('Console_Getopt'))) {
  52.     array_shift($argv);
  53.     $options = Console_Getopt::getopt2($argv"c:C:d:D:Gh?sSqu:vV");
  54. else {
  55.     $options = Console_Getopt::getopt($argv"c:C:d:D:Gh?sSqu:vV");
  56. }
  57. if (PEAR::isError($options)) {
  58.     usage($options);
  59. }
  60.  
  61. $opts $options[0];
  62.  
  63. $fetype 'CLI';
  64. if ($progname == 'gpear' || $progname == 'pear-gtk'{
  65.     $fetype 'Gtk';
  66. else {
  67.     foreach ($opts as $opt{
  68.         if ($opt[0== 'G'{
  69.             $fetype 'Gtk';
  70.         }
  71.     }
  72. }
  73. PEAR_Command::setFrontendType($fetype);
  74. $ui &PEAR_Command::getFrontendObject();
  75. PEAR::setErrorHandling(PEAR_ERROR_CALLBACKarray($ui"displayFatalError"));
  76. if (ini_get('safe_mode')) {
  77.     $ui->outputData('WARNING: running in safe mode requires that all files created ' .
  78.         'be the same uid as the current script.  PHP reports this script is uid: ' .
  79.         @getmyuid(', and current user is: ' @get_current_user());
  80. }
  81.  
  82. $pear_user_config '';
  83. $pear_system_config '';
  84. $store_user_config = false;
  85. $store_system_config = false;
  86. $verbose = 1;
  87.  
  88. foreach ($opts as $opt{
  89.     switch ($opt[0]{
  90.         case 'c':
  91.             $pear_user_config $opt[1];
  92.             break;
  93.         case 'C':
  94.             $pear_system_config $opt[1];
  95.             break;
  96.     }
  97. }
  98.  
  99. $config &PEAR_Config::singleton($pear_user_config$pear_system_config);
  100. $verbose $config->get("verbose");
  101. $cmdopts = array();
  102.  
  103. foreach ($opts as $opt{
  104.     $param !empty($opt[1]$opt[1: true;
  105.     switch ($opt[0]{
  106.         case 'd':
  107.             list($key$valueexplode('='$param);
  108.             $config->set($key$value'user');
  109.             break;
  110.         case 'D':
  111.             list($key$valueexplode('='$param);
  112.             $config->set($key$value'system');
  113.             break;
  114.         case 's':
  115.             $store_user_config = true;
  116.             break;
  117.         case 'S':
  118.             $store_system_config = true;
  119.             break;
  120.         case 'u':
  121.             $config->remove($param'user');
  122.             break;
  123.         case 'v':
  124.             $config->set('verbose'$config->get('verbose'+ 1);
  125.             break;
  126.         case 'q':
  127.             $config->set('verbose'$config->get('verbose'- 1);
  128.             break;
  129.         case 'V':
  130.             usage(null'version');
  131.         default:
  132.             // all non pear params goes to the command
  133.             $cmdopts[$opt[0]] $param;
  134.             break;
  135.     }
  136. }
  137.  
  138. if ($store_system_config{
  139.     $config->store('system');
  140. }
  141.  
  142. if ($store_user_config{
  143.     $config->store('user');
  144. }
  145.  
  146. $command (isset($options[1][0])) $options[1][0: null;
  147.  
  148. if (empty($command&& ($store_user_config || $store_system_config)) {
  149.     exit;
  150. }
  151.  
  152. if ($fetype == 'Gtk'{
  153.     Gtk::main();
  154. else do {
  155.     if ($command == 'help'{
  156.         usage(null@$options[1][1]);
  157.     }
  158.  
  159.     PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  160.     $cmd = PEAR_Command::factory($command$config);
  161.     PEAR::popErrorHandling();
  162.     if (PEAR::isError($cmd)) {
  163.         usage(null@$options[1][1]);
  164.     }
  165.  
  166.     $short_args $long_args = null;
  167.     PEAR_Command::getGetoptArgs($command$short_args$long_args);
  168.     if (in_array('getopt2'get_class_methods('Console_Getopt'))) {
  169.         array_shift($options[1]);
  170.         $tmp = Console_Getopt::getopt2($options[1]$short_args$long_args);
  171.     else {
  172.         $tmp = Console_Getopt::getopt($options[1]$short_args$long_args);
  173.     }
  174.     if (PEAR::isError($tmp)) {
  175.         break;
  176.     }
  177.     list($tmpopt$params$tmp;
  178.     $opts = array();
  179.     foreach ($tmpopt as $foo => $tmp2{
  180.         list($opt$value$tmp2;
  181.         if ($value === null{
  182.             $value = true; // options without args
  183.         }
  184.         if (strlen($opt== 1{
  185.             $cmdoptions $cmd->getOptions($command);
  186.             foreach ($cmdoptions as $o => $d{
  187.                 if (@$d['shortopt'== $opt{
  188.                     $opts[$o$value;
  189.                 }
  190.             }
  191.         else {
  192.             if (substr($opt02== '--'{
  193.                 $opts[substr($opt2)$value;
  194.             }
  195.         }
  196.     }
  197.     $ok $cmd->run($command$opts$params);
  198.     if ($ok === false{
  199.         PEAR::raiseError("unknown command `$command'");
  200.     }
  201. while (false);
  202.  
  203. // {{{ usage()
  204.  
  205. function usage($error = null$helpsubject = null)
  206. {
  207.     global $progname$all_commands;
  208.     $stderr fopen('php://stderr''w');
  209.     if (PEAR::isError($error)) {
  210.         fputs($stderr$error->getMessage("\n");
  211.     elseif ($error !== null{
  212.         fputs($stderr"$error\n");
  213.     }
  214.     if ($helpsubject != null{
  215.         $put cmdHelp($helpsubject);
  216.     else {
  217.         $put =
  218.             "Commands:\n";
  219.         $maxlen max(array_map("strlen"$all_commands));
  220.         $formatstr = "%-{$maxlen}s  %s\n";
  221.         ksort($all_commands);
  222.         foreach ($all_commands as $cmd => $class{
  223.             $put .= sprintf($formatstr$cmdPEAR_Command::getDescription($cmd));
  224.         }
  225.         $put .=
  226.             "Usage: $progname [options] command [command-options] <parameters>\n".
  227.             "Type \"$progname help options\" to list all options.\n".
  228.             "Type \"$progname help shortcuts\" to list all command shortcuts.\n".
  229.             "Type \"$progname help <command>\" to get the help for the specified command.";
  230.     }
  231.     fputs($stderr"$put\n");
  232.     fclose($stderr);
  233.     exit;
  234. }
  235.  
  236. function cmdHelp($command)
  237. {
  238.     global $progname$all_commands$config;
  239.     if ($command == "options"{
  240.         return
  241.         "Options:\n".
  242.         "     -v         increase verbosity level (default 1)\n".
  243.         "     -q         be quiet, decrease verbosity level\n".
  244.         "     -c file    find user configuration in `file'\n".
  245.         "     -C file    find system configuration in `file'\n".
  246.         "     -d foo=bar set user config variable `foo' to `bar'\n".
  247.         "     -D foo=bar set system config variable `foo' to `bar'\n".
  248.         "     -G         start in graphical (Gtk) mode\n".
  249.         "     -s         store user configuration\n".
  250.         "     -S         store system configuration\n".
  251.         "     -u foo     unset `foo' in the user configuration\n".
  252.         "     -h, -?     display help/usage (this message)\n".
  253.         "     -V         version information\n";
  254.     elseif ($command == "shortcuts"{
  255.         $sc = PEAR_Command::getShortcuts();
  256.         $ret "Shortcuts:\n";
  257.         foreach ($sc as $s => $c{
  258.             $ret .= sprintf("     %-8s %s\n"$s$c);
  259.         }
  260.         return $ret;
  261.  
  262.     elseif ($command == "version"{
  263.         return "PEAR Version: ".$GLOBALS['pear_package_version'].
  264.                "\nPHP Version: ".phpversion().
  265.                "\nZend Engine Version: ".zend_version().
  266.                "\nRunning on: ".php_uname();
  267.  
  268.     elseif ($help = PEAR_Command::getHelp($command)) {
  269.         if (is_string($help)) {
  270.             return "$progname $command [options] $help\n";
  271.         }
  272.         if ($help[1=== null{
  273.             return "$progname $command $help[0]";
  274.         else {
  275.             return "$progname $command [options] $help[0]\n$help[1]";
  276.         }
  277.     }
  278.     return "Command '$command' is not valid, try 'pear help'";
  279. }
  280.  
  281. // }}}
  282.  
  283. function error_handler($errno$errmsg$file$line$vars{
  284.     if ((defined('E_STRICT'&& $errno E_STRICT|| !error_reporting()) {
  285.         return// @silenced error
  286.     }
  287.     $errortype = array (
  288.         E_ERROR   =>  "Error",
  289.         E_WARNING   =>  "Warning",
  290.         E_PARSE   =>  "Parsing Error",
  291.         E_NOTICE   =>  "Notice",
  292.         E_CORE_ERROR  =>  "Core Error",
  293.         E_CORE_WARNING  =>  "Core Warning",
  294.         E_COMPILE_ERROR  =>  "Compile Error",
  295.         E_COMPILE_WARNING =>  "Compile Warning",
  296.         E_USER_ERROR =>  "User Error",
  297.         E_USER_WARNING =>  "User Warning",
  298.         E_USER_NOTICE =>  "User Notice"
  299.     );
  300.     $prefix $errortype[$errno];
  301.     $file basename($file);
  302.     print "\n$prefix$errmsg in $file on line $line\n";
  303. }
  304.  
  305.  
  306. /*
  307.  * Local variables:
  308.  * tab-width: 4
  309.  * c-basic-offset: 4
  310.  * indent-tabs-mode: nil
  311.  * mode: php
  312.  * End:
  313.  */
  314. // vim600:syn=php
  315.  
  316. ?>

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