]> granicus.if.org Git - php/commitdiff
* partial PEAR MFH
authorStig Bakken <ssb@php.net>
Tue, 9 Apr 2002 18:04:33 +0000 (18:04 +0000)
committerStig Bakken <ssb@php.net>
Tue, 9 Apr 2002 18:04:33 +0000 (18:04 +0000)
35 files changed:
pear/DB.php
pear/Makefile.frag
pear/Makefile.in
pear/PEAR.php
pear/PEAR/Command.php
pear/PEAR/Command/Auth.php
pear/PEAR/Command/Common.php
pear/PEAR/Command/Config.php
pear/PEAR/Command/Install.php
pear/PEAR/Command/Package.php
pear/PEAR/Command/Registry.php
pear/PEAR/Common.php
pear/PEAR/Config.php
pear/PEAR/Frontend/CLI.php
pear/PEAR/Installer.php
pear/PEAR/Packager.php
pear/PEAR/Registry.php
pear/PEAR/Remote.php
pear/package.dtd
pear/pear.m4
pear/scripts/pear-get.in [deleted file]
pear/scripts/pear.in
pear/scripts/pearcmd-common.php [deleted file]
pear/scripts/pearcmd-help.php [deleted file]
pear/scripts/pearcmd-info.php [deleted file]
pear/scripts/pearcmd-install.php [deleted file]
pear/scripts/pearcmd-list.php [deleted file]
pear/scripts/pearcmd-package.php [deleted file]
pear/scripts/pearcmd-remote-list.php [deleted file]
pear/scripts/pearcmd-show-config.php [deleted file]
pear/scripts/pearcmd-uninstall.php [deleted file]
pear/scripts/phpize.in
pear/tests/pear_config.phpt
pear/tests/pear_error.phpt
pear/tests/pear_error3.phpt

index 86125a2b60b253a72223fa52be4abbf3a7d10c01..22cff1f81cbfaeccde3a6b475fb939d855a9b4eb 100644 (file)
@@ -261,6 +261,9 @@ class DB
 
         @$obj =& new $classname;
 
+        if (isset($options['connect_ondemand']) && !extension_loaded("overload")) {
+            unset($options['connect_ondemand']);
+        }
         if (is_array($options)) {
             foreach ($options as $option => $value) {
                 $test = $obj->setOption($option, $value);
@@ -271,11 +274,14 @@ class DB
         } else {
             $obj->setOption('persistent', $options);
         }
-        $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
-
-        if (DB::isError($err)) {
-            $err->addUserInfo($dsn);
-            return $err;
+        if (!$obj->getOption('connect_ondemand')) {
+            $err = $obj->connect($dsninfo, $obj->getOption('persistent'));
+            if (DB::isError($err)) {
+                $err->addUserInfo($dsn);
+                return $err;
+            }
+        } else {
+            $obj->dsn = $dsninfo;
         }
 
         return $obj;
index 1395913117fc186833fff5a857b5d56e0ed2f00e..18248215d783f6ca8e834a8aa9c6e661fe64fc0a 100644 (file)
@@ -1,7 +1,6 @@
-# -*- makefile -*-
 
 pear_install_targets = \
-       install-pear \
+       install-data-local \
        install-headers \
        install-build \
        install-programs
@@ -11,26 +10,63 @@ peardir=$(PEAR_INSTALLDIR)
 PEAR_SUBDIRS = \
        Archive \
        Console \
+       Crypt \
+       Date \
+       DB \
+       File \
+       HTML \
+       HTTP \
+       Image \
+       Mail \
+       Net \
        PEAR \
        PEAR/Command \
        PEAR/Frontend \
+       Schedule \
        XML 
 
-# These are moving to /pear (in cvs):
-#      Crypt \
-#      File \
-#      Date \
-#      DB \
-#      HTML \
-#      HTTP \
-#      Image \
-#      Mail \
-#      Net \
-#      Schedule \
-
 PEAR_FILES = \
        Archive/Tar.php \
        Console/Getopt.php \
+       Crypt/CBC.php \
+       Crypt/HCEMD5.php \
+       Date/Calc.php \
+       Date/Human.php \
+       DB.php \
+       DB/common.php \
+       DB/fbsql.php \
+       DB/ibase.php \
+       DB/ifx.php \
+       DB/msql.php \
+       DB/mssql.php \
+       DB/mysql.php \
+       DB/oci8.php \
+       DB/odbc.php \
+       DB/pgsql.php \
+       DB/storage.php \
+       DB/sybase.php \
+       File/Find.php \
+       File/Passwd.php \
+       File/SearchReplace.php \
+       HTML/Common.php \
+       HTML/Form.php \
+       HTML/IT.php \
+       HTML/ITX.php \
+       HTML/IT_Error.php \
+       HTML/Page.php \
+       HTML/Processor.php \
+       HTML/Select.php \
+       HTML/Table.php \
+       HTTP.php \
+       HTTP/Compress.php \
+       Mail.php \
+       Mail/RFC822.php \
+       Mail/sendmail.php \
+       Mail/smtp.php \
+       Net/Curl.php \
+       Net/Dig.php \
+       Net/SMTP.php \
+       Net/Socket.php \
        PEAR.php \
        PEAR/Autoloader.php \
        PEAR/Command.php \
@@ -41,70 +77,26 @@ PEAR_FILES = \
        PEAR/Command/Package.php \
        PEAR/Command/Registry.php \
        PEAR/Command/Remote.php \
-       PEAR/Frontend/CLI.php \
        PEAR/Common.php \
        PEAR/Config.php \
        PEAR/Dependency.php \
+       PEAR/Frontend/CLI.php \
        PEAR/Installer.php \
        PEAR/Packager.php \
        PEAR/Registry.php \
        PEAR/Remote.php \
+       PEAR/Uploader.php \
+       Schedule/At.php \
        System.php \
        XML/Parser.php 
 
-# These are moving to /pear (in cvs):
-#      Crypt/CBC.php \
-#      Crypt/HCEMD5.php \
-#      DB.php \
-#      DB/common.php \
-#      DB/fbsql.php \
-#      DB/ibase.php \
-#      DB/ifx.php \
-#      DB/msql.php \
-#      DB/mssql.php \
-#      DB/mysql.php \
-#      DB/oci8.php \
-#      DB/odbc.php \
-#      DB/pgsql.php \
-#      DB/storage.php \
-#      DB/sybase.php \
-#      Date/Calc.php \
-#      Date/Human.php \
-#      File/Find.php \
-#      File/Passwd.php \
-#      File/SearchReplace.php \
-#      HTML/Common.php \
-#      HTML/Form.php \
-#      HTML/IT.php \
-#      HTML/ITX.php \
-#      HTML/IT_Error.php \
-#      HTML/Page.php \
-#      HTML/Processor.php \
-#      HTML/Select.php \
-#      HTML/Table.php \
-#      HTTP.php \
-#      HTTP/Compress.php \
-#      Mail.php \
-#      Mail/RFC822.php \
-#      Mail/sendmail.php \
-#      Mail/smtp.php \
-#      Net/Curl.php \
-#      Net/Dig.php \
-#      Net/SMTP.php \
-#      Net/Socket.php \
-#      Schedule/At.php \
-
-PEAR_PACKAGES=\
-       Net_Socket-1.0.tgz
-
-
 install-pear:
        @if $(mkinstalldirs) $(INSTALL_ROOT)$(peardir); then \
                for i in $(PEAR_SUBDIRS); do \
                        $(mkinstalldirs) $(INSTALL_ROOT)$(peardir)/$$i; \
                done; \
                for dir in PEAR/CommandUI; do \
-                       test -d $(INSTALL_ROOT)$(peardir)/$$dir && rm -rf $(INSTALL_ROOT)$(peardir)/$$dir; \
+                       test -d $(INSTALL_ROOT)$(peardir)/$$dir && rmdir $(INSTALL_ROOT)$(peardir)/$$dir; \
                done; \
                for i in $(PEAR_FILES); do \
                        echo "Installing $$i"; \
@@ -113,8 +105,6 @@ install-pear:
                done; \
                rm -f $(INSTALL_ROOT)$(peardir)/PEAR/Command/Login.php; \
                rm -f $(INSTALL_ROOT)$(peardir)/PEAR/CommandUI/CLI.php; \
-               rm -f $(INSTALL_ROOT)$(peardir)/PEAR/CommandResponse.php; \
-               rm -f $(INSTALL_ROOT)$(peardir)/PEAR/Uploader.php; \
        else \
                cat $(srcdir)/install-pear.txt; \
                exit 5; \
@@ -158,10 +148,9 @@ HEADER_DIRS = \
        ext/standard \
        ext/session \
        ext/xml \
-       ext/xml/expat \
+       ext/xml/expat/xmlparse \
+       ext/xml/expat/xmltok \
        main \
-       ext/mbstring \
-       ext/pgsql \
        regex
 
 install-headers:
index 411335bb5b91adb9267ed336a0ab2c229cf0d31c..f5b01e7bf6c0e75e31745ceafc33283eda3f0bcd 100644 (file)
@@ -22,6 +22,8 @@ PEAR_SUBDIRS = \
        Mail \
        Net \
        PEAR \
+       PEAR/Command \
+       PEAR/Frontend \
        Schedule \
        XML 
 
@@ -69,9 +71,18 @@ PEAR_FILES = \
        Net/Socket.php \
        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/Package.php \
+       PEAR/Command/Registry.php \
+       PEAR/Command/Remote.php \
        PEAR/Common.php \
        PEAR/Config.php \
        PEAR/Dependency.php \
+       PEAR/Frontend/CLI.php \
        PEAR/Installer.php \
        PEAR/Packager.php \
        PEAR/Registry.php \
@@ -81,17 +92,6 @@ PEAR_FILES = \
        System.php \
        XML/Parser.php 
 
-PEAR_COMMAND_LIBS = \
-       pearcmd-common.php \
-       pearcmd-help.php \
-       pearcmd-info.php \
-       pearcmd-install.php \
-       pearcmd-list.php \
-       pearcmd-package.php \
-       pearcmd-remote-list.php \
-       pearcmd-show-config.php \
-       pearcmd-uninstall.php
-
 install-data-local:
        @if $(mkinstalldirs) $(INSTALL_ROOT)$(peardir); then \
                for i in $(PEAR_SUBDIRS); do \
@@ -125,7 +125,7 @@ BUILD_FILES = \
        dynlib.m4 \
        acinclude.m4
 
-bin_SCRIPTS = phpize php-config pear pear-get pearize phptar
+bin_SCRIPTS = phpize php-config pear pearize phptar
 
 install-build:
        @echo "Installing build environment"
@@ -140,10 +140,6 @@ install-programs:
        for prog in phpextdist; do \
                echo "Installing program: $$prog"; \
                $(INSTALL) -m 755 $(srcdir)/scripts/$$prog $(INSTALL_ROOT)$(bindir)/$$prog; \
-       done; \
-       for lib in $(PEAR_COMMAND_LIBS); do \
-               echo "Installing program library: $$lib"; \
-               $(INSTALL) -m 644 $(srcdir)/scripts/$$lib $(INSTALL_ROOT)$(bindir)/$$lib; \
        done
 
 HEADER_DIRS = \
@@ -172,9 +168,6 @@ install-headers:
 scripts/pear: scripts/pear.in $(top_builddir)/config.status
        (cd ..;CONFIG_FILES=pear/scripts/pear CONFIG_HEADERS= $(top_builddir)/config.status)
 
-scripts/pear-get: scripts/pear-get.in $(top_builddir)/config.status
-       (cd ..;CONFIG_FILES=pear/scripts/pear-get CONFIG_HEADERS= $(top_builddir)/config.status)
-
 scripts/phpize: scripts/phpize.in $(top_builddir)/config.status
        (cd ..;CONFIG_FILES=pear/scripts/phpize CONFIG_HEADERS= $(top_builddir)/config.status)
 
index db7f21bfa71a7b6525e0dab6e806a991ad75a51a..7c5198b6b18f6eefec9957c19beee1b6565ee5f9 100644 (file)
@@ -39,13 +39,8 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
 
 $GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
 $GLOBALS['_PEAR_default_error_options']  = E_USER_NOTICE;
-$GLOBALS['_PEAR_default_error_callback'] = '';
 $GLOBALS['_PEAR_destructor_object_list'] = array();
 
-//
-// Tests needed: - PEAR inheritance
-//
-
 /**
  * Base class for other PEAR classes.  Provides rudimentary
  * emulation of destructors.
@@ -60,8 +55,12 @@ $GLOBALS['_PEAR_destructor_object_list'] = array();
  * discarded.  If you need to get any debug information from your
  * destructor, use error_log(), syslog() or something similar.
  *
+ * IMPORTANT! To use the emulated destructors you need to create the
+ * objects by reference, ej: $obj =& new PEAR_child;
+ *
  * @since PHP 4.0.2
  * @author Stig Bakken <ssb@fast.no>
+ * @see http://pear.php.net/manual/
  */
 class PEAR
 {
@@ -126,8 +125,8 @@ class PEAR
      * $_PEAR_destructor_object_list for destructor emulation if a
      * destructor object exists.
      *
-     * @param string      (optional) which class to use for error objects,
-     *                    defaults to PEAR_Error.
+     * @param string  $error_class (optional) which class to use for error
+     *                             objects, defaults to PEAR_Error.
      * @access public
      * @return void
      */
@@ -178,7 +177,7 @@ class PEAR
     /**
      * Tell whether a value is a PEAR error.
      *
-     * @param   mixed   the value to test
+     * @param   mixed   $data the value to test
      * @access  public
      * @return  bool    true if parameter is an error
      */
@@ -234,11 +233,9 @@ class PEAR
         if (isset($this)) {
             $setmode     = &$this->_default_error_mode;
             $setoptions  = &$this->_default_error_options;
-            //$setcallback = &$this->_default_error_callback;
         } else {
             $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
             $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
-            //$setcallback = &$GLOBALS['_PEAR_default_error_callback'];
         }
 
         switch ($mode) {
@@ -279,12 +276,15 @@ class PEAR
      * expected errors are in effect until they are popped off the
      * stack with the popExpect() method.
      *
-     * @param mixed    a single error code or an array of error codes
-     *                 to expect
+     * Note that this method can not be called statically
+     *
+     * @param mixed  $code  a single error code or an array of error codes
+     *                      to expect
      *
      * @return int     the new depth of the "expected errors" stack
+     * @access public
      */
-    function expectError($code = "*")
+    function expectError($code = '*')
     {
         if (is_array($code)) {
             array_push($this->_expected_errors, $code);
@@ -371,45 +371,19 @@ class PEAR
                 $mode = PEAR_ERROR_RETURN;
             }
         }
-
+        // No mode given, try global ones
         if ($mode === null) {
+            // Class error handler
             if (isset($this) && isset($this->_default_error_mode)) {
-                $mode = $this->_default_error_mode;
-            } else {
-                $mode = $GLOBALS['_PEAR_default_error_mode'];
-            }
-        }
-
-        if ($mode == PEAR_ERROR_TRIGGER && $options === null) {
-            if (isset($this)) {
-                if (isset($this->_default_error_options)) {
-                    $options = $this->_default_error_options;
-                }
-            } else {
+                $mode    = $this->_default_error_mode;
+                $options = $this->_default_error_options;
+            // Global error handler
+            } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
+                $mode    = $GLOBALS['_PEAR_default_error_mode'];
                 $options = $GLOBALS['_PEAR_default_error_options'];
             }
         }
 
-        if ($mode == PEAR_ERROR_CALLBACK) {
-            if (!is_string($options) &&
-                !(is_array($options) && sizeof($options) == 2 &&
-                  is_object($options[0]) && is_string($options[1])))
-            {
-                if (isset($this) && isset($this->_default_error_options)) {
-                    $options = $this->_default_error_options;
-                } else {
-                    $options = $GLOBALS['_PEAR_default_error_options'];
-                }
-            }
-        } else {
-            if ($options === null) {
-                if (isset($this) && isset($this->_default_error_options)) {
-                    $options = $this->_default_error_options;
-                } else {
-                    $options = $GLOBALS['_PEAR_default_error_options'];
-                }
-            }
-        }
         if ($error_class !== null) {
             $ec = $error_class;
         } elseif (isset($this) && isset($this->_error_class)) {
@@ -432,7 +406,7 @@ class PEAR
     * you can easily override the actual error handler for some code and restore
     * it later with popErrorHandling.
     *
-    * @param $mode mixed (same as setErrorHandling)
+    * @param $mode    mixed (same as setErrorHandling)
     * @param $options mixed (same as setErrorHandling)
     *
     * @return bool Always true
@@ -446,13 +420,9 @@ class PEAR
             if (isset($this)) {
                 $def_mode = &$this->_default_error_mode;
                 $def_options = &$this->_default_error_options;
-                // XXX Used anywhere?
-                //$def_callback = &$this->_default_error_callback;
             } else {
                 $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
                 $def_options = &$GLOBALS['_PEAR_default_error_options'];
-                // XXX Used anywhere?
-                //$def_callback = &$GLOBALS['_PEAR_default_error_callback'];
             }
             $stack = array();
             $stack[] = array($def_mode, $def_options);
@@ -652,7 +622,7 @@ class PEAR_Error
      * @return  string  full error message
      * @access public
      */
-    function getMessage ()
+    function getMessage()
     {
         return ($this->error_message_prefix . $this->message);
     }
@@ -681,7 +651,7 @@ class PEAR_Error
      * @return string error/exception name (type)
      * @access public
      */
-    function getType ()
+    function getType()
     {
         return get_class($this);
     }
@@ -695,7 +665,7 @@ class PEAR_Error
      * @return string user-supplied information
      * @access public
      */
-    function getUserInfo ()
+    function getUserInfo()
     {
         return $this->userinfo;
     }
@@ -709,7 +679,7 @@ class PEAR_Error
      * @return string debug information
      * @access public
      */
-    function getDebugInfo ()
+    function getDebugInfo()
     {
         return $this->getUserInfo();
     }
index 49807d0339bfc0ed0e95236407dd45febbc9c05b..851099e66bffb0c22795fb9ec725e3653a54765f 100644 (file)
@@ -27,6 +27,18 @@ require_once "PEAR.php";
  */
 $GLOBALS['_PEAR_Command_commandlist'] = array();
 
+/**
+ * Which user interface class is being used.
+ * @var string class name
+ */
+$GLOBALS['_PEAR_Command_uiclass'] = 'PEAR_Frontend_CLI';
+
+/**
+* The options accepted by the commands
+* @var string the options
+*/
+$GLOBALS['_PEAR_Command_commandopts'] = '';
+
 /**
  * PEAR command class, a simple factory class for administrative
  * commands.
@@ -82,17 +94,40 @@ class PEAR_Command
      *
      * @access public
      */
-    function factory(&$config, $command)
+    function factory($command, &$config)
     {
         if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
             PEAR_Command::registerCommands();
         }
         if (isset($GLOBALS['_PEAR_Command_commandlist'][$command])) {
             $class = $GLOBALS['_PEAR_Command_commandlist'][$command];
-            $obj =& new $class($config);
+            $obj = &new $class(PEAR_Command::getFrontendObject(), $config);
             return $obj;
         }
-        return PEAR::raiseError("unknown command: $command");
+        return PEAR::raiseError("unknown command `$command'");
+    }
+
+    function &getFrontendObject()
+    {
+        global $_PEAR_Command_uiclass, $_PEAR_Command_uiobject;
+        if (empty($_PEAR_Command_uiobject)) {
+            $_PEAR_Command_uiobject = &new $_PEAR_Command_uiclass;
+        }
+        return $_PEAR_Command_uiobject;
+    }
+
+    function setFrontendClass($uiclass)
+    {
+        $GLOBALS['_PEAR_Command_uiclass'] = $uiclass;
+        $file = str_replace("_", "/", $uiclass) . '.php';
+        include_once $file;
+        return class_exists(strtolower($uiclass));
+    }
+
+    function setFrontendType($uitype)
+    {
+        $uiclass = 'PEAR_Frontend_' . $uitype;
+        return PEAR_Command::setFrontendClass($uiclass);
     }
 
     /**
@@ -119,23 +154,31 @@ class PEAR_Command
         }
         $dp = @opendir($dir);
         if (empty($dp)) {
-            return PEAR::raiseError("PEAR_Command::registerCommands: opendir($dir) failed");
+            return PEAR::raiseError("PEAR_Command::registerCommands: ".
+                                    "opendir($dir) failed");
         }
         if (!$merge) {
             $GLOBALS['_PEAR_Command_commandlist'] = array();
         }
+        $cmdopts = array();
         while ($entry = readdir($dp)) {
-            if ($entry{0} == '.' || substr($entry, -4) != '.php' || $entry == 'Common.php') {
+            if ($entry{0} == '.' || substr($entry, -4) != '.php' ||
+                $entry == 'Common.php')
+            {
                 continue;
             }
             $class = "PEAR_Command_".substr($entry, 0, -4);
             $file = "$dir/$entry";
             include_once $file;
+            // List of commands
             $implements = call_user_func(array($class, "getCommands"));
             foreach ($implements as $command) {
                 $GLOBALS['_PEAR_Command_commandlist'][$command] = $class;
             }
+            // List of options accepted
+            $cmdopts = array_merge($cmdopts, call_user_func(array($class, "getOptions")));
         }
+        $GLOBALS['_PEAR_Command_commandopts'] = implode('', $cmdopts);
         return true;
     }
 
@@ -149,8 +192,19 @@ class PEAR_Command
      */
     function getCommands()
     {
+        if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
+            PEAR_Command::registerCommands();
+        }
         return $GLOBALS['_PEAR_Command_commandlist'];
     }
+
+    function getOptions()
+    {
+        if (empty($GLOBALS['_PEAR_Command_commandlist'])) {
+            PEAR_Command::registerCommands();
+        }
+        return $GLOBALS['_PEAR_Command_commandopts'];
+    }
 }
 
 ?>
\ No newline at end of file
index f59f730b83c243fbe8d739a1ff03e6c2aedf6fcf..81c393e8d6c28aa37e2d9796738df65411d8955f 100644 (file)
@@ -55,16 +55,6 @@ class PEAR_Command_Auth extends PEAR_Command_Common
     }
 
     // }}}
-
-    function getHelp($command)
-    {
-        switch ($command) {
-            case 'login':
-                return array(null, 'Connects to the remote server');
-            case 'logout':
-                return array(null, 'Disconnects from the remote server');
-        }
-    }
     // {{{ run()
 
     /**
@@ -83,27 +73,28 @@ class PEAR_Command_Auth extends PEAR_Command_Common
      */
     function run($command, $options, $params)
     {
+        $cf = $this->config;
         $failmsg = '';
-        $server = $this->config->get('master_server');
+        $server = $cf->get('master_server');
         switch ($command) {
             case 'login': {
-                $remote = new PEAR_Remote($this->config);
-                $username = $this->config->get('username');
+                $remote = new PEAR_Remote($cf);
+                $username = $cf->get('username');
                 if (empty($username)) {
                     $username = @$_ENV['USER'];
                 }
                 $this->ui->displayLine("Logging in to $server.");
                 $username = trim($this->ui->userDialog('Username', 'text', $username));
 
-                $this->config->set('username', $username);
+                $cf->set('username', $username);
                 $password = trim($this->ui->userDialog('Password', 'password'));
-                $this->config->set('password', $password);
+                $cf->set('password', $password);
                 $remote->expectError(401);
                 $ok = $remote->call('logintest');
                 $remote->popExpect();
                 if ($ok === true) {
                     $this->ui->displayLine("Logged in.");
-                    $this->config->store();
+                    $cf->store();
                 } else {
                     $this->ui->displayLine("Login failed!");
                 }
@@ -111,9 +102,9 @@ class PEAR_Command_Auth extends PEAR_Command_Common
             }
             case 'logout': {
                 $this->ui->displayLine("Logging out from $server.");
-                $this->config->remove('username');
-                $this->config->remove('password');
-                $this->config->store();
+                $cf->remove('username');
+                $cf->remove('password');
+                $cf->store();
                 break;
             }
             default: {
index e54c1694f13cc21f01720b8ca9e38a1b0da3bb17..7ea724a999e202550c1f3845979fb6762085aac4 100644 (file)
@@ -19,7 +19,7 @@
 // $Id$
 
 require_once "PEAR.php";
-require_once "PEAR/CommandResponse.php";
+//require_once "PEAR/CommandResponse.php";
 
 class PEAR_Command_Common extends PEAR
 {
@@ -31,15 +31,27 @@ class PEAR_Command_Common extends PEAR
      */
     var $config;
 
+    /**
+     * User Interface object, for all interaction with the user.
+     * @var object
+     */
+    var $ui;
+
     /**
      * PEAR_Command_Common constructor.
      *
      * @access public
      */
-    function PEAR_Command_Common()
+    function PEAR_Command_Common(&$ui, &$config)
     {
         parent::PEAR();
-        $this->config = PEAR_Config::singleton();
+        $this->config = &$config;
+        $this->ui = &$ui;
+    }
+
+    function getOptions()
+    {
+        return array();
     }
 
     /**
@@ -56,13 +68,13 @@ class PEAR_Command_Common extends PEAR
      *
      * @see PEAR_CommandResponse
      */
+/*
     function &makeResponse($status, $message, $encoding = null)
     {
-        $obj =new PEAR_CommandResponse($status, $message, $encoding);
+        $obj = &new PEAR_CommandResponse($status, $message, $encoding);
         return $obj;
     }
-
-    
+*/
 }
 
 ?>
\ No newline at end of file
index 009c2d243ebf5210edb2d77aed20b0e4e011c03f..1fdcf32747dc009c32b98c6d5b37aef4bb0e625a 100644 (file)
@@ -14,8 +14,6 @@
 // | license@php.net so we can mail you a copy immediately.               |
 // +----------------------------------------------------------------------+
 // | Author: Stig Bakken <ssb@fast.no>                                    |
-// |         Tomas V.V.Cox <cox@idecnet.com>                              |
-// |                                                                      |
 // +----------------------------------------------------------------------+
 //
 // $Id$
@@ -59,66 +57,44 @@ class PEAR_Command_Config extends PEAR_Command_Common
     }
 
     // }}}
-
-    function getHelp($command)
-    {
-        switch ($command) {
-            case 'config-show':
-                $ret = array('[<layer>]', 'Displays the configuration');
-                break;
-            case 'config-get':
-                $ret = array('<parameter> [<layer>]',
-                             'Displays the value of the given parameter');
-                break;
-            case 'config-set':
-                $ret = array('<parameter> <value> [<layer>]',
-                             'Sets the value of a parameter in the config');
-                break;
-        }
-        $ret[1] .= "\n".
-                   "  <layer>    Where to store/get the configuration. The installer\n".
-                   "             supports 'user' (per user conf) and 'system' (global conf)";
-        return $ret;
-    }
     // {{{ run()
 
     function run($command, $options, $params)
     {
-        $cf = &$this->config;
+        $cf =$this->config;
         $failmsg = '';
+        $params[0] = (isset($params[0])) ? $params[0] : null;
+        $params[1] = (isset($params[1])) ? $params[1] : null;
         switch ($command) {
             case 'config-show': {
-                // $params[0] -> the layer
-                if ($error = $this->_checkLayer(@$params[0])) {
-                    $failmsg .= $error;
-                    break;
-                }
                 $keys = $cf->getKeys();
                 sort($keys);
                 $this->ui->startTable(array('caption' => 'Configuration:'));
-                foreach ($keys as $key) {
-                    $type = $cf->getType($key);
-                    $value = $cf->get($key, @$params[0]);
-                    if ($type == 'password' && $value) {
-                        $value = '********';
+                if (isset($params[0]) && $cf->isDefined($params[0])) {
+                    foreach ($keys as $key) {
+                        $type = $cf->getType($key);
+                        $value = $cf->get($key, $params[0]);
+                        if ($type == 'password' && $value) {
+                            $value = '********';
+                        }
+                        $this->ui->tableRow(array($key, $value));
                     }
-                    if (empty($value)) {
-                        $value = '<not set>';
+                } else {
+                    foreach ($keys as $key) {
+                        $type = $cf->getType($key);
+                        $value = $cf->get($key, $params[0]);
+                        if ($type == 'password' && $value) {
+                            $value = '********';
+                        }
+                        $this->ui->tableRow(array($key, $value));
                     }
-                    $this->ui->tableRow(array($key, $value));
                 }
                 $this->ui->endTable();
                 break;
             }
             case 'config-get': {
-                // $params[0] -> the parameter
-                // $params[1] -> the layer
-                if ($error = $this->_checkLayer(@$params[1])) {
-                    $failmsg .= $error;
-                    break;
-                }
                 if (sizeof($params) < 1 || sizeof($params) > 2) {
-                    $failmsg .= "config-get expects 1 or 2 parameters. Try \"help config-get\" for help";
+                    $failmsg .= "config-get expects 1 or 2 parameters";
                 } elseif (sizeof($params) == 1) {
                     $this->ui->displayLine("$params[0] = " . $cf->get($params[0]));
                 } else {
@@ -128,22 +104,15 @@ class PEAR_Command_Config extends PEAR_Command_Common
                 break;
             }
             case 'config-set': {
-                // $param[0] -> a parameter to set
-                // $param[1] -> the value for the parameter
-                // $param[2] -> the layer
                 if (sizeof($params) < 2 || sizeof($params) > 3) {
-                    $failmsg .= "config-set expects 2 or 3 parameters. Try \"help config-set\" for help";
-                    break;
-                }
-                if ($error = $this->_checkLayer(@$params[2])) {
-                    $failmsg .= $error;
+                    $failmsg .= "config-set expects 2 or 3 parameters";
                     break;
-                }
-                if (!call_user_func_array(array(&$cf, 'set'), $params))
-                {
-                    $failmsg = "config-set (" . implode(", ", $params) . ") failed";
                 } else {
-                    $cf->store();
+                    if (!call_user_func_array(array($cf, 'set'), $params))
+                    {
+                        $failmsg = "config-set (" .
+                             implode(", ", $params) . ") failed";
+                    }
                 }
                 break;
             }
@@ -158,24 +127,6 @@ class PEAR_Command_Config extends PEAR_Command_Common
     }
 
     // }}}
-
-    /**
-    * Checks if a layer is defined or not
-    *
-    * @param string $layer The layer to search for
-    * @return mixed False on no error or the error message
-    */
-    function _checkLayer($layer = null)
-    {
-        if (!empty($layer)) {
-            $layers = $this->config->getLayers();
-            if (!in_array($layer, $layers)) {
-                return " only the layers: \"" . implode('" or "', $layers) . "\" are supported";
-            }
-        }
-        return false;
-    }
-
 }
 
 ?>
\ No newline at end of file
index 0d99f85b1afbf64cabbdc32cf20f5d642026a1c1..7204c309bfd76a714c8d956119420fef813eb739 100644 (file)
@@ -28,26 +28,25 @@ require_once "PEAR/Installer.php";
  */
 class PEAR_Command_Install extends PEAR_Command_Common
 {
-    /** Stack of executing commands, to make run() re-entrant
-     * @var array
-     */
-    var $command_stack; // XXX UNUSED to make run() re-entrant
+    // {{{ properties
+    // }}}
 
-    /** Currently executing command.
-     * @var string
-     */
-    var $command; // XXX UNUSED
+    // {{{ constructor
 
     /**
      * PEAR_Command_Install constructor.
      *
      * @access public
      */
-    function PEAR_Command_Install()
+    function PEAR_Command_Install(&$ui, &$config)
     {
-        parent::PEAR_Command_Common();
+        parent::PEAR_Command_Common($ui, $config);
     }
 
+    // }}}
+
+    // {{{ getCommands()
+
     /**
      * Return a list of all the commands defined by this class.
      * @return array list of commands
@@ -58,41 +57,57 @@ class PEAR_Command_Install extends PEAR_Command_Common
         return array('install', 'uninstall', 'upgrade');
     }
 
+    // }}}
+    // {{{ run()
+
     function run($command, $options, $params)
     {
-        $installer =& new PEAR_Installer($options['php_dir'],
-                                         $options['ext_dir'],
-                                         $options['doc_dir']);
-        $installer->debug = @$options['verbose'];
-        $status = PEAR_COMMAND_SUCCESS;
-        ob_start();
+        $installer = &new PEAR_Installer($this->config->get('php_dir'),
+                                         $this->config->get('ext_dir'),
+                                         $this->config->get('doc_dir'));
+        $installer->debug = $this->config->get('verbose');
+
+        $failmsg = '';
+        $opts = array();
         switch ($command) {
-            case 'install':
-            case 'upgrade': {
-                if ($command == 'upgrade') {
-                    $options['upgrade'] = true;
+            case 'upgrade':
+                $opts['upgrade'] = true;
+                // fall through
+            case 'install': {
+                if (isset($options['f'])) {
+                    $opts['force'] = true;
                 }
-                if ($installer->install($params[0], $options, $this->config)) {
-                    print "install ok\n";
+                // XXX The ['nodeps'] option is still missing
+                if ($installer->install(@$params[0], $opts, $this->config)) {
+                    $this->ui->displayLine("install ok");
                 } else {
-                    print "install failed\n";
-                    $status = PEAR_COMMAND_FAILURE;
+                    $failmsg = "install failed";
                 }
                 break;
             }
             case 'uninstall': {
-                if ($installer->uninstall($params[0], $uninstall_options)) {
-                    print "uninstall ok\n";
+                if ($installer->uninstall($params[0], $options)) {
+                    $this->ui->displayLine("uninstall ok");
                 } else {
-                    print "uninstall failed\n";
-                    $status = PEAR_COMMAND_FAILURE;
+                    $failmsg = "uninstall failed";
                 }
                 break;
-            }                
+            }
+            default: {
+                return false;
+            }
+        }
+        if ($failmsg) {
+            return $this->raiseError($failmsg);
         }
-        $output = ob_get_contents();
-        ob_end_clean();
-        return $this->makeResponse($status, $output);
+        return true;
+    }
+
+    // }}}
+
+    function getOptions()
+    {
+        return array('f');
     }
 }
 
index eb2d9771b2f0d29ac429d5b1f3efd103e811f017..a95f45a1fd6fdceab8b4d7e5d54546c22749008a 100644 (file)
@@ -1,22 +1,4 @@
 <?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/Packager.php';
@@ -38,26 +20,6 @@ class PEAR_Command_Package extends PEAR_Command_Common
 
     // }}}
 
-    // {{{ _displayValidationResults()
-
-    function _displayValidationResults($err, $warn, $strict = false)
-    {
-        foreach ($err as $e) {
-            $this->ui->displayLine("Error: $e");
-        }
-        foreach ($warn as $w) {
-            $this->ui->displayLine("Warning: $w");
-        }
-        $this->ui->displayLine(sprintf('Validation: %d error(s), %d warning(s)',
-                                       sizeof($err), sizeof($warn)));
-        if ($strict && sizeof($err) > 0) {
-            $this->ui->displayLine("Fix these errors and try again.");
-            return false;
-        }
-        return true;
-    }
-
-    // }}}
     // {{{ getCommands()
 
     /**
@@ -68,43 +30,8 @@ class PEAR_Command_Package extends PEAR_Command_Common
     function getCommands()
     {
         return array('package',
-                     'package-info',
                      'package-list',
-                     'package-validate',
-                     'cvstag');
-    }
-
-    // }}}
-    // {{{ getOptions()
-
-    function getOptions()
-    {
-        return array('Z', 'n' /*, 'f', 'd', 'q', 'Q'*/);
-    }
-
-    // }}}
-    // {{{ getHelp()
-
-    function getHelp($command)
-    {
-        switch ($command) {
-            case 'package':
-                return array('[<package.xml>]',
-                             'Creates a PEAR package from its description file (usually '.
-                             'named as package.xml)');
-            case 'package-list':
-                return array('<pear package>',
-                             'List the contents of a PEAR package');
-            case 'packge-info':
-                return array('<pear package>',
-                             'Shows information about a PEAR package');
-            case 'package-validate':
-                return array('<package.(tgz|tar|xml)>',
-                             'Verifies a package or description file');
-            case 'cvstag':
-                return array('<package.xml>',
-                             'Runs "cvs tag" on files contained in a release');
-        }
+                     'package-info');
     }
 
     // }}}
@@ -131,19 +58,13 @@ class PEAR_Command_Package extends PEAR_Command_Common
             // {{{ package
 
             case 'package': {
-                $pkginfofile = isset($params[0]) ? $params[0] : 'package.xml';
+                $pkginfofile = isset($params[0]) ? $params[0] : null;
                 ob_start();
                 $packager =& new PEAR_Packager($this->config->get('php_dir'),
                                                $this->config->get('ext_dir'),
                                                $this->config->get('doc_dir'));
                 $packager->debug = $this->config->get('verbose');
-                $err = $warn = array();
-                $packager->validatePackageInfo($pkginfofile, $err, $warn);
-                if (!$this->_displayValidationResults($err, $warn, true)) {
-                    break;
-                }
-                $compress = empty($options['Z']) ? true : false;
-                $result = $packager->Package($pkginfofile, $compress);
+                $result = $packager->Package($pkginfofile);
                 $output = ob_get_contents();
                 ob_end_clean();
                 $lines = explode("\n", $output);
@@ -151,7 +72,9 @@ class PEAR_Command_Package extends PEAR_Command_Common
                     $this->ui->displayLine($line);
                 }
                 if (PEAR::isError($result)) {
-                    $this->ui->displayLine("Package failed: ".$result->getMessage());
+                    $this->ui->displayLine("Package failed!");
+                } else {
+                    $this->ui->displayLine("Package ok.");
                 }
                 break;
             }
@@ -160,14 +83,7 @@ class PEAR_Command_Package extends PEAR_Command_Common
             // {{{ package-list
 
             case 'package-list': {
-                // $params[0] -> the PEAR package to list its contents
-                if (sizeof($params) != 1) {
-                    $failmsg = "Command package-list requires a valid PEAR package filename ".
-                               " as the first argument. Try the command \"help package-list\"";
-                    break;
-                }
                 $obj = new PEAR_Common();
-
                 if (PEAR::isError($info = $obj->infoFromTgzFile($params[0]))) {
                     return $info;
                 }
@@ -180,9 +96,9 @@ class PEAR_Command_Package extends PEAR_Command_Common
                 foreach ($list as $file => $att) {
                     if (isset($att['baseinstalldir'])) {
                         $dest = $att['baseinstalldir'] . DIRECTORY_SEPARATOR .
-                                $file;
+                                basename($file);
                     } else {
-                        $dest = $file;
+                        $dest = basename($file);
                     }
                     switch ($att['role']) {
                         case 'test':
@@ -288,89 +204,6 @@ class PEAR_Command_Package extends PEAR_Command_Common
                 break;
             }
 
-            // }}}
-            // {{{ package-validate
-
-            case 'package-validate': {
-                if (sizeof($params) < 1) {
-                    $params[0] = "package.xml";
-                }
-                $obj = new PEAR_Common;
-                $info = null;
-                if (file_exists($params[0])) {
-                    $fp = fopen($params[0], "r");
-                    $test = fread($fp, 5);
-                    fclose($fp);
-                    if ($test == "<?xml") {
-                        $info = $obj->infoFromDescriptionFile($params[0]);
-                    }
-                }
-                if (empty($info)) {
-                    $info = $obj->infoFromTgzFile($params[0]);
-                }
-                if (PEAR::isError($info)) {
-                    return $this->raiseError($info);
-                }
-                $obj->validatePackageInfo($info, $err, $warn);
-                $this->_displayValidationResults($err, $warn);
-                break;
-            }
-
-            // }}}
-            // {{{ cvstag
-
-            case 'cvstag': {
-                if (sizeof($params) < 1) {
-                    $help = $this->getHelp($command);
-                    return $this->raiseError("$command: missing parameter: $help[0]");
-                }
-                $obj = new PEAR_Common;
-                $info = $obj->infoFromDescriptionFile($params[0]);
-                if (PEAR::isError($info)) {
-                    return $this->raiseError($info);
-                }
-                $err = $warn = array();
-                $obj->validatePackageInfo($info, $err, $warn);
-                if (!$this->_displayValidationResults($err, $warn, true)) {
-                    break;
-                }
-                $version = $info['version'];
-                $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $version);
-                $cvstag = "RELEASE_$cvsversion";
-                $files = array_keys($info['filelist']);
-                $command = "cvs";
-                /* until the getopt bug is fixed, these won't work:
-                if (isset($options['q'])) {
-                    $command .= ' -q';
-                }
-                if (isset($options['Q'])) {
-                    $command .= ' -Q';
-                }
-                */
-                $command .= ' tag';
-                if (isset($options['f'])) {
-                    $command .= ' -f';
-                }
-                /* neither will this one:
-                if (isset($options['d'])) {
-                    $command .= ' -d';
-                }
-                */
-                $command .= ' ' . $cvstag . ' ' . escapeshellarg($params[0]);
-                foreach ($files as $file) {
-                    $command .= ' ' . escapeshellarg($file);
-                }
-                $this->ui->displayLine("+ $command");
-                if (empty($options['n'])) {
-                    $fp = popen($command, "r");
-                    while ($line = fgets($fp, 1024)) {
-                        $this->ui->displayLine(rtrim($line));
-                    }
-                    pclose($fp);
-                }
-                break;
-            }
-
             // }}}
             default: {
                 return false;
@@ -384,6 +217,7 @@ class PEAR_Command_Package extends PEAR_Command_Common
 
     // }}}
 
+
 }
 
 ?>
\ No newline at end of file
index 92777094ca1a17e2e21ef514eb31b192dfd0da63..25e0c576b410c9cef11abe23b970d7064d518bc8 100644 (file)
@@ -29,15 +29,7 @@ class PEAR_Command_Registry extends PEAR_Command_Common
      */
     function getCommands()
     {
-        return array('list-installed', 'shell-test');
-    }
-
-    function getHelp($command)
-    {
-        switch ($command) {
-            case 'list-installed':
-                return array(null, 'List the installed PEAR packages in the system');
-        }
+        return array('list-installed');
     }
 
     // }}}
@@ -62,8 +54,6 @@ class PEAR_Command_Registry extends PEAR_Command_Common
         $failmsg = '';
         $cf = &PEAR_Config::singleton();
         switch ($command) {
-            // {{{ list-installed
-
             case 'list-installed': {
                 $reg = new PEAR_Registry($cf->get('php_dir'));
                 $installed = $reg->packageInfo();
@@ -73,47 +63,16 @@ class PEAR_Command_Registry extends PEAR_Command_Common
                           'border' => true));
                 foreach ($installed as $package) {
                     if ($i++ % 20 == 0) {
-                        $this->ui->tableRow(
-                            array('Package', 'Version', 'State'),
-                            array('bold' => true));
+                        $this->ui->tableRow(array('Package', 'Version', 'State'),
+                                        array('bold' => true));
                     }
                     $this->ui->tableRow(array($package['package'],
                                               $package['version'],
-                                              @$package['release_state']));
+                                              $package['release_state']));
                 }
                 $this->ui->endTable();
                 break;
             }
-
-            // }}}
-            case 'shell-test': {
-                // silence error messages for the rest of the execution
-                PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
-                $reg = &new PEAR_Registry($this->config->get('php_dir'));
-                // "pear shell-test Foo"
-                if (sizeof($params) == 1) {
-                    if (!$reg->packageExists($params[0])) {
-                        exit(1);
-                    }
-                // "pear shell-test Foo 1.0"
-                } elseif (sizeof($params) == 2) {
-                    $v = $reg->packageInfo($params[0], 'version');
-                    if (!$v || !version_compare($v, $params[1], "ge")) {
-                        exit(1);
-                    }
-                // "pear shell-test Foo ge 1.0"
-                } elseif (sizeof($params) == 3) {
-                    $v = $reg->packageInfo($params[0], 'version');
-                    if (!$v || !version_compare($v, $params[2], $params[1])) {
-                        exit(1);
-                    }
-                } else {
-                    PEAR::popErrorHandling();
-                    PEAR::raiseError("$command: expects 1 to 3 parameters");
-                    exit(1);
-                }
-                break;
-            }
             default: {
                 return false;
             }
index 929a97917ecc73ac84cf95e944e3b6426426084e..efbaaac2a77b0921044db8dd405000eaa0110b7c 100644 (file)
@@ -24,11 +24,22 @@ require_once 'Archive/Tar.php';
 require_once 'System.php';
 
 /**
+ * List of temporary files and directories registered by
+ * PEAR_Common::addTempFile().
+ * @var array
+ */
+$GLOBALS['_PEAR_Common_tempfiles'] = array();
+
+/*
  * TODO:
  *   - check in inforFromDescFile that the minimal data needed is present
  *     (pack name, version, files, others?)
  *   - inherance of dir attribs to files may fail under certain circumstances
  */
+
+/**
+ * Class providing common functionality for PEAR adminsitration classes.
+ */
 class PEAR_Common extends PEAR
 {
     // {{{ properties
@@ -42,9 +53,6 @@ class PEAR_Common extends PEAR
     /** array of attributes of the currently parsed XML element */
     var $current_attributes = array();
 
-    /** list of temporary files created by this object */
-    var $_tempfiles = array();
-
     /** assoc with information about a package */
     var $pkginfo = array();
 
@@ -58,30 +66,36 @@ class PEAR_Common extends PEAR
      * Permitted release states
      * @var array
      */
-    var $releases_states  = array('alpha','beta','stable','snapshot');
+    var $releases_states  = array('alpha','beta','stable','snapshot','devel');
 
     // }}}
 
     // {{{ constructor
 
+    /**
+     * PEAR_Common constructor
+     *
+     * @access public
+     */
     function PEAR_Common()
     {
-        $GLOBALS['_PEAR_Common_tempfiles'] = array();
-        $this->_tempfiles =& $GLOBALS['_PEAR_Common_tempfiles'];
         $this->PEAR();
     }
 
     // }}}
     // {{{ destructor
 
+    /**
+     * PEAR_Common destructor
+     *
+     * @access private
+     */
     function _PEAR_Common()
     {
         // doesn't work due to bug #14744
         //$tempfiles = $this->_tempfiles;
         $tempfiles =& $GLOBALS['_PEAR_Common_tempfiles'];
-        while (is_array($tempfiles) &&
-               $file = array_shift($tempfiles))
-        {
+        while ($file = array_shift($tempfiles)) {
             if (@is_dir($file)) {
                 System::rm("-rf $file");
             } elseif (file_exists($file)) {
@@ -93,14 +107,35 @@ class PEAR_Common extends PEAR
     // }}}
     // {{{ addTempFile()
 
+    /**
+     * Register a temporary file or directory.  When the destructor is
+     * executed, all registered temporary files and directories are
+     * removed.
+     *
+     * @param string   name of file or directory
+     *
+     * @return void
+     *
+     * @access public
+     */
     function addTempFile($file)
     {
-        $this->_tempfiles[] = $file;
+        $GLOBALS['_PEAR_Common_tempfiles'][] = $file;
     }
 
     // }}}
     // {{{ mkDirHier()
 
+    /**
+     * Wrapper to System::mkDir(), creates a directory as well as
+     * any necessary parent directories.
+     *
+     * @param string  directory name
+     *
+     * @return bool TRUE on success, or a PEAR error
+     *
+     * @access public
+     */
     function mkDirHier($dir)
     {
         $this->log(2, "+ create dir $dir");
@@ -110,6 +145,17 @@ class PEAR_Common extends PEAR
     // }}}
     // {{{ log()
 
+    /**
+     * Logging method.
+     *
+     * @param int    log level (0 is quiet, higher is noisier)
+     *
+     * @param string message to write to the log
+     *
+     * @return void
+     *
+     * @access public
+     */
     function log($level, $msg)
     {
         if ($this->debug >= $level) {
@@ -120,9 +166,25 @@ class PEAR_Common extends PEAR
     // }}}
     // {{{ mkTempDir()
 
-    function mkTempDir()
+    /**
+     * Create and register a temporary directory.
+     * 
+     * @param string (optional) Directory to use as tmpdir.  Will use
+     * system defaults (for example /tmp or c:\windows\temp) if not
+     * specified
+     *
+     * @return string name of created directory
+     * 
+     * @access public
+     */
+    function mkTempDir($tmpdir = '')
     {
-        if (!$tmpdir = System::mktemp('-d pear')) {
+        if ($tmpdir) {
+            $topt = "-t $tmpdir ";
+        } else {
+            $topt = '';
+        }
+        if (!$tmpdir = System::mktemp($topt . '-d pear')) {
             return false;
         }
         $this->addTempFile($tmpdir);
@@ -132,7 +194,77 @@ class PEAR_Common extends PEAR
     // }}}
     // {{{ _element_start()
 
+    /**
+     * XML parser callback for starting elements.  Used while package
+     * format version is not yet known.
+     *
+     * @param resource  XML parser resource
+     * @param string    name of starting element
+     * @param array     element attributes, name => value
+     *
+     * @return void
+     *
+     * @access private
+     */
     function _element_start($xp, $name, $attribs)
+    {
+        array_push($this->element_stack, $name);
+        $this->current_element = $name;
+        $spos = sizeof($this->element_stack) - 2;
+        $this->prev_element = ($spos >= 0) ? $this->element_stack[$spos] : '';
+        $this->current_attributes = $attribs;
+        switch ($name) {
+            case 'package': {
+                if (isset($attribs['version'])) {
+                    $vs = preg_replace('/[^0-9a-z]/', '_', $attribs['version']);
+                } else {
+                    $vs = '1_0';
+                }
+                $elem_start = '_element_start_'. $vs;
+                $elem_end = '_element_end_'. $vs;
+                $cdata = '_pkginfo_cdata_'. $vs;
+                xml_set_element_handler($xp, $elem_start, $elem_end);
+                xml_set_character_data_handler($xp, $cdata);
+                break;
+            }
+        }
+    }
+
+    // }}}
+    // {{{ _element_end()
+
+    /**
+     * XML parser callback for ending elements.  Used while package
+     * format version is not yet known.
+     *
+     * @param resource  XML parser resource
+     * @param string    name of ending element
+     *
+     * @return void
+     *
+     * @access private
+     */
+    function _element_end($xp, $name)
+    {
+    }
+    
+    // }}}
+
+    // Support for package DTD v1.0:
+    // {{{ _element_start_1_0()
+
+    /**
+     * XML parser callback for ending elements.  Used for version 1.0
+     * packages.
+     *
+     * @param resource  XML parser resource
+     * @param string    name of ending element
+     *
+     * @return void
+     *
+     * @access private
+     */
+    function _element_start_1_0($xp, $name, $attribs)
     {
         array_push($this->element_stack, $name);
         $this->current_element = $name;
@@ -142,11 +274,8 @@ class PEAR_Common extends PEAR
         $this->cdata = '';
         switch ($name) {
             case 'dir':
-                if (isset($this->dir_names)) {
+                if ($attribs['name'] != '/') {
                     $this->dir_names[] = $attribs['name'];
-                } else {
-                    // Don't add the root dir
-                    $this->dir_names = array();
                 }
                 if (isset($attribs['baseinstalldir'])) {
                     $this->dir_install = $attribs['baseinstalldir'];
@@ -157,7 +286,7 @@ class PEAR_Common extends PEAR
                 break;
             case 'libfile':
                 $this->lib_atts = $attribs;
-                $this->lib_atts['role'] = 'extension';
+                $this->lib_atts['role'] = 'extsrc';
                 break;
             case 'maintainers':
                 $this->pkginfo['maintainers'] = array();
@@ -184,20 +313,35 @@ class PEAR_Common extends PEAR
                 }
                 break;
             case 'deps':
-                $this->pkginfo['release_deps'] = array();
+                if (!$this->in_changelog) {
+                    $this->pkginfo['release_deps'] = array();
+                }
                 break;
             case 'dep':
                 // dependencies array index
-                $this->d_i = (isset($this->d_i)) ? $this->d_i + 1 : 0;
-                $this->pkginfo['release_deps'][$this->d_i] = $attribs;
+                if (!$this->in_changelog) {
+                    $this->d_i = (isset($this->d_i)) ? $this->d_i + 1 : 0;
+                    $this->pkginfo['release_deps'][$this->d_i] = $attribs;
+                }
                 break;
         }
     }
 
     // }}}
-    // {{{ _element_end()
+    // {{{ _element_end_1_0()
 
-    function _element_end($xp, $name)
+    /**
+     * XML parser callback for ending elements.  Used for version 1.0
+     * packages.
+     *
+     * @param resource  XML parser resource
+     * @param string    name of ending element
+     *
+     * @return void
+     *
+     * @access private
+     */
+    function _element_end_1_0($xp, $name)
     {
         $data = trim($this->cdata);
         switch ($name) {
@@ -278,7 +422,7 @@ class PEAR_Common extends PEAR
             case 'file':
                 $this->current_file = $data;
                 $path = '';
-                if (!empty($this->dir_names)) {
+                if (count($this->dir_names)) {
                     foreach ($this->dir_names as $dir) {
                         $path .= $dir . DIRECTORY_SEPARATOR;
                     }
@@ -297,7 +441,6 @@ class PEAR_Common extends PEAR
                 }
                 break;
             case 'libfile':
-                $this->lib_name = $data;
                 $path = '';
                 if (!empty($this->dir_names)) {
                     foreach ($this->dir_names as $dir) {
@@ -313,12 +456,19 @@ class PEAR_Common extends PEAR
                     $this->filelist[$path]['baseinstalldir'] = $this->dir_install;
                 }
                 if (isset($this->lib_sources)) {
-                    $this->filelist[$path]['sources'] = $this->lib_sources;
+                    $this->filelist[$path]['sources'] = implode(' ', $this->lib_sources);
                 }
                 unset($this->lib_atts);
                 unset($this->lib_sources);
+                unset($this->lib_name);
+                break;
+            case 'libname':
+                $this->lib_name = $data;
                 break;
             case 'maintainer':
+                if (empty($this->pkginfo['maintainers'][$this->m_i]['role'])) {
+                    $this->pkginfo['maintainers'][$this->m_i]['role'] = 'lead';
+                }
                 $this->m_i++;
                 break;
             case 'release':
@@ -339,22 +489,109 @@ class PEAR_Common extends PEAR
     }
 
     // }}}
-    // {{{ _pkginfo_cdata()
+    // {{{ _pkginfo_cdata_1_0()
 
-    function _pkginfo_cdata($xp, $data)
+    /**
+     * XML parser callback for character data.  Used for version 1.0
+     * packages.
+     *
+     * @param resource  XML parser resource
+     * @param string    character data
+     *
+     * @return void
+     *
+     * @access private
+     */
+    function _pkginfo_cdata_1_0($xp, $data)
     {
         $this->cdata .= $data;
     }
 
+    // }}}
+
+    // {{{ infoFromTgzFile()
+
+    /**
+     * Returns information about a package file.  Expects the name of
+     * a gzipped tar file as input.
+     *
+     * @param string   name of .tgz file
+     *
+     * @return array   array with package information
+     *
+     * @access public
+     *
+     */
+    function infoFromTgzFile($file)
+    {
+        if (!@is_file($file)) {
+            return $this->raiseError('tgz :: could not open file');
+        }
+        $tar = new Archive_Tar($file, true);
+        $content = $tar->listContent();
+        if (!is_array($content)) {
+            return $this->raiseError('tgz :: could not get contents of package');
+        }
+        $xml = null;
+        foreach ($content as $file) {
+            $name = $file['filename'];
+            if ($name == 'package.xml') {
+                $xml = $name;
+            } elseif (ereg('^.*/package.xml$', $name, $match)) {
+                $xml = $match[0];
+            }
+        }
+        $tmpdir = System::mkTemp('-d pear');
+        $this->addTempFile($tmpdir);
+        if (!$xml || !$tar->extractList($xml, $tmpdir)) {
+            return $this->raiseError('tgz :: could not extract the package.xml file');
+        }
+        return $this->infoFromDescriptionFile("$tmpdir/$xml");
+    }
+
     // }}}
     // {{{ infoFromDescriptionFile()
 
+    /**
+     * Returns information about a package file.  Expects the name of
+     * a package xml file as input.
+     *
+     * @param string   name of package xml file
+     *
+     * @return array   array with package information
+     *
+     * @access public
+     *
+     */
     function infoFromDescriptionFile($descfile)
     {
         if (!@is_file($descfile) || !is_readable($descfile) ||
              (!$fp = @fopen($descfile, 'r'))) {
             return $this->raiseError("Unable to open $descfile");
         }
+
+        // read the whole thing so we only get one cdata callback
+        // for each block of cdata
+        $data = fread($fp, filesize($descfile));
+        return $this->infoFromString($data);
+    }
+
+    // }}}
+    // {{{ infoFromString()
+
+    /**
+     * Returns information about a package file.  Expects the contents
+     * of a package xml file as input.
+     *
+     * @param string   name of package xml file
+     *
+     * @return array   array with package information
+     *
+     * @access public
+     *
+     */
+    function infoFromString($data)
+    {
         $xp = @xml_parser_create();
         if (!$xp) {
             return $this->raiseError('Unable to create XML parser');
@@ -370,17 +607,16 @@ class PEAR_Common extends PEAR
         $this->destdir = '';
         $this->pkginfo['filelist'] = array();
         $this->filelist =& $this->pkginfo['filelist'];
+        $this->dir_names = array();
         $this->in_changelog = false;
 
-        // read the whole thing so we only get one cdata callback
-        // for each block of cdata
-        $data = fread($fp, filesize($descfile));
         if (!xml_parse($xp, $data, 1)) {
+            $code = xml_get_error_code($xp);
             $msg = sprintf("XML error: %s at line %d",
-                           xml_error_string(xml_get_error_code($xp)),
+                           xml_error_string($code),
                            xml_get_current_line_number($xp));
             xml_parser_free($xp);
-            return $this->raiseError($msg);
+            return $this->raiseError($msg, $code);
         }
 
         xml_parser_free($xp);
@@ -393,36 +629,128 @@ class PEAR_Common extends PEAR
         return $this->pkginfo;
     }
     // }}}
-    // {{{ infoFromTgzFile()
+    // {{{ xmlFromInfo()
 
     /**
-    * Returns info from a tgz pear package
-    */
-    function infoFromTgzFile($file)
+     * Return an XML document based on the package info (as returned
+     * by the PEAR_Common::infoFrom* methods).
+     *
+     * @param array package info
+     *
+     * @return string XML data
+     *
+     * @access public
+     */
+    function xmlFromInfo($pkginfo)
     {
-        if (!@is_file($file)) {
-            return $this->raiseError('tgz :: could not open file');
+        static $maint_map = array(
+            "handle" => "user",
+            "name" => "name",
+            "email" => "email",
+            "role" => "role",
+            );
+        $ret = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
+        //$ret .= "<!DOCTYPE package SYSTEM \"http://pear.php.net/package10.dtd\">\n";
+        $ret .= "<package version=\"1.0\">
+  <name>$pkginfo[package]</name>
+  <summary>".htmlspecialchars($pkginfo['summary'])."</summary>
+  <description>".htmlspecialchars($pkginfo['description'])."</description>
+  <maintainers>
+";
+        foreach ($pkginfo['maintainers'] as $maint) {
+            $ret .= "    <maintainer>\n";
+            foreach ($maint_map as $idx => $elm) {
+                $ret .= "      <$elm>";
+                $ret .= htmlspecialchars($maint[$idx]);
+                $ret .= "</$elm>\n";
+            }
+            $ret .= "    </maintainer>\n";
         }
-        $tar = new Archive_Tar($file, true);
-        $content = $tar->listContent();
-        if (!is_array($content)) {
-            return $this->raiseError('tgz :: could not get contents of package');
+        $ret .= "  </maintainers>\n";
+        $ret .= $this->_makeReleaseXml($pkginfo);
+        if (@sizeof($pkginfo['changelog']) > 0) {
+            $ret .= "  <changelog>\n";
+            foreach ($pkginfo['changelog'] as $oldrelease) {
+                $ret .= $this->_makeReleaseXml($oldrelease, true);
+            }
+            $ret .= "  </changelog>\n";
         }
-        $xml = null;
-        foreach ($content as $file) {
-            $name = $file['filename'];
-            if (ereg('^.*/package.xml$', $name, $match)) {
-                $xml = $match[0];
+        $ret .= "</package>\n";
+        return $ret;
+    }
+
+    // }}}
+    // {{{ _makeReleaseXml()
+
+    /**
+     * Generate part of an XML description with release information.
+     *
+     * @param array  array with release information
+     * @param bool   whether the result will be in a changelog element
+     *
+     * @return string XML data
+     *
+     * @access private
+     */
+    function _makeReleaseXml($pkginfo, $changelog = false)
+    {
+        $indent = $changelog ? "  " : "";
+        $ret = "$indent  <release>\n";
+        if (!empty($pkginfo['version'])) {
+            $ret .= "$indent    <version>$pkginfo[version]</version>\n";
+        }
+        if (!empty($pkginfo['release_date'])) {
+            $ret .= "$indent    <date>$pkginfo[release_date]</date>\n";
+        }
+        if (!empty($pkginfo['release_license'])) {
+            $ret .= "$indent    <license>$pkginfo[release_license]</license>\n";
+        }
+        if (!empty($pkginfo['release_state'])) {
+            $ret .= "$indent    <state>$pkginfo[release_state]</state>\n";
+        }
+        if (!empty($pkginfo['release_notes'])) {
+            $ret .= "$indent    <notes>$pkginfo[release_notes]</notes>\n";
+        }
+        if (sizeof($pkginfo['release_deps']) > 0) {
+            $ret .= "$indent    <deps>\n";
+            foreach ($pkginfo['release_deps'] as $dep) {
+                $ret .= "$indent      <dep type=\"$dep[type]\" rel=\"$dep[rel]\"";
+                if (isset($dep['version'])) {
+                    $ret .= " version=\"$dep[version]\"";
+                }
+                if (isset($dep['name'])) {
+                    $ret .= ">$dep[name]</dep>\n";
+                } else {
+                    $ret .= "/>\n";
+                }
             }
+            $ret .= "$indent    </deps>\n";
         }
-        $tmpdir = System::mkTemp('-d pear');
-        $this->addTempFile($tmpdir);
-        if (!$xml || !$tar->extractList($xml, $tmpdir)) {
-            return $this->raiseError('tgz :: could not extract the package.xml file');
+        if (isset($pkginfo['filelist'])) {
+            $ret .= "$indent    <filelist>\n";
+            foreach ($pkginfo['filelist'] as $file => $fa) {
+                if ($fa['role'] == 'extsrc') {
+                    $ret .= "$indent      <libfile>\n";
+                    $ret .= "$indent        <libname>$file</libname>\n";
+                    $ret .= "$indent        <sources>$fa[sources]</sources>\n";
+                    $ret .= "$indent      </libfile>\n";
+                } else {
+                    $ret .= "$indent      <file role=\"$fa[role]\"";
+                    if (isset($fa['baseinstalldir'])) {
+                        $ret .= " baseinstalldir=\"$fa[baseinstalldir]\"";
+                    }
+                    if (isset($fa['md5sum'])) {
+                        $ret .= " md5sum=\"$fa[md5sum]\"";
+                    }
+                    $ret .= ">$file</file>\n";
+                }
+            }
+            $ret .= "$indent    </filelist>\n";
         }
-        return $this->infoFromDescriptionFile("$tmpdir/$xml");
+        $ret .= "$indent  </release>\n";
+        return $ret;
+    }
 
     // }}}
-    }
 }
 ?>
\ No newline at end of file
index e8b4b610d81a866359533eb0473f1c213cab9343..62ad1cdea3a8935e3c77365a72b44a16282a17d8 100644 (file)
@@ -24,7 +24,7 @@ require_once 'PEAR.php';
  * Last created PEAR_Config instance.
  * @var object
  */
-$GLOBALS['_PEAR_Config_last_instance'] = null;
+$GLOBALS['_PEAR_Config_instance'] = null;
 
 define('PEAR_CONFIG_DEFAULT_DOCDIR',
        PHP_DATADIR.DIRECTORY_SEPARATOR.'pear'.DIRECTORY_SEPARATOR.'doc');
@@ -122,12 +122,22 @@ class PEAR_Config extends PEAR
             'default' => 1,
             'doc' => 'verbosity level',
             ),
+        'preferred_state' => array(
+            'type' => 'set',
+            'default' => 'stable',
+            'doc' => 'the installer will prefer releases with this state
+when installing packages without a version or state specified',
+            'valid_set' => array(
+                'stable', 'beta', 'alpha', 'devel', 'snapshot', 'any'),
+            ),
+/*
         'testset1' => array(
             'type' => 'set',
             'default' => 'foo',
             'doc' => 'test set',
             'valid_set' => array('foo', 'bar'),
             ),
+*/
         );
 
     // }}}
@@ -165,7 +175,6 @@ class PEAR_Config extends PEAR
         $this->layers = array_keys($this->configuration);
         $this->files['user'] = $user_file;
         $this->files['system'] = $system_file;
-        $GLOBALS['_PEAR_Config_last_instance'] = &$this;
         if ($user_file && file_exists($user_file)) {
             $this->readConfigFile($user_file);
         }
@@ -175,6 +184,7 @@ class PEAR_Config extends PEAR
         foreach ($this->configuration_info as $key => $info) {
             $this->configuration['default'][$key] = $info['default'];
         }
+        //$GLOBALS['_PEAR_Config_instance'] = &$this;
     }
 
     // }}}
@@ -197,11 +207,12 @@ class PEAR_Config extends PEAR
      */
     function &singleton($user_file = '', $system_file = '')
     {
-        if (empty($GLOBALS['_PEAR_Config_last_instance'])) {
-            $obj =& new PEAR_Config($user_file, $system_file);
-            $GLOBALS['_PEAR_Config_last_instance'] = &$obj;
+        if (is_object($GLOBALS['_PEAR_Config_instance'])) {
+            return $GLOBALS['_PEAR_Config_instance'];
         }
-        return $GLOBALS['_PEAR_Config_last_instance'];
+        $GLOBALS['_PEAR_Config_instance'] =
+             &new PEAR_Config($user_file, $system_file);
+        return $GLOBALS['_PEAR_Config_instance'];
     }
 
     // }}}
@@ -318,7 +329,7 @@ class PEAR_Config extends PEAR
         }
         $data = $this->configuration[$layer];
         $this->_encodeOutput($data);
-        if (!@is_writeable($file)) {
+        if (@file_exists($file) && !@is_writeable($file)) {
             return $this->raiseError("no write access to $file!");
         }
         $fp = @fopen($file, "w");
@@ -354,7 +365,7 @@ class PEAR_Config extends PEAR
         $size = filesize($file);
         $contents = fread($fp, $size);
         $version = '0.1';
-        if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, &$matches)) {
+        if (preg_match('/^#PEAR_Config\s+(\S+)\s+/si', $contents, $matches)) {
             $version = $matches[1];
             $contents = substr($contents, strlen($matches[0]));
         }
@@ -446,7 +457,7 @@ class PEAR_Config extends PEAR
     }
 
     // }}}
-    // {{{ get(key)
+    // {{{ get(key, [layer])
 
     /**
      * Returns a configuration value, prioritizing layers as per the
@@ -458,12 +469,16 @@ class PEAR_Config extends PEAR
      *
      * @access public
      */
-    function get($key)
+    function get($key, $layer = null)
     {
-        foreach ($this->layers as $layer) {
-            if (isset($this->configuration[$layer][$key])) {
-                return $this->configuration[$layer][$key];
+        if ($layer === null) {
+            foreach ($this->layers as $layer) {
+                if (isset($this->configuration[$layer][$key])) {
+                    return $this->configuration[$layer][$key];
+                }
             }
+        } elseif (isset($this->configuration[$layer][$key])) {
+            return $this->configuration[$layer][$key];
         }
         return null;
     }
@@ -633,6 +648,23 @@ class PEAR_Config extends PEAR
         return false;
     }
 
+    // }}}
+    // {{{ store([layer])
+
+    /**
+     * Stores configuration data in a layer.
+     *
+     * @param string config layer to store
+     *
+     * @return bool TRUE on success, or PEAR error on failure
+     *
+     * @access public
+     */
+    function store($layer = 'user')
+    {
+        return $this->writeConfigFile(null, $layer);
+    }
+
     // }}}
     // {{{ toDefault(key)
 
@@ -716,6 +748,23 @@ class PEAR_Config extends PEAR
         return false;
     }
 
+    // }}}
+    // {{{ isDefinedLayer(key)
+
+    /**
+     * Tells whether a given config layer exists.
+     *
+     * @param string config layer
+     *
+     * @return bool whether <config layer> exists in this object
+     *
+     * @access public
+     */
+    function isDefinedLayer($layer)
+    {
+        return isset($this->configuration[$layer]);
+    }
+
     // }}}
 }
 
index e8cc5e49e483928329b32f3ddb74ebcb3c1314b2..ae6d9c043659e8f7ab72440f2629c2a312b70b16 100644 (file)
@@ -25,14 +25,6 @@ class PEAR_Frontend_CLI extends PEAR
 {
     // {{{ properties
 
-    /**
-     * What type of user interface this frontend is for.
-     * @var string
-     * @access public
-     */
-    var $type = 'CLI';
-    var $lp = ''; // line prefix
-
     var $omode = 'plain';
     var $params = array();
     var $term = array(
@@ -64,28 +56,16 @@ class PEAR_Frontend_CLI extends PEAR
 
     // }}}
 
+    // For now, all the display functions print a "| " at the
+    // beginning of the line.  This is just a temporary thing, it
+    // is for discovering commands that use print instead of
+    // the UI layer.
+
     // {{{ displayLine(text)
 
     function displayLine($text)
     {
-        print "$this->lp$text\n";
-    }
-
-    // }}}
-    // {{{ displayError(eobj)
-
-    function displayError($eobj)
-    {
-        return $this->displayLine($eobj->getMessage());
-    }
-
-    // }}}
-    // {{{ displayFatalError(eobj)
-
-    function displayFatalError($eobj)
-    {
-        $this->displayError($eobj);
-        exit(1);
+        print "| $text\n";
     }
 
     // }}}
@@ -93,8 +73,8 @@ class PEAR_Frontend_CLI extends PEAR
 
     function displayHeading($title)
     {
-        print $this->lp.$this->bold($title)."\n";
-        print $this->lp.str_repeat("=", strlen($title))."\n";
+        print "| ".$this->bold($title)."\n";
+        print "| ".str_repeat("=", strlen($title))."\n";
     }
 
     // }}}
@@ -105,7 +85,7 @@ class PEAR_Frontend_CLI extends PEAR
         if ($type == 'password') {
             system('stty -echo');
         }
-        print "$this->lp$prompt ";
+        print "$prompt ";
         if ($default) {
             print "[$default] ";
         }
@@ -130,7 +110,7 @@ class PEAR_Frontend_CLI extends PEAR
     {
         static $positives = array('y', 'yes', 'on', '1');
         static $negatives = array('n', 'no', 'off', '0');
-        print "$this->lp$prompt [$default] : ";
+        print "$prompt [$default] : ";
         $fp = fopen("php://stdin", "r");
         $line = fgets($fp, 2048);
         fclose($fp);
index 260e3e817efee8ab8d78732120420bdecbab4494..0e9dbdaf191e03021ced5316d2eb7653ef7e918e 100644 (file)
@@ -347,6 +347,10 @@ class PEAR_Installer extends PEAR_Common
 
         // Register that the package is installed -----------------------
         if (empty($options['upgrade'])) {
+            // if 'force' is used, replace the info in registry
+            if (!empty($options['force']) && $this->registry->packageExists($pkgname)) {
+                $this->registry->deletePackage($pkgname);
+            }
             $ret = $this->registry->addPackage($pkgname, $this->pkginfo);
         } else {
             $ret = $this->registry->updatePackage($pkgname, $this->pkginfo, false);
index d4fd0c187fc3772b1626b4eb9425efde16346310..c314e55f8d953f39f3c634cccb8262bf86dcfb49 100644 (file)
@@ -26,7 +26,6 @@ require_once 'PEAR/Common.php';
  *
  * TODO:
  *  - add an extra param the dir where to place the created package
- *  - finish and test Windows support
  *
  * @since PHP 4.0.2
  * @author Stig Bakken <ssb@fast.no>
@@ -35,51 +34,16 @@ class PEAR_Packager extends PEAR_Common
 {
     // {{{ properties
 
-    /** assoc with information about the package */
-    var $pkginfo = array();
-
-    /** name of the package directory, for example Foo-1.0 */
-    var $pkgdir;
-
-    /** directory where PHP code files go */
-    var $phpdir;
-
-    /** directory where PHP extension files go */
-    var $extdir;
-
-    /** directory where documentation goes */
-    var $docdir;
-
-    /** directory where system state information goes */
-    var $statedir;
-
     /** debug mode (integer) */
     var $debug = 0;
 
-    /** temporary directory */
-    var $tmpdir;
-
-    /** whether file list is currently being copied */
-    var $recordfilelist;
-
-    /** temporary space for copying file list */
-    var $filelist;
-
-    /** package name and version, for example "HTTP-1.0" */
-    var $pkgver;
-
     // }}}
 
     // {{{ constructor
 
-    function PEAR_Packager($phpdir = PEAR_INSTALL_DIR,
-                           $extdir = PEAR_EXTENSION_DIR,
-                           $docdir = '')
+    function PEAR_Packager()
     {
         $this->PEAR();
-        $this->phpdir = $phpdir;
-        $this->extdir = $extdir;
-        $this->docdir = $docdir;
     }
 
     // }}}
@@ -135,23 +99,41 @@ class PEAR_Packager extends PEAR_Common
                 return $this->raiseError("File $fname does not exist");
             } else {
                 $filelist[$i++] = $fname;
+                if (empty($pkginfo['filelist'][$fname]['md5sum'])) {
+                    $md5sum = md5_file($fname);
+                    $pkginfo['filelist'][$fname]['md5sum'] = $md5sum;
+                }
+                $this->log(2, "Adding file $fname");
             }
         }
-        // XXX TODO: Rebuild the package file as the old method did?
+        $new_xml = $this->xmlFromInfo($pkginfo);
+        if (PEAR::isError($new_xml)) {
+            return $new_xml;
+        }
+        $tmpdir = $this->mkTempDir(getcwd());
+        $newpkgfile = $tmpdir . DIRECTORY_SEPARATOR . $pkgfile;
+        $np = @fopen($newpkgfile, "w");
+        if (!$np) {
+            return $this->raiseError("PEAR_Packager: unable to rewrite $pkgfile");
+        }
+        fwrite($np, $new_xml);
+        fclose($np);
 
         // TAR the Package -------------------------------------------
         $dest_package = $this->orig_pwd . DIRECTORY_SEPARATOR . "{$pkgver}.tgz";
-        $tar = new Archive_Tar($dest_package, true);
-        $tar->setErrorHandling(PEAR_ERROR_PRINT);
+        $tar =& new Archive_Tar($dest_package, true);
+        $tar->setErrorHandling(PEAR_ERROR_RETURN); // XXX Don't print errors
         // ----- Creates with the package.xml file
-        if (!$tar->create($pkgfile)) {
-            return $this->raiseError('an error ocurred during package creation');
+        $ok = $tar->createModify($newpkgfile, '', $tmpdir);
+        if (PEAR::isError($ok)) {
+            return $ok;
+        } elseif (!$ok) {
+            return $this->raiseError('PEAR_Packager: tarball creation failed');
         }
         // ----- Add the content of the package
         if (!$tar->addModify($filelist, $pkgver)) {
-            return $this->raiseError('an error ocurred during package creation');
+            return $this->raiseError('PEAR_Packager: tarball creation failed');
         }
-
         $this->log(1, "Package $dest_package done");
         $cvsversion = preg_replace('/[^a-z0-9]/i', '_', $pkgversion);
         $cvstag = "RELEASE_$cvsversion";
index d22623e06de6182f364987cdddaf66e9a92a395b..c09e3abddb8a83f1bffb52626804812838c914d3 100644 (file)
 // $Id$
 
 require_once "System.php";
+require_once "PEAR.php";
+
+define("PEAR_REGISTRY_ERROR_LOCK", -2);
 
 /**
  * Administration class used to maintain the installed package database.
  */
-class PEAR_Registry
+class PEAR_Registry extends PEAR
 {
     // {{{ properties
 
-    var $statedir;
+    /** Directory where registry files are stored.
+     * @var string
+     */
+    var $statedir = '';
+
+    /** File where the file map is stored
+     * @var string
+     */
+    var $filemap = '';
+
+    /** Name of file used for locking the registry
+     * @var string
+     */
+    var $lockfile = '';
+
+    /** File descriptor used during locking
+     * @var resource
+     */
+    var $lock_fp = null;
+
+    /** Mode used during locking
+     * @var int
+     */
+    var $lock_mode = 0; // XXX UNUSED
 
     // }}}
 
     // {{{ PEAR_Registry
 
+    /**
+     * PEAR_Registry constructor.
+     *
+     * @param string (optional) PEAR install directory (for .php files)
+     *
+     * @access public
+     */
     function PEAR_Registry($pear_install_dir = PEAR_INSTALL_DIR)
     {
-        $this->statedir = $pear_install_dir . "/.registry";
+        parent::PEAR();
+        $ds = DIRECTORY_SEPARATOR;
+        $this->statedir = $pear_install_dir.$ds.'.registry';
+        $this->filemap  = $pear_install_dir.$ds.'.filemap';
+        $this->lockfile = $pear_install_dir.$ds.'.lock';
+        if (!file_exists($this->filemap)) {
+            $this->_rebuildFileMap();
+        }
+    }
+
+    // }}}
+    // {{{ _PEAR_Registry
+
+    /**
+     * PEAR_Registry destructor.  Makes sure no locks are forgotten.
+     *
+     * @access private
+     */
+    function _PEAR_Registry()
+    {
+        parent::_PEAR();
+        if (is_resource($this->lock_fp)) {
+            $this->_unlock();
+        }
     }
 
     // }}}
 
     // {{{ _assertStateDir()
 
+    /**
+     * Make sure the directory where we keep registry files exists.
+     *
+     * @return bool TRUE if directory exists, FALSE if it could not be
+     * created
+     *
+     * @access private
+     */
     function _assertStateDir()
     {
         if (!@is_dir($this->statedir)) {
-            System::mkdir("-p {$this->statedir}");
+            if (!System::mkdir("-p {$this->statedir}")) {
+                return $this->raiseError("could not create directory '{$this->statedir}'");
+            }
         }
+        return true;
     }
 
     // }}}
     // {{{ _packageFileName()
 
+    /**
+     * Get the name of the file where data for a given package is stored.
+     *
+     * @param string package name
+     *
+     * @return string registry file name
+     *
+     * @access public
+     */
     function _packageFileName($package)
     {
         return "{$this->statedir}/{$package}.reg";
@@ -80,41 +156,110 @@ class PEAR_Registry
     }
 
     // }}}
+    // {{{ _rebuildFileMap()
 
-    // {{{ packageExists()
-
-    function packageExists($package)
+    function _rebuildFileMap()
     {
-        return file_exists($this->_packageFileName($package));
+        $packages = $this->listPackages();
+        $files = array();
+        foreach ($packages as $package) {
+            $version = $this->packageInfo($package, 'version');
+            $filelist = $this->packageInfo($package, 'filelist');
+            if (!is_array($filelist)) {
+                continue;
+            }
+            foreach ($filelist as $name => $attrs) {
+                if (isset($attrs['role']) && $attrs['role'] != 'php') {
+                    continue;
+                }
+                if (isset($attrs['baseinstalldir'])) {
+                    $file = $attrs['baseinstalldir'].DIRECTORY_SEPARATOR.$name;
+                } else {
+                    $file = $name;
+                }
+                $file = preg_replace(',^/+,', '', $file);
+                $files[$file] = $package;
+            }
+        }
+        $this->_assertStateDir();
+        $fp = @fopen($this->filemap, 'w');
+        if (!$fp) {
+            return false;
+        }
+        fwrite($fp, serialize($files));
+        fclose($fp);
+        return true;
     }
 
     // }}}
-    // {{{ addPackage()
+    // {{{ _lock()
 
-    function addPackage($package, $info)
+    /**
+     * Lock the registry.
+     *
+     * @param integer lock mode, one of LOCK_EX, LOCK_SH or LOCK_UN.
+     *                See flock manual for more information.
+     *
+     * @return bool TRUE on success, FALSE if locking failed, or a
+     *              PEAR error if some other error occurs (such as the
+     *              lock file not being writable).
+     *
+     * @access private
+     */
+    function _lock($mode = LOCK_EX)
     {
-        if ($this->packageExists($package)) {
-            return false;
+        if ($mode != LOCK_UN && is_resource($this->lock_fp)) {
+            // XXX does not check type of lock (LOCK_SH/LOCK_EX)
+            return true;
         }
-        $fp = $this->_openPackageFile($package, "w");
-        if ($fp === null) {
-            return false;
+        if (PEAR::isError($err = $this->_assertStateDir())) {
+            return $err;
+        }
+        $this->lock_fp = @fopen($this->lockfile, 'w');
+        if (!is_resource($this->lock_fp)) {
+            return $this->raiseError("could not create lock file: $php_errormsg");
+        }
+        if (!(int)flock($this->lock_fp, $mode)) {
+            switch ($mode) {
+                case LOCK_SH: $str = 'shared';    break;
+                case LOCK_EX: $str = 'exclusive'; break;
+                case LOCK_UN: $str = 'unlock';    break;
+                default:      $str = 'unknown';   break;
+            }
+            return $this->raiseError("could not acquire $str lock ($this->lockfile)",
+                                     PEAR_REGISTRY_ERROR_LOCK);
         }
-        fwrite($fp, serialize($info));
-        $this->_closePackageFile($fp);
         return true;
     }
 
     // }}}
-    // {{{ packageInfo()
+    // {{{ _unlock()
 
-    function packageInfo($package = null, $key = null)
+    function _unlock()
+    {
+        $ret = $this->_lock(LOCK_UN);
+        $this->lock_fp = null;
+        return $ret;
+    }
+
+    // }}}
+    // {{{ _packageExists()
+
+    function _packageExists($package)
+    {
+        return file_exists($this->_packageFileName($package));
+    }
+
+    // }}}
+    // {{{ _packageInfo()
+
+    function _packageInfo($package = null, $key = null)
     {
         if ($package === null) {
-            return array_map(array($this, "packageInfo"),
-                             $this->listPackages());
+            return array_map(array($this, '_packageInfo'),
+                             $this->_listPackages());
         }
-        $fp = $this->_openPackageFile($package, "r");
+        $fp = $this->_openPackageFile($package, 'r');
         if ($fp === null) {
             return null;
         }
@@ -130,13 +275,100 @@ class PEAR_Registry
         return null;
     }
 
+    // }}}
+    // {{{ _listPackages()
+
+    function _listPackages()
+    {
+        $pkglist = array();
+        $dp = @opendir($this->statedir);
+        if (!$dp) {
+            return $pkglist;
+        }
+        while ($ent = readdir($dp)) {
+            if ($ent{0} == '.' || substr($ent, -4) != '.reg') {
+                continue;
+            }
+            $pkglist[] = substr($ent, 0, -4);
+        }
+        return $pkglist;
+    }
+
+    // }}}
+
+    // {{{ packageExists()
+
+    function packageExists($package)
+    {
+        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
+            return $e;
+        }
+        $ret = $this->_packageExists($package);
+        $this->_unlock();
+        return $ret;
+    }
+
+    // }}}
+    // {{{ packageInfo()
+
+    function packageInfo($package = null, $key = null)
+    {
+        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
+            return $e;
+        }
+        $ret = $this->_packageInfo($package, $key);
+        $this->_unlock();
+        return $ret;
+    }
+
+    // }}}
+    // {{{ listPackages()
+
+    function listPackages()
+    {
+        if (PEAR::isError($e = $this->_lock(LOCK_SH))) {
+            return $e;
+        }
+        $ret = $this->_listPackages();
+        $this->_unlock();
+        return $ret;
+    }
+
+    // }}}
+    // {{{ addPackage()
+
+    function addPackage($package, $info)
+    {
+        if ($this->packageExists($package)) {
+            return false;
+        }
+        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
+            return $e;
+        }
+        $fp = $this->_openPackageFile($package, 'w');
+        if ($fp === null) {
+            $this->_unlock();
+            return false;
+        }
+        fwrite($fp, serialize($info));
+        $this->_closePackageFile($fp);
+        $this->_unlock();
+        return true;
+    }
+
     // }}}
     // {{{ deletePackage()
 
     function deletePackage($package)
     {
+        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
+            return $e;
+        }
         $file = $this->_packageFileName($package);
-        return @unlink($file);
+        $ret = @unlink($file);
+        $this->_rebuildFileMap();
+        $this->_unlock();
+        return $ret;
     }
 
     // }}}
@@ -148,8 +380,15 @@ class PEAR_Registry
         if (empty($oldinfo)) {
             return false;
         }
-        $fp = $this->_openPackageFile($package, "w");
+        if (PEAR::isError($e = $this->_lock(LOCK_EX))) {
+            return $e;
+        }
+        if (!file_exists($this->filemap)) {
+            $this->_rebuildFileMap();
+        }
+        $fp = $this->_openPackageFile($package, 'w');
         if ($fp === null) {
+            $this->_unlock();
             return false;
         }
         if ($merge) {
@@ -158,26 +397,11 @@ class PEAR_Registry
             fwrite($fp, serialize($info));
         }
         $this->_closePackageFile($fp);
-        return true;
-    }
-
-    // }}}
-    // {{{ listPackages()
-
-    function listPackages()
-    {
-        $pkglist = array();
-        $dp = @opendir($this->statedir);
-        if (!$dp) {
-            return $pkglist;
-        }
-        while ($ent = readdir($dp)) {
-            if ($ent{0} == "." || substr($ent, -4) != ".reg") {
-                continue;
-            }
-            $pkglist[] = substr($ent, 0, -4);
+        if (isset($info['filelist'])) {
+            $this->_rebuildFileMap();
         }
-        return $pkglist;
+        $this->_unlock();
+        return true;
     }
 
     // }}}
index 7f397b72210158fa8635efd1d23350b9d443d9cf..1f20db6508c6cf07cd54c0ea0cc4b3168fb1cf4a 100644 (file)
@@ -19,6 +19,7 @@
 // $Id$
 
 require_once 'PEAR.php';
+require_once 'PEAR/Config.php';
 
 /**
  * This is a class for doing remote operations against the central
@@ -28,16 +29,16 @@ class PEAR_Remote extends PEAR
 {
     // {{{ properties
 
-    var $config_object = null;
+    var $config = null;
 
     // }}}
 
     // {{{ PEAR_Remote(config_object)
 
-    function PEAR_Remote($config_object)
+    function PEAR_Remote(&$config)
     {
         $this->PEAR();
-        $this->config_object = $config_object;
+        $this->config = $config;
     }
 
     // }}}
@@ -51,7 +52,7 @@ class PEAR_Remote extends PEAR
         }
         $method = str_replace("_", ".", $method);
         $request = xmlrpc_encode_request($method, $params);
-        $server_host = $this->config_object->get("master_server");
+        $server_host = $this->config->get("master_server");
         if (empty($server_host)) {
             return $this->raiseError("PEAR_Remote::call: no master_server configured");
         }
@@ -61,13 +62,34 @@ class PEAR_Remote extends PEAR
             return $this->raiseError("PEAR_Remote::call: fsockopen(`$server_host', $server_port) failed");
         }
         $len = strlen($request);
-        fwrite($fp, ("POST /xmlrpc.php HTTP/1.0\r\n".
-                     "Host: $server_host:$server_port\r\n".
-                     "Content-type: text/xml\r\n".
-                     "Content-length: $len\r\n".
-                     "\r\n$request"));
+        $req_headers = "Host: $server_host:$server_port\r\n" .
+             "Content-type: text/xml\r\n" .
+             "Content-length: $len\r\n";
+        $username = $this->config->get('username');
+        $password = $this->config->get('password');
+        if ($username && $password) {
+            $tmp = base64_encode("$username:$password");
+            $req_headers .= "Authorization: Basic $tmp\r\n";
+        }
+        fwrite($fp, ("POST /xmlrpc.php HTTP/1.0\r\n$req_headers\r\n$request"));
         $response = '';
-        while (trim(fgets($fp, 2048)) != ''); // skip headers
+        $line1 = fgets($fp, 2048);
+        if (!preg_match('!^HTTP/[0-9\.]+ (\d+) (.*)!', $line1, $matches)) {
+            return $this->raiseError("PEAR_Remote: invalid HTTP response from XML-RPC server");
+        }
+        switch ($matches[1]) {
+            case "200":
+                break;
+            case "401":
+                if ($username && $password) {
+                    return $this->raiseError("PEAR_Remote: authorization failed", 401);
+                } else {
+                    return $this->raiseError("PEAR_Remote: authorization required, please log in first", 401);
+                }
+            default:
+                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)) {
             $response .= $chunk;
         }
@@ -85,13 +107,20 @@ class PEAR_Remote extends PEAR
                 if ($ret['userinfo'] === '') $ret['userinfo'] = null;
                 if (strtolower($class) == 'db_error') {
                     $ret = $this->raiseError(DB::errorMessage($ret['code']),
-                                                $ret['code'], null, null,
-                                                $ret['userinfo']);
+                                             $ret['code'], null, null,
+                                             $ret['userinfo']);
                 } else {
                     $ret = $this->raiseError($ret['message'], $ret['code'],
-                                                null, null, $ret['userinfo']);
+                                             null, null, $ret['userinfo']);
                 }
             }
+        } elseif (is_array($ret) && sizeof($ret) == 1 &&
+                  isset($ret[0]['faultString']) &&
+                  isset($ret[0]['faultCode'])) {
+            extract($ret[0]);
+            $faultString = "XML-RPC Server Fault: " .
+                 str_replace("\n", " ", $faultString);
+            return $this->raiseError($faultString, $faultCode);
         }
         return $ret;
     }
index fce939283ac732407ee9484b31bf3d361ef65656..a0cb045559384ad8795f9e25c903e30f8ef8a5d0 100644 (file)
@@ -1,10 +1,10 @@
 <!--
-     $Id: package.dtd,v 1.17 2002-02-24 10:45:28 ssb Exp $
+     $Id: package.dtd,v 1.17.2.1 2002-04-09 18:04:28 ssb Exp $
 
-     This is the PEAR package description, version 1.0b3.
+     This is the PEAR package description, version 1.0b4.
      It should be used with the informal public identifier:
 
-         "-//PHP Group//DTD PEAR Package 1.0b3//EN//XML"
+         "-//PHP Group//DTD PEAR Package 1.0b4//EN//XML"
 
      Copyright (c) 1997-2002 The PHP Group             
 
@@ -64,7 +64,9 @@
                debug          (na|on|off)        'na'
                threaded       (na|on|off)        'na'
                format         CDATA              #IMPLIED
-               baseinstalldir CDATA              #IMPLIED>
+               baseinstalldir CDATA              #IMPLIED
+               platform       CDATA              #IMPLIED
+               md5sum         CDATA              #IMPLIED>
 
 <!ELEMENT libfile (libname|sources|includes|libadd)+>
 
@@ -79,5 +81,5 @@
 <!ELEMENT dep (#PCDATA)>
 <!ATTLIST dep
        type    (pkg|ext|php|prog|ldlib|ltlib|os|websrv|sapi) #REQUIRED
-       rel     (has|eq|lt|le|gt|ge)                          #IMPLIED
+       rel     (has|eq|lt|le|gt|ge)                          'has'
        version CDATA                                         #IMPLIED>
index 9f128016117028c18eea62bdd8e3b56a0b68b97a..a8c626b0242998b9a3328dc0cb5c2273842eccf8 100644 (file)
@@ -1,5 +1,8 @@
+dnl This file becomes configure.in for self-contained extensions.
 
-AC_INIT(Makefile.in)
+AC_INIT(config.m4)
+
+PHP_INIT_BUILD_SYSTEM
 
 AC_DEFUN(PHP_WITH_PHP_CONFIG,[
   AC_ARG_WITH(php-config,
@@ -23,20 +26,42 @@ AC_DEFUN(PHP_WITH_PHP_CONFIG,[
   AC_MSG_CHECKING(for PHP extension directory)
   AC_MSG_RESULT($EXTENSION_DIR)
 ])
-
+dnl
+AC_DEFUN(PHP_EXT_BUILDDIR,[.])dnl
+AC_DEFUN(PHP_EXT_SRCDIR,[$abs_srcdir])dnl
+AC_DEFUN(PHP_ALWAYS_SHARED,[
+  ext_output="yes, shared"
+  ext_shared=yes
+  test "[$]$1" = "no" && $1=yes
+])dnl
+dnl
 abs_srcdir=`(cd $srcdir && pwd)`
-
-php_always_shared=yes
+abs_builddir=`pwd`
 
 PHP_CONFIG_NICE(config.nice)
 
 AC_PROG_CC
 AC_PROG_CC_C_O
 
+PHP_SHLIB_SUFFIX_NAME
 PHP_WITH_PHP_CONFIG
 
+PHP_BUILD_SHARED
+
 AC_PREFIX_DEFAULT()
 
+AC_ARG_WITH(openssl,
+[  --with-openssl[=DIR]    Include OpenSSL support (requires OpenSSL >= 0.9.5) ],
+[
+  if test "$withval" != "no"; then
+    PHP_WITH_SHARED
+    PHP_OPENSSL=$withval
+    ext_openssl_shared=yes
+    ext_shared=yes
+    PHP_SETUP_OPENSSL
+  fi
+])
+    
 sinclude(config.m4)
 
 enable_static=no
@@ -44,14 +69,18 @@ enable_shared=yes
 
 AC_PROG_LIBTOOL
 
-SHARED_LIBTOOL='$(LIBTOOL)'
-PHP_COMPILE='$(LIBTOOL) --mode=compile $(COMPILE) -c $<'
+all_targets='$(PHP_MODULES)'
+install_targets=install-modules
 phplibdir="`pwd`/modules"
 CPPFLAGS="$CPPFLAGS -DHAVE_CONFIG_H"
 
 test "$prefix" = "NONE" && prefix="/usr/local"
 test "$exec_prefix" = "NONE" && exec_prefix='$(prefix)'
 
+PHP_SUBST(PHP_MODULES)
+PHP_SUBST(all_targets)
+PHP_SUBST(install_targets)
+
 PHP_SUBST(prefix)
 PHP_SUBST(exec_prefix)
 PHP_SUBST(libdir)
@@ -72,14 +101,13 @@ PHP_SUBST(INCLUDES)
 PHP_SUBST(LEX)
 PHP_SUBST(LEX_OUTPUT_ROOT)
 PHP_SUBST(LFLAGS)
+PHP_SUBST(LDFLAGS)
 PHP_SUBST(SHARED_LIBTOOL)
 PHP_SUBST(LIBTOOL)
 PHP_SUBST(SHELL)
 
-PHP_FAST_OUTPUT(Makefile)
-
-PHP_GEN_CONFIG_VARS
-PHP_GEN_MAKEFILES($PHP_FAST_OUTPUT_FILES)
+PHP_GEN_BUILD_DIRS
+PHP_GEN_GLOBAL_MAKEFILE
 
 test -d modules || mkdir modules
 touch .deps
diff --git a/pear/scripts/pear-get.in b/pear/scripts/pear-get.in
deleted file mode 100644 (file)
index 5ff308d..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-#!@prefix@/bin/php -Cq
-<?php // -*- 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.               |
-// +----------------------------------------------------------------------+
-// | Authors: Stig Bakken <ssb@fast.no>                                   |
-// |          Tomas V.V.Cox <cox@idecnet.com>                             |
-// +----------------------------------------------------------------------+
-//
-
-require_once 'PEAR.php';
-require_once 'PEAR/Remote.php';
-
-error_reporting(E_ALL & ~E_NOTICE);
-
-$subcommands = array(
-    'help'        => 'help [command]',
-    'install'     => 'install [-r] <package file/name>',
-    'upgrade'     => 'upgrade [-r] <package file/name>',
-    'list'        => 'list',
-    'info'        => 'info <package name>',
-);
-
-$shortcuts = array(
-    'list'     => 'remote-list',
-    'upgrade'  => 'install',
-);
-
-$command_options = array(
-    'install' => 'fr',
-);
-
-include "pearcmd-common.php";
-
-if (isset($shortcuts[$command])) {
-    $realcommand = $shortcuts[$command];
-} else {
-    $realcommand = $command;
-}
-
-if (isset($subcommands[$command])) {
-    include "pearcmd-$realcommand.php";
-} elseif (!$store_default_config && !$store_user_config) {
-    usage();
-}
-
-?>
index d7bb854b53bb2cc4e4bb2e7cc4973665ae1d25fc..862e20e35edbbb0090909cf9baefa4314c3f6786 100644 (file)
 //
 
 require_once 'PEAR.php';
-require_once 'PEAR/Common.php';
-require_once 'PEAR/Registry.php';
+require_once "PEAR/Config.php";
+require_once "PEAR/Command.php";
+require_once "Console/Getopt.php";
 
-error_reporting(E_ALL & ~E_NOTICE);
+PEAR_Command::setFrontendType('CLI');
+$all_commands = PEAR_Command::getCommands();
+$cmd_options  = PEAR_Command::getOptions();
 
-$subcommands = array(
-    'help'        => 'help [command]',
-    'uninstall'   => 'uninstall [-r] <package name>',
-    'package'     => 'package [package info file]',
-    'info'        => 'info',
-    'list'        => 'list',
-    'show-config' => 'show-config',
-);
+$progname = basename($argv[0]);
 
-$command_options = array(
-    "list"      => "v",
-    "uninstall" => "fr",
-);
+PEAR::setErrorHandling(PEAR_ERROR_DIE, "$progname: %s\n");
+$argv = Console_Getopt::readPHPArgv();
 
-include "pearcmd-common.php";
+// XXX change Getopt to use raiseError() ?
+$options = Console_Getopt::getopt($argv, "c:C:d:D:h?sSqu:v" . $cmd_options);
+if (PEAR::isError($options)) {
+    usage($options);
+}
+
+$opts = $options[0];
+
+$pear_user_config = '';
+$pear_system_config = '';
+$store_user_config = false;
+$store_system_config = false;
+$verbose = 1;
+
+foreach ($opts as $opt) {
+    switch ($opt[0]) {
+        case 'c':
+            $pear_user_config = $opt[1];
+            break;
+        case 'C':
+            $pear_system_config = $opt[1];
+            break;
+    }
+}
+
+$config = &PEAR_Config::singleton($pear_user_config, $pear_system_config);
+$verbose = $config->get("verbose");
+$cmdopts = array();
+
+foreach ($opts as $opt) {
+    $param = !empty($opt[1]) ? $opt[1] : true;
+    switch ($opt[0]) {
+        case 'd':
+            list($key, $value) = explode('=', $param);
+            $config->set($key, $value, 'user');
+            break;
+        case 'D':
+            list($key, $value) = explode('=', $param);
+            $config->set($key, $value, 'system');
+            break;
+        case 's':
+            $store_user_config = true;
+            break;
+        case 'S':
+            $store_system_config = true;
+            break;
+        case 'u':
+            $config->remove($param, 'user');
+            break;
+        case 'v':
+            $config->set('verbose', $verbose + 1);
+            break;
+        case 'q':
+            $config->set('verbose', $verbose - 1);
+            break;
+        default:
+            // all non pear params goes to the command
+            $cmdopts[$opt[0]] = $param;
+            break;
+    }
+}
+
+if ($store_system_config) {
+    $config->store('system');
+}
+
+if ($store_user_config) {
+    $config->store('user');
+}
+
+$command = (isset($options[1][1])) ? $options[1][1] : null;
+
+if (empty($command) && ($store_user_config || $store_system_config)) {
+    exit;
+}
 
-if (isset($subcommands[$command])) {
-    include "pearcmd-$command.php";
-} elseif (!$store_default_config && !$store_user_config) {
-    usage();
+if (empty($all_commands[$command]) || $command == 'help') {
+    usage(null, @$options[1][2]);
 }
 
+$cmd = PEAR_Command::factory($command, $config);
+if (PEAR::isError($cmd)) {
+    die($cmd->getMessage());
+}
+
+$cmdargs = array_slice($options[1], 2);
+$ok = $cmd->run($command, $cmdopts, $cmdargs);
+if ($ok === false) {
+    PEAR::raiseError("unknown command `$command'");
+}
+
+exit;
+
+// {{{ usage()
+
+function usage($error = null, $helpsubject = null)
+{
+    global $progname, $all_commands;
+    $stderr = fopen('php://stderr', 'w');
+    if (PEAR::isError($error)) {
+        fputs($stderr, $error->getMessage());
+    } elseif ($error !== null) {
+        fputs($stderr, $error);
+    }
+    fputs($stderr,
+        "Usage: $progname [options] command [command-options] <parameters>\n");
+    if ($helpsubject == "options") {
+        fputs($stderr,
+        "Options:\n".
+        "     -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".
+        "     -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");
+    } else {
+        fputs($stderr,
+              "Type \"$progname help options\" to list all options.\n");
+    }
+    fputs($stderr,
+          "Commands:\n   " . implode("\n   ", array_keys($all_commands)) .
+          "\n");
+    fclose($stderr);
+    exit;
+}
+
+// }}}
+// {{{ present_array()
+
+function present_array(&$arr, $keys = null)
+{
+    if ($keys === null) {
+        $keys = array_keys($arr);
+    }
+    $longest_key = max(array_map("strlen", array_keys($arr))) + 2;
+    $format_string = "%{$longest_key}s : %s\n";
+    foreach ($keys as $k) {
+        if (is_array($arr[$k])) {
+            foreach ($arr[$k] as $i => $value) {
+                $x = "$k #$i";
+                $cont = array();
+                foreach(array_keys($value) as $val) {
+                    $cont[] = "$val=" . $value[$val];
+                }
+                $v = implode(", ", $cont);
+                printf($format_string, $x, $v);
+            }
+            continue;
+        } else {
+            $v = $arr[$k];
+            printf($format_string, $k, $v);
+        }
+    }
+}
+
+// }}}
+// {{{ heading()
+
+function heading($text)
+{
+    $l = strlen(trim($text));
+    print rtrim($text) . "\n" . str_repeat("=", $l) . "\n";
+}
+
+// }}}
+
 /*
  * Local variables:
  * tab-width: 4
diff --git a/pear/scripts/pearcmd-common.php b/pear/scripts/pearcmd-common.php
deleted file mode 100644 (file)
index 6293532..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-<?php
-
-require_once "PEAR/Config.php";
-require_once "Console/Getopt.php";
-
-$progname = basename($argv[0]);
-
-PEAR::setErrorHandling(PEAR_ERROR_PRINT, "$progname: %s\n");
-
-$argv = Console_Getopt::readPHPArgv();
-if (PEAR::isError($argv)) {
-    die($argv->getMessage());
-}
-$options = Console_Getopt::getopt($argv, "c:C:d:D:h?sSqu:v");
-if (PEAR::isError($options)) {
-    usage($options);
-}
-
-if (OS_WINDOWS) {
-    $pear_default_config = PHP_SYSCONFDIR.DIRECTORY_SEPARATOR.'pearsys.ini';
-    $pear_user_config    = PHP_SYSCONFDIR.DIRECTORY_SEPARATOR.'pear.ini';
-} else {
-    $pear_default_config = PHP_SYSCONFDIR.DIRECTORY_SEPARATOR.'pear.conf';
-    $pear_user_config    = getenv('HOME').DIRECTORY_SEPARATOR.'.pearrc';
-}
-
-$opts = $options[0];
-
-foreach ($opts as $opt) {
-    switch ($opt[0]) {
-        case 'c':
-            $pear_user_config = $opt[1];
-            break;
-        case 'C':
-            $pear_default_config = $opt[1];
-            break;
-    }
-}
-
-$config = new PEAR_Config($pear_user_config, $pear_default_config);
-$store_user_config = false;
-$store_default_config = false;
-$verbose = 1;
-
-foreach ($opts as $opt) {
-    $param = $opt[1];
-    switch ($opt[0]) {
-        case 'd':
-            list($key, $value) = explode('=', $param);
-            $config->set($key, $value);
-            break;
-        case 'D':
-            list($key, $value) = explode('=', $param);
-            $config->set($key, $value, true);
-            break;
-        case 's':
-            $store_user_config = true;
-            break;
-        case 'S':
-            $store_default_config = true;
-            break;
-        case 'u':
-            $config->toDefault($param);
-            break;
-        case 'v':
-            $verbose++;
-            break;
-        case 'q':
-            $verbose--;
-            break;
-    }
-}
-
-if ($store_default_config) {
-    if (@is_writeable($pear_default_config)) {
-        $config->writeConfigFile($pear_default_config, 'default');
-    } else {
-        die("You don't have write access to $pear_default_config, exiting!\n");
-    }
-}
-
-if ($store_user_config) {
-    $config->writeConfigFile($pear_user_config, 'userdefined');
-}
-
-$fallback_config = array(
-    'master_server' => 'pear.php.net',
-    'php_dir'       => PEAR_INSTALL_DIR,
-    'ext_dir'       => PEAR_EXTENSION_DIR,
-    'doc_dir'       => PHP_DATADIR . DIRECTORY_SEPARATOR . 'pear' .
-                       DIRECTORY_SEPARATOR . 'doc',
-    'verbose'       => true,
-);
-$fallback_done = array();
-
-foreach ($fallback_config as $key => $value) {
-    if (!$config->isDefined($key)) {
-        $config->set($key, $value);
-        $fallback_done[$key] = true;
-    }
-}
-
-//$verbose    = $config->get("verbose");
-$script_dir = $config->get("php_dir");
-$ext_dir    = $config->get("ext_dir");
-$doc_dir    = $config->get("doc_dir");
-
-$command = (isset($options[1][1])) ? $options[1][1] : null;
-$rest = array_slice($options[1], 2);
-
-if (isset($command_options[$command])) {
-    $tmp = Console_Getopt::getopt($rest, $command_options[$command]);
-    if (PEAR::isError($tmp)) {
-        usage($tmp);
-    }
-    $cmdopts = $tmp[0];
-    $cmdargs = $tmp[1];
-} else {
-    $cmdopts = array();
-    $cmdargs = $rest;
-}
-
-// {{{ usage()
-
-function usage($error = null, $helpsubject = null)
-{
-    global $progname, $subcommands;
-    $stderr = fopen('php://stderr', 'w');
-    if (PEAR::isError($error)) {
-        fputs($stderr, $error->getMessage());
-    } elseif ($error !== null) {
-        fputs($stderr, $error);
-    }
-    fputs($stderr,
-        "Usage: $progname [options] command [command-options] <parameters>\n");
-    if ($helpsubject == "options") {
-        fputs($stderr,
-        "Options:\n".
-        "     -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".
-        "     -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");
-    } else {
-        fputs($stderr, "Type \"$progname help options\" to list all options.\n");
-    }        
-    fputs($stderr, "Commands:".implode("\n   ", $subcommands) . "\n");
-    fclose($stderr);
-    exit;
-}
-
-// }}}
-// {{{ present_array()
-
-function present_array(&$arr, $keys = null)
-{
-    if ($keys === null) {
-        $keys = array_keys($arr);
-    }
-    $longest_key = max(array_map("strlen", array_keys($arr))) + 2;
-    $format_string = "%{$longest_key}s : %s\n";
-    foreach ($keys as $k) {
-        if (is_array($arr[$k])) {
-            foreach ($arr[$k] as $i => $value) {
-                $x = "$k #$i";
-                $cont = array();
-                foreach(array_keys($value) as $val) {
-                    $cont[] = "$val=" . $value[$val];
-                }
-                $v = implode(", ", $cont);
-                printf($format_string, $x, $v);
-            }
-            continue;
-        } else {
-            $v = $arr[$k];
-            printf($format_string, $k, $v);
-        }
-    }
-}
-
-// }}}
-// {{{ heading()
-
-function heading($text)
-{
-    $l = strlen(trim($text));
-    print rtrim($text) . "\n" . str_repeat("=", $l) . "\n";
-}
-
-// }}}
-
-?>
\ No newline at end of file
diff --git a/pear/scripts/pearcmd-help.php b/pear/scripts/pearcmd-help.php
deleted file mode 100644 (file)
index 5bb8b7d..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-
-if (isset($cmdargs[0])) {
-    usage(null, $cmdargs[0]);
-} else {
-    usage();
-}
-
-?>
\ No newline at end of file
diff --git a/pear/scripts/pearcmd-info.php b/pear/scripts/pearcmd-info.php
deleted file mode 100644 (file)
index 99b6b1c..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-
-require_once "PEAR/Common.php";
-$parser = new PEAR_Common;
-$parser->setErrorHandling(PEAR_ERROR_DIE, "pear info: %s\n");
-$info = $parser->infoFromTgzFile($cmdargs[0]);
-unset($info['filelist']);
-present_array($info);
-
-?>
\ No newline at end of file
diff --git a/pear/scripts/pearcmd-install.php b/pear/scripts/pearcmd-install.php
deleted file mode 100644 (file)
index 4a4a349..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-include_once 'PEAR/Installer.php';
-$pkgfile = $cmdargs[0];
-$installer =& new PEAR_Installer($script_dir, $ext_dir, $doc_dir);
-$installer->setErrorHandling(PEAR_ERROR_DIE,
-                             basename($pkgfile) . ": %s\n");
-$installer->debug = $verbose;
-$install_options = array();
-if ($command == 'upgrade') {
-    $install_options['upgrade'] = true;
-}
-foreach ($cmdopts as $opt) {
-    switch ($opt[0]) {
-        case 'r':
-            // This option is for use by rpm and other package
-            // tools that can install files etc. by itself, but
-            // still needs to register the package as installed in
-            // PEAR's local registry.
-            $install_options['register_only'] = true;
-            break;
-        case 'f':
-            $install_options['force'] = true;
-            break;
-    }
-}
-if ($installer->install($pkgfile, $install_options, $config)) {
-    print "install ok\n";
-} else {
-    print "install failed\n";
-}
-
-?>
\ No newline at end of file
diff --git a/pear/scripts/pearcmd-list.php b/pear/scripts/pearcmd-list.php
deleted file mode 100644 (file)
index 6bf0be5..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-
-$reg = new PEAR_Registry($script_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']);
-}
-
-?>
\ No newline at end of file
diff --git a/pear/scripts/pearcmd-package.php b/pear/scripts/pearcmd-package.php
deleted file mode 100644 (file)
index 5cc485a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-include_once 'PEAR/Packager.php';
-$pkginfofile = isset($cmdargs[0]) ? $cmdargs[0] : null;
-$packager =& new PEAR_Packager($script_dir, $ext_dir, $doc_dir);
-$packager->setErrorHandling(PEAR_ERROR_DIE, "pear page: %s\n");
-$packager->debug = $verbose;
-if (PEAR::isError($packager->Package($pkginfofile))) {
-    print "\npackage failed\n";
-} else {
-    print "package ok\n";
-}
-
-
-?>
\ No newline at end of file
diff --git a/pear/scripts/pearcmd-remote-list.php b/pear/scripts/pearcmd-remote-list.php
deleted file mode 100644 (file)
index c9db676..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-$remote = new PEAR_Remote($config);
-$result = $remote->call('package.listAll', 1);
-$i = $j = 0;
-
-if (PEAR::isError($result)) {
-    die("\n\n   Error while executing command!\n\n");
-}
-
-heading("Available packages");
-
-foreach ($result as $package => $info) {
-    if ($i++ % 20 == 0) {
-        if ($j++ > 0) {
-            print "\n";
-        }
-        printf("%-20s %-10s %-15s %s\n",
-               "Package", "Stable", "Lead", "Category");
-        print str_repeat("-", 75)."\n";
-    }
-    if (empty($info['stable'])) {
-        $info['stable'] = '(none)';
-    }
-    $stable = (string)$info['stable'];
-    printf("%-20s %-10s %-15s %s\n", $package,
-           $info['stable'], $info['lead'], $info['category']);
-}
-
-?>
\ No newline at end of file
diff --git a/pear/scripts/pearcmd-show-config.php b/pear/scripts/pearcmd-show-config.php
deleted file mode 100644 (file)
index 0ebc70a..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-
-$keys = $config->getKeys();
-foreach ($keys as $key) {
-    $value = $config->get($key);
-    $xi = "";
-    if ($config->isDefaulted($key)) {
-        $xi .= " (default)";
-    }
-    if (isset($fallback_done[$key])) {
-        $xi .= " (built-in)";
-    }
-    printf("%s = %s%s\n", $key, $value, $xi);
-}
-
-?>
\ No newline at end of file
diff --git a/pear/scripts/pearcmd-uninstall.php b/pear/scripts/pearcmd-uninstall.php
deleted file mode 100644 (file)
index 18f4e41..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-
-include_once 'PEAR/Installer.php';
-$pkgfile = $cmdargs[0];
-$installer =& new PEAR_Installer($script_dir, $ext_dir, $doc_dir);
-$installer->setErrorHandling(PEAR_ERROR_DIE,
-                             basename($pkgfile) . ": %s\n");
-$installer->debug = $verbose;
-$uninstall_options = array();
-foreach ($cmdopts as $opt) {
-    switch ($opt[0]) {
-        case 'r':
-            $uninstall_options['register_only'] = true;
-            break;
-        case 'f':
-            $uninstall_options['force'] = true;
-            break;
-    }
-}
-if ($installer->uninstall($pkgfile, $uninstall_options)) {
-    print "uninstall ok\n";
-} else {
-    print "uninstall failed\n";
-}
-
-?>
index 33b5ad2cfb2f4904752cb43efb7f78cdaf7ecbe2..537431ffad1ee0e34528920bee4bede35523ba9a 100644 (file)
@@ -3,8 +3,8 @@
 prefix='@prefix@'
 phpdir="$prefix/lib/php/build"
 builddir="`pwd`"
-FILES_BUILD="dynlib.mk fastgen.sh library.mk ltlib.mk mkdep.awk program.mk rules.mk rules_common.mk rules_pear.mk shtool"
-FILES="acinclude.m4 dynlib.m4"
+FILES_BUILD="mkdep.awk shtool"
+FILES="acinclude.m4 Makefile.global scan_makefile_in.awk"
 
 if test ! -r config.m4; then
   echo "Cannot find config.m4. "
@@ -17,8 +17,6 @@ test -d build || mkdir build
 (cd $phpdir && cp $FILES_BUILD $builddir/build)
 (cd $phpdir && cp $FILES $builddir)
 
-mv build/rules_pear.mk build/rules.mk
-
 sed \
 -e "s#@prefix@#$prefix#" \
 < $phpdir/pear.m4 > configure.in
index 08163b331d02cfe38f97cec19f945d496bbaa1aa..b52d16c913039035dd179bc768dc04c68dda82e7 100644 (file)
@@ -20,8 +20,11 @@ $config = new PEAR_Config("user.conf", "system.conf");
 dump_array("files", $config->files);
 
 print "#2 testing: singleton\n";
-$cf2 = PEAR_Config::singleton();
-dump_array("files", $cf2->files);
+$o1 = &PEAR_Config::singleton();
+$o1->blah = 'blah';
+$o2 = &PEAR_Config::singleton();
+var_dump($o1->blah);
+@var_dump($o2->blah);
 
 print "#3 testing: readConfigFile\n";
 $config->readConfigFile("user2.conf", "user");
@@ -167,7 +170,8 @@ function dump_config(&$obj, $layer = null) {
 #1 testing: constructor
 files: system="system.conf" user="user.conf"
 #2 testing: singleton
-files: system="system.conf" user="user.conf"
+string(4) "blah"
+string(4) "blah"
 #3 testing: readConfigFile
 user: verbose="2"
 system: master_server="pear.php.net"
@@ -196,7 +200,7 @@ string(9) "directory"
 #8 testing: getDocs
 master_server: name of the main PEAR server
 #9 testing: getKeys
-doc_dir ext_dir master_server password php_dir testset1 username verbose
+doc_dir ext_dir master_server password php_dir preferred_state username verbose
 #10 testing: definedBy
 string(7) "default"
 string(4) "user"
index 99510fd0a494a38eca106c161bf68b9e65398050..e602aa2887c2ea627b8b9c8fc17d7de21cb3e5d1 100644 (file)
@@ -30,7 +30,7 @@ function test_error_handler($errno, $errmsg, $file, $line, $vars) {
        }
        $prefix = $errortype[$errno];
        $file = basename($file);
-       print "\n$prefix: $errmsg in $file on line $line\n";
+       print "\n$prefix: $errmsg in $file on line XXX\n";
 }
 
 error_reporting(E_ALL);
@@ -137,17 +137,17 @@ mode=print: test error[pear_error: message="test error" code=-42 mode=print leve
 mode=callback(function): errorhandler function called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorhandler prefix="" info=""]
 mode=callback(method): errorhandler method called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorclass::errorhandler prefix="" info=""]
 mode=print&trigger: test error
-User Notice: test error in PEAR.php on line 593
+User Notice: test error in PEAR.php on line XXX
 [pear_error: message="test error" code=-42 mode=print|trigger level=notice prefix="" info=""]
 mode=trigger:
-User Notice: test error in PEAR.php on line 593
+User Notice: test error in PEAR.php on line XXX
 [pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" info=""]
 mode=trigger,level=notice:
-User Notice: test error in PEAR.php on line 593
+User Notice: test error in PEAR.php on line XXX
 [pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" info=""]
 mode=trigger,level=warning:
-User Warning: test error in PEAR.php on line 593
+User Warning: test error in PEAR.php on line XXX
 [pear_error: message="test error" code=-42 mode=trigger level=warning prefix="" info=""]
 mode=trigger,level=error:
-User Error: test error in PEAR.php on line 593
+User Error: test error in PEAR.php on line XXX
 [pear_error: message="test error" code=-42 mode=trigger level=error prefix="" info=""]
index 694d877519e5f2b6ec7534dfb3e032e041d8ac99..fb26c9a2b01594998e04a4909dd56cc6557271d6 100644 (file)
@@ -22,19 +22,31 @@ function errorhandler($eobj)
     }
 }
 
+// Test 1
+PEAR::setErrorHandling(PEAR_ERROR_PRINT, "OOPS: %s\n");
+$tmp = new PEAR;
+$tmp->raiseError("error happens");
+
+// Return PEAR to its original state
+$GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
+$GLOBALS['_PEAR_default_error_options']  = E_USER_NOTICE;
+$GLOBALS['_PEAR_default_error_callback'] = '';
+
+// Test 2
 $obj = new PEAR;
 $obj->setErrorHandling(PEAR_ERROR_PRINT);
 $obj->raiseError("error 1\n");
 $obj->setErrorHandling(null);
 $obj->raiseError("error 2\n");
 PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "errorhandler");
-$obj->raiseError("error 3\n");
+$obj->raiseError("error 3");
 $obj->setErrorHandling(PEAR_ERROR_PRINT);
 $obj->raiseError("error 4\n");
 
 ?>
 --EXPECT--
+OOPS: error happens
 error 1
 errorhandler called with an error object.
 error message: error 3
-error 4
+error 4
\ No newline at end of file