]> granicus.if.org Git - php/commitdiff
* rename PEAR_CommandUI* to PEAR_Frontend*
authorStig Bakken <ssb@php.net>
Fri, 22 Mar 2002 09:22:28 +0000 (09:22 +0000)
committerStig Bakken <ssb@php.net>
Fri, 22 Mar 2002 09:22:28 +0000 (09:22 +0000)
* rename PEAR/Command/Login.php to PEAR/Command/Auth.php
* replace PEAR/Command/Info.php with PEAR/Command/Registry.php (will contain
  more commands related to the local registry)
* started working on Frontend table output

12 files changed:
pear/Makefile.frag
pear/PEAR/Command.php
pear/PEAR/Command/Auth.php [moved from pear/PEAR/Command/Login.php with 95% similarity]
pear/PEAR/Command/Common.php
pear/PEAR/Command/Install.php
pear/PEAR/Command/List.php [deleted file]
pear/PEAR/Command/Package.php
pear/PEAR/Command/Registry.php [new file with mode: 0644]
pear/PEAR/CommandUI/CLI.php [deleted file]
pear/PEAR/Frontend/CLI.php [new file with mode: 0644]
pear/PEAR/Installer.php
pear/PEAR/Remote.php

index 5a1cf57de4d73af47e1614aaef20dd5533a6a2d6..7a1692bdbffa06c2ea5c13f32fa194492471614a 100644 (file)
@@ -70,13 +70,14 @@ PEAR_FILES = \
        PEAR.php \
        PEAR/Autoloader.php \
        PEAR/Command.php \
+       PEAR/Command/Auth.php \
        PEAR/Command/Common.php \
        PEAR/Command/Config.php \
        PEAR/Command/Install.php \
-       PEAR/Command/Login.php \
        PEAR/Command/Package.php \
+       PEAR/Command/Registry.php \
        PEAR/CommandResponse.php \
-       PEAR/CommandUI/CLI.php \
+       PEAR/Frontend/CLI.php \
        PEAR/Common.php \
        PEAR/Config.php \
        PEAR/Dependency.php \
index f0f88eaefe2a778109a76fa2eabccbc28f0ac151..851099e66bffb0c22795fb9ec725e3653a54765f 100644 (file)
@@ -31,7 +31,7 @@ $GLOBALS['_PEAR_Command_commandlist'] = array();
  * Which user interface class is being used.
  * @var string class name
  */
-$GLOBALS['_PEAR_Command_uiclass'] = 'PEAR_CommandUI_CLI';
+$GLOBALS['_PEAR_Command_uiclass'] = 'PEAR_Frontend_CLI';
 
 /**
 * The options accepted by the commands
@@ -101,13 +101,13 @@ class PEAR_Command
         }
         if (isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
             $class = $GLOBALS['_PEAR_Command_commandlist'][$command];
-            $obj = &new $class(PEAR_Command::getUIObject(), $config);
+            $obj = &new $class(PEAR_Command::getFrontendObject(), $config);
             return $obj;
         }
         return PEAR::raiseError("unknown command `$command'");
     }
 
-    function &getUIObject()
+    function &getFrontendObject()
     {
         global $_PEAR_Command_uiclass, $_PEAR_Command_uiobject;
         if (empty($_PEAR_Command_uiobject)) {
@@ -116,7 +116,7 @@ class PEAR_Command
         return $_PEAR_Command_uiobject;
     }
 
-    function setUIClass($uiclass)
+    function setFrontendClass($uiclass)
     {
         $GLOBALS['_PEAR_Command_uiclass'] = $uiclass;
         $file = str_replace("_", "/", $uiclass) . '.php';
@@ -124,10 +124,10 @@ class PEAR_Command
         return class_exists(strtolower($uiclass));
     }
 
-    function setUIType($uitype)
+    function setFrontendType($uitype)
     {
-        $uiclass = 'PEAR_CommandUI_' . $uitype;
-        return PEAR_Command::setUIClass($uiclass);
+        $uiclass = 'PEAR_Frontend_' . $uitype;
+        return PEAR_Command::setFrontendClass($uiclass);
     }
 
     /**
similarity index 95%
rename from pear/PEAR/Command/Login.php
rename to pear/PEAR/Command/Auth.php
index 44c85c909bc2880ecb63591fcf860e0ccc86c1f5..735c2e311cf0f1c8283521a8470549c7abcba06e 100644 (file)
@@ -37,7 +37,7 @@ class PEAR_Command_Login extends PEAR_Command_Common
      */
     function PEAR_Command_Login(&$ui, &$config)
     {
-        parent::PEAR_Command_Common($ui);
+        parent::PEAR_Command_Common($ui, $config);
     }
 
     // }}}
@@ -66,7 +66,8 @@ class PEAR_Command_Login extends PEAR_Command_Common
      *
      * @param array list of additional parameters
      *
-     * @return bool TRUE on success, PEAR error on failure
+     * @return bool TRUE on success, FALSE for unknown commands, or
+     * a PEAR error on failure
      *
      * @access public
      */
@@ -77,6 +78,7 @@ class PEAR_Command_Login extends PEAR_Command_Common
         $server = $cf->get('master_server');
         switch ($command) {
             case 'login': {
+                $remote = new PEAR_Remote($cf);
                 $username = $cf->get('username');
                 if (empty($username)) {
                     $username = @$_ENV['USER'];
@@ -87,7 +89,6 @@ class PEAR_Command_Login extends PEAR_Command_Common
                 $cf->set('username', $username);
                 $password = trim($this->ui->userDialog('Password', 'password'));
                 $cf->set('password', $password);
-                $remote = new PEAR_Remote($cf);
                 $remote->expectError(401);
                 $ok = $remote->call('logintest');
                 $remote->popExpect();
@@ -107,8 +108,7 @@ class PEAR_Command_Login extends PEAR_Command_Common
                 break;
             }
             default: {
-                $failmsg = "unknown command: $command";
-                break;
+                return false;
             }
         }
         if ($failmsg) {
index 0ae02ebddd843c78165a17b78c1e1f6fe6f354d4..7ea724a999e202550c1f3845979fb6762085aac4 100644 (file)
@@ -45,8 +45,8 @@ class PEAR_Command_Common extends PEAR
     function PEAR_Command_Common(&$ui, &$config)
     {
         parent::PEAR();
-        $this->config =$config;
-        $this->ui = $ui;
+        $this->config = &$config;
+        $this->ui = &$ui;
     }
 
     function getOptions()
index e858adf5e079d88d8f4dfa23200f69ea1ee77a4b..3a8702bd929cf4b8c7139db05686e14d1d753397 100644 (file)
@@ -66,6 +66,7 @@ class PEAR_Command_Install extends PEAR_Command_Common
                                          $this->config->get('ext_dir'),
                                          $this->config->get('doc_dir'));
         $installer->debug = $this->config->get('verbose');
+
         $failmsg = '';
         $opts = array();
         switch ($command) {
diff --git a/pear/PEAR/Command/List.php b/pear/PEAR/Command/List.php
deleted file mode 100644 (file)
index 7334c18..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-<?php
-//
-// +----------------------------------------------------------------------+
-// | PHP Version 4                                                        |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997-2002 The PHP Group                                |
-// +----------------------------------------------------------------------+
-// | This source file is subject to version 2.02 of the PHP license,      |
-// | that is bundled with this package in the file LICENSE, and is        |
-// | available at through the world-wide-web at                           |
-// | http://www.php.net/license/2_02.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.               |
-// +----------------------------------------------------------------------+
-// | Author: Stig Bakken <ssb@fast.no>                                    |
-// +----------------------------------------------------------------------+
-//
-// $Id$
-
-require_once "PEAR/Command/Common.php";
-require_once "PEAR/Registry.php";
-
-/**
- * PEAR commands for managing configuration data.
- *
- */
-class PEAR_Command_List extends PEAR_Command_Common
-{
-    // {{{ properties
-    // }}}
-
-    // {{{ constructor
-
-    /**
-     * PEAR_Command_Config constructor.
-     *
-     * @access public
-     */
-    function PEAR_Command_List(&$ui, &$config)
-    {
-        parent::PEAR_Command_Common($ui, $config);
-    }
-
-    // }}}
-
-    // {{{ getCommands()
-
-    /**
-     * Return a list of all the commands defined by this class.
-     * @return array list of commands
-     * @access public
-     */
-    function getCommands()
-    {
-        return array('list');
-    }
-
-    // }}}
-    // {{{ run()
-
-    function run($command, $options, $params)
-    {
-        $reg = new PEAR_Registry(); // XXX Use config here
-        $installed = $reg->packageInfo();
-        $i = $j = 0;
-        ob_start();
-        heading("Installed packages:");
-        foreach ($installed as $package) {
-            if ($i++ % 20 == 0) {
-                if ($j++ > 0) {
-                    print "\n";
-                }
-                printf("%-20s %-10s %s\n",
-                       "Package", "Version", "State");
-                print str_repeat("-", 75)."\n";
-            }
-            printf("%-20s %-10s %s\n", $package['package'],
-                   $package['version'], $package['release_state']);
-        }
-        $output = ob_get_contents();
-        ob_end_clean();
-        $lines = explode("\n", $output);
-        foreach ($lines as $line) {
-            $this->ui->displayLine($line);
-        }
-    }
-}
-?>
\ No newline at end of file
index f3f7a27e67955ec4e3d176383270f482b41cafc2..cea5a627fb1cf6102cc6aa72e711d634aef1a2e2 100644 (file)
@@ -8,7 +8,7 @@ class PEAR_Command_Package extends PEAR_Command_Common
     // {{{ constructor
 
     /**
-     * PEAR_Command_Login constructor.
+     * PEAR_Command_Package constructor.
      *
      * @access public
      */
diff --git a/pear/PEAR/Command/Registry.php b/pear/PEAR/Command/Registry.php
new file mode 100644 (file)
index 0000000..f5444fc
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+
+require_once 'PEAR/Command/Common.php';
+require_once 'PEAR/Registry.php';
+require_once 'PEAR/Config.php';
+
+class PEAR_Command_Registry extends PEAR_Command_Common
+{
+    // {{{ constructor
+
+    /**
+     * PEAR_Command_Registry constructor.
+     *
+     * @access public
+     */
+    function PEAR_Command_Registry(&$ui)
+    {
+        parent::PEAR_Command_Common($ui);
+    }
+
+    // }}}
+
+    // {{{ getCommands()
+
+    /**
+     * Return a list of all the commands defined by this class.
+     * @return array list of commands
+     * @access public
+     */
+    function getCommands()
+    {
+        return array('list-installed');
+    }
+
+    // }}}
+    // {{{ run()
+
+    /**
+     * Execute the command.
+     *
+     * @param string command name
+     *
+     * @param array option_name => value
+     *
+     * @param array list of additional parameters
+     *
+     * @return bool TRUE on success, FALSE if the command was unknown,
+     *              or a PEAR error on failure
+     *
+     * @access public
+     */
+    function run($command, $options, $params)
+    {
+        $failmsg = '';
+        $cf = &PEAR_Config::singleton();
+        switch ($command) {
+            case 'list-installed': {
+                $reg = new PEAR_Registry($cf->get('php_dir'));
+                $installed = $reg->packageInfo();
+                $i = $j = 0;
+                heading("Installed packages:");
+                foreach ($installed as $package) {
+                    if ($i++ % 20 == 0) {
+                        if ($j++ > 0) {
+                            print "\n";
+                        }
+                        printf("%-20s %-10s %s\n",
+                               "Package", "Version", "State");
+                        print str_repeat("-", 75)."\n";
+                    }
+                    printf("%-20s %-10s %s\n", $package['package'],
+                           $package['version'], $package['release_state']);
+                }
+                break;
+            }
+            default: {
+                return false;
+            }
+        }
+        if ($failmsg) {
+            return $this->raiseError($failmsg);
+        }
+        return true;
+    }
+
+    // }}}
+
+
+}
+
+?>
\ No newline at end of file
diff --git a/pear/PEAR/CommandUI/CLI.php b/pear/PEAR/CommandUI/CLI.php
deleted file mode 100644 (file)
index 76ea6f6..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-
-require_once "PEAR.php";
-
-class PEAR_CommandUI_CLI extends PEAR
-{
-    var $output_mode = 'plain';
-    var $output_mode_params = array();
-
-    function PEAR_CommandUI_CLI()
-    {
-        parent::PEAR();
-    }
-
-    function _PEAR_CommandUI_CLI()
-    {
-        parent::_PEAR();
-        if ($this->output_mode) {
-            $this->endOutput();
-        }
-    }
-
-    function displayLine($text)
-    {
-        print "$text\n";
-    }
-
-    function userDialog($prompt, $type = 'text', $default = '')
-    {
-        if ($type == 'password') {
-            system('stty -echo');
-        }
-        print "$prompt ";
-        if ($default) {
-            print "[$default] ";
-        }
-        print ": ";
-        $fp = fopen("php://stdin", "r");
-        $line = fgets($fp, 2048);
-        fclose($fp);
-        if ($type == 'password') {
-            system('stty echo');
-            print "\n";
-        }
-        if ($default && trim($line) == "") {
-            return $default;
-        }
-        return $line;
-    }
-
-    function userConfirm($prompt, $default = 'yes')
-    {
-        static $positives = array('y', 'yes', 'on', '1');
-        static $negatives = array('n', 'no', 'off', '0');
-        print "$prompt [$default] : ";
-        $fp = fopen("php://stdin", "r");
-        $line = fgets($fp, 2048);
-        fclose($fp);
-        $answer = strtolower(trim($line));
-        if (empty($answer)) {
-            $answer = $default;
-        }
-        if (in_array($answer, $positives)) {
-            return true;
-        }
-        if (in_array($answer, $negatives)) {
-            return false;
-        }
-        if (in_array($default, $positives)) {
-            return true;
-        }
-        return false;
-    }
-
-    function setOutputMode($mode, $params = array())
-    {
-        $this->output_mode = $mode;
-        $this->output_mode_params = $params;
-    }
-
-    function startOutput($mode)
-    {
-        if ($this->output_mode) {
-            $this->endOutput();
-        }
-        switch ($mode) {
-        }
-    }
-
-    function endOutput($mode = null)
-    {
-        if ($mode === null) {
-            $mode = $this->output_mode;
-        }
-        $this->output_mode = '';
-        switch ($mode) {
-        }
-    }
-}
-
-?>
\ No newline at end of file
diff --git a/pear/PEAR/Frontend/CLI.php b/pear/PEAR/Frontend/CLI.php
new file mode 100644 (file)
index 0000000..22ff678
--- /dev/null
@@ -0,0 +1,154 @@
+<?php
+
+require_once "PEAR.php";
+
+class PEAR_Frontend_CLI extends PEAR
+{
+    var $omode = 'plain';
+    var $params = array();
+
+    function PEAR_Frontend_CLI()
+    {
+        parent::PEAR();
+    }
+
+    function _PEAR_Frontend_CLI()
+    {
+        parent::_PEAR();
+        if ($this->omode) {
+            $this->endOutput();
+        }
+    }
+
+    function displayLine($text)
+    {
+        print "| $text\n";
+    }
+
+    function displayHeading($title)
+    {
+        print "| ".strtoupper($title)."\n";
+        print "| ".str_repeat("=", strlen($title))."\n";
+    }
+
+    function userDialog($prompt, $type = 'text', $default = '')
+    {
+        if ($type == 'password') {
+            system('stty -echo');
+        }
+        print "| $prompt ";
+        if ($default) {
+            print "[$default] ";
+        }
+        print ": ";
+        $fp = fopen("php://stdin", "r");
+        $line = fgets($fp, 2048);
+        fclose($fp);
+        if ($type == 'password') {
+            system('stty echo');
+            print "\n";
+        }
+        if ($default && trim($line) == "") {
+            return $default;
+        }
+        return $line;
+    }
+
+    function userConfirm($prompt, $default = 'yes')
+    {
+        static $positives = array('y', 'yes', 'on', '1');
+        static $negatives = array('n', 'no', 'off', '0');
+        print "| $prompt [$default] : ";
+        $fp = fopen("php://stdin", "r");
+        $line = fgets($fp, 2048);
+        fclose($fp);
+        $answer = strtolower(trim($line));
+        if (empty($answer)) {
+            $answer = $default;
+        }
+        if (in_array($answer, $positives)) {
+            return true;
+        }
+        if (in_array($answer, $negatives)) {
+            return false;
+        }
+        if (in_array($default, $positives)) {
+            return true;
+        }
+        return false;
+    }
+
+    function startTable($params = array())
+    {
+        $this->omode = 'table';
+        $params['table_data'] = array();
+        $params['widest'] = array();
+        $params['ncols'] = 0;
+        $this->params = $params;
+    }
+
+    function tableRow($columns, $rowparams = array(), $colparams = array())
+    {
+        for ($i = 0; $i < sizeof($columns); $i++) {
+            if (!isset($this->params['widest'][$i]) ||
+                strlen($columns[$i] > $this->params['widest'][$i]))
+            {
+                $this->params['widest'][$i] = strlen($columns[$i]);
+            }
+        }
+        if (!isset($this->params['ncols']) ||
+            sizeof($columns) > $this->params['ncols'])
+        {
+            $this->params['ncols'] = sizeof($columns);
+        }
+        $new_row = array(
+            'data' => $columns,
+            'rowparams' => $rowparams,
+            'colparams' => $colparams,
+            );
+        $this->params['table_data'][] = $new_row;
+    }
+
+    function endTable()
+    {
+        $this->omode = '';
+        extract($this->params);
+        if (!empty($caption)) {
+            $this->displayHeading($caption);
+        }
+        if (!isset($width)) {
+            $width = $widest;
+        } else {
+            for ($i = 0; $i < $ncols; $i++) {
+                if (!isset($width[$i])) {
+                    $width[$i] = $widest[$i];
+                }
+            }
+        }
+        if (empty($params['border'])) {
+            $cellstart = " ";
+            $rowend = "\n";
+            $padrowend = false;
+        } else {
+            $cellstart = "| ";
+            $rowend = " |\n";
+            $padrowend = true;
+            $borderline = "+";
+            foreach ($width as $w) {
+                $borderline .= str_repeat('-', $w + 2);
+            }
+        }
+        for ($i = 0; $i < sizeof($table_data); $i++) {
+            extract($table_data[$i]);
+            for ($c = 0; $c < sizeof($data); $c++) {
+                $w = $width[$c];
+                $l = strlen($data[$c]);
+                if ($l > $w) {
+                    print
+                }
+            }
+        }
+    }
+}
+
+?>
\ No newline at end of file
index 0e9dbdaf191e03021ced5316d2eb7653ef7e918e..e24688d15edd2a55c47f2edd268bf8b7c571d5a1 100644 (file)
@@ -68,9 +68,7 @@ class PEAR_Installer extends PEAR_Common
 
     // {{{ constructor
 
-    function PEAR_Installer($phpdir = PEAR_INSTALL_DIR,
-                            $extdir = PEAR_EXTENSION_DIR,
-                            $docdir = null)
+    function PEAR_Installer(&$config)
     {
         $this->PEAR();
         $this->phpdir = $phpdir;
index 3ecbb5f4f541c92dbcb7af0955bcc8c4397d4648..97317cc71c966b7f2a299a8d4a94d24737df0880 100644 (file)
@@ -87,7 +87,7 @@ class PEAR_Remote extends PEAR
                     return $this->raiseError("PEAR_Remote: authorization required, please log in first", 401);
                 }
             default:
-                return $this->raiseError("PEAR_Remote: unexpected HTTP response: $matches[1] $matches[2]", (int)$matches[1]);
+                return $this->raiseError("PEAR_Remote: unexpected HTTP response", (int)$matches[1], null, null, "$matches[1] $matches[2]");
         }
         while (trim(fgets($fp, 2048)) != ''); // skip rest of headers
         while ($chunk = fread($fp, 10240)) {