]> granicus.if.org Git - php/commitdiff
* new class: PEAR - can be used as a base class for others.
authorStig Bakken <ssb@php.net>
Mon, 24 Jul 2000 08:05:51 +0000 (08:05 +0000)
committerStig Bakken <ssb@php.net>
Mon, 24 Jul 2000 08:05:51 +0000 (08:05 +0000)
* PEAR_Error moved into PEAR.php to reduce the number of files that are
  always included
* cleaned up the PEAR_Error API a bit and changed the two classes using it
* added PEAR_Installer - an administration class for installing packages
  and maintaining a "class/file cache"

pear/DB.php
pear/Makefile.in
pear/PEAR.php [new file with mode: 0644]
pear/PEAR/Installer.php [new file with mode: 0644]
pear/PEAR_Error.php [deleted file]
pear/pear.in

index a9e5e629431b70e1a8886c1cc91478e37d663462..d9f7e51f37099abbfb39e758d5cb3999e87322a8 100644 (file)
@@ -22,6 +22,8 @@
 // Database independent query interface.
 //
 
+require_once "PEAR.php";
+
 // {{{ Database independent error codes.
 
 /*
@@ -220,12 +222,12 @@ class DB {
        /**
         * Tell whether a result code from a DB method is an error
         *
-        * @param $code int result code
+        * @param $value int result code
         *
-        * @return bool whether $code is an error
+        * @return bool whether $value is an error
         */
-       function isError($code) {
-               return is_int($code) && ($code < 0) && ($code > -1000);
+       function isError($value) {
+               return is_object($value) && is_subclass_of($value, "DB_Error");
        }
 
     // }}}
@@ -236,12 +238,12 @@ class DB {
         * Warnings differ from errors in that they are generated by DB,
         * and are not fatal.
         *
-        * @param $code int result code
+        * @param $value mixed result value
         *
-        * @return bool whether $code is a warning
+        * @return bool whether $value is a warning
         */
-       function isWarning($code) {
-               return is_int($code) && ($code <= -1000);
+       function isWarning($value) {
+               return is_object($value) && is_subclass_of($value, "DB_Warning");
        }
 
     // }}}
@@ -250,12 +252,12 @@ class DB {
        /**
         * Return a textual error message for a DB error code
         *
-        * @param $code int error code
+        * @param $value int error code
         *
         * @return string error message, or false if the error code was
         * not recognized
         */
-       function errorMessage($code) {
+       function errorMessage($value) {
                if (!isset($errorMessages)) {
                        $errorMessages = array(
                                DB_OK                   => "no error",
@@ -280,7 +282,7 @@ class DB {
                                DB_WARNING_READ_ONLY    => "warning: read only"
                        );
                }
-               return $errorMessages[$code];
+               return $errorMessages[$value];
        }
 
     // }}}
@@ -401,6 +403,8 @@ class DB {
  * This class implements a wrapper for a DB result set.
  * A new instance of this class will be returned by the DB implementation
  * after processing a query that returns data.
+ *
+ * @author Stig Bakken <ssb@fast.no>
  */
 class DB_result {
     // {{{ properties
@@ -476,6 +480,34 @@ class DB_result {
     // }}}
 }
 
+/**
+ * DB_Error implements a class for reporting portable database error
+ * messages.
+ *
+ * @author Stig Bakken <ssb@fast.no>
+ */
+class DB_Error extends PEAR_Error {
+       function DB_Error($code = DB_ERROR,
+                                         $mode = PEAR_ERROR_RETURN,
+                                         $level = E_USER_NOTICE) {
+               $this->PEAR_Error("DB Error: " . DB::errorMessage($code), $code, $mode, $level);
+       }
+}
+
+/**
+ * DB_Warning implements a class for reporting portable database
+ * warning messages.
+ *
+ * @author Stig Bakken <ssb@fast.no>
+ */
+class DB_Warning extends PEAR_Error {
+       function DB_Error($code = DB_WARNING,
+                                         $mode = PEAR_ERROR_RETURN,
+                                         $level = E_USER_NOTICE) {
+               $this->PEAR_Error("DB Warning: " . DB::errorMessage($code), $code, $mode, $level);
+       }
+}
+
 // Local variables:
 // tab-width: 4
 // c-basic-offset: 4
index 4fbdf6cf53935e8cd582ff86458aeb7e85f12c82..4f336f7fa30f12142b2dfd4de1379e947fd2422e 100644 (file)
@@ -19,7 +19,8 @@ PEAR_FILES = \
        DB/storage.php \
        HTTP.php \
        File/Find.php \
-       PEAR_Error.php
+       PEAR.php \
+       PEAR/Installer.php
 
 install-data-local:
        @if $(mkinstalldirs) $(peardir); then \
diff --git a/pear/PEAR.php b/pear/PEAR.php
new file mode 100644 (file)
index 0000000..7d6f622
--- /dev/null
@@ -0,0 +1,227 @@
+<?php
+//
+// +----------------------------------------------------------------------+
+// | PHP version 4.0                                                      |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group                   |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.0 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_0.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: Sterling Hughes <sterling@php.net>                          |
+// |          Stig Bakken <ssb@fast.no>                                   |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+//
+
+define('PEAR_ERROR_RETURN', 0);
+define('PEAR_ERROR_PRINT', 1);
+define('PEAR_ERROR_TRIGGER', 2);
+define('PEAR_ERROR_DIE', 3);
+
+$_PEAR_destructor_object_list = array();
+
+/**
+ * Base class for other PEAR classes.  Provides rudimentary
+ * emulation of destructors.
+ *
+ * If you want a destructor in your class, inherit PEAR and make a
+ * destructor method called _yourclassname (same name as the
+ * constructor, but with a "_" prefix).  Also, in your constructor you
+ * have to call the PEAR constructor: "$this->PEAR();".  The
+ * destructor method will be called without parameters.  Note that at
+ * in some SAPI implementations (such as Apache), any output during
+ * the request shutdown (in which destructors are called) seems to be
+ * discarded.  If you need to get any debug information from your
+ * destructor, use error_log(), syslog() or something like that
+ * instead.
+ *
+ * @since PHP 4.0.2
+ * @author Stig Bakken <ssb@fast.no>
+ */
+class PEAR {
+    // {{{ constructor
+
+    /**
+     * Constructor.  Registers this object in
+     * $_PEAR_destructor_object_list for destructor emulation.
+     */
+    function PEAR() {
+       global $_PEAR_destructor_object_list;
+       $_PEAR_destructor_object_list[] = &$this;
+    }
+
+    // }}}
+    // {{{ destructor
+
+    /**
+     * Destructor (the emulated type of...).
+     * 
+     * See the note in the class desciption about output from
+     * destructors.
+     */
+    function _PEAR() {
+    }
+
+    // }}}
+    // {{{ isError()
+
+    /**
+     * Tell whether a value is a PEAR error.
+     *
+     * @param $data the value to test
+     *
+     * @return bool true if $data is an error
+     */
+    function isError(&$data) {
+       return is_object($data) && is_subclass_of($data, "PEAR_Error");
+    }
+
+    // }}}
+}
+
+// {{{ _PEAR_call_destructors()
+
+function _PEAR_call_destructors() {
+    global $_PEAR_destructor_object_list;
+    if (is_array($_PEAR_destructor_object_list) && sizeof($_PEAR_destructor_object_list)) {
+       reset($_PEAR_destructor_object_list);
+       while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
+           $destructor = "_".get_class($objref);
+           if (method_exists($objref, $destructor)) {
+               $objref->$destructor();
+           }
+       }
+       // Empty the object list to ensure that destructors are
+       // not called more than once.
+       $_PEAR_destructor_object_list = array();
+    }
+}
+
+// }}}
+
+class PEAR_Error
+{
+    // {{{ properties
+
+       var $classname            = '';
+       var $error_message_prefix = '';
+       var $error_prepend        = '';
+       var $error_append         = '';
+       
+       var $mode                 = PEAR_ERROR_RETURN;
+       var $level                = E_USER_NOTICE;
+       
+       var $message              = '';
+
+       // Wait until we have a stack-groping function in PHP.
+       //var $file    = '';
+       //var $line    = 0;
+       
+
+    // }}}
+    // {{{ constructor
+
+       /**
+        * PEAR_Error constructor
+        *
+        * @param $message error message
+        * @param $code (optional) error code
+        *
+        */
+       function PEAR_Error($message = 'unknown error',
+                                               $code = 0,
+                                               $mode = PEAR_ERROR_RETURN,
+                                               $level = E_USER_NOTICE)
+       {
+               $this->message = $message;
+               $this->code    = $code;
+               $this->mode    = $mode;
+               $this->level   = $level;
+               if (!$this->classname) {
+                       $this->classname = get_class($this);
+               }
+               switch ($this->mode) {
+                       case PEAR_ERROR_PRINT:
+                               print $this->getMessage();
+                               break;
+                       case PEAR_ERROR_TRIGGER:
+                               trigger_error($this->getMessage(), $this->level);
+                               break;
+                       case PEAR_ERROR_DIE:
+                               die($this->getMessage());
+                               break;
+                       case PEAR_ERROR_RETURN:
+                       default:
+                               break;
+               }
+       }
+
+    // }}}
+    // {{{ getMessage()
+
+       
+       /**
+        * Get the error message from an error object.
+        *
+        * @return string full error message
+        */
+       function getMessage ()
+       {
+               return ($this->error_prepend . $this->error_message_prefix .
+                       $this->message       . $this->error_append);
+       }
+       
+
+    // }}}
+    // {{{ getType()
+
+       /**
+        * Get the name of this error/exception.
+        *
+        * @return string error/exception name (type)
+        */
+       function getType ()
+       {
+               return $this->classname;
+       }
+
+    // }}}
+    // {{{ toString()
+
+       /**
+        * Make a string representation of this object.
+        *
+        * @return string a string with an object "summary"
+        */
+       function toString() {
+               $modes = array(PEAR_ERROR_RETURN => "return",
+                                          PEAR_ERROR_PRINT => "print",
+                                          PEAR_ERROR_TRIGGER => "trigger",
+                                          PEAR_ERROR_DIE => "die");
+               $levels = array(E_USER_NOTICE => "notice",
+                                               E_USER_WARNING => "warning",
+                                               E_USER_ERROR => "error");
+               return sprintf("[%s: message=%s code=%d mode=%s level=%s prefix=%s prepend=%s append=%s]",
+                                          $this->message, $this->code, $modes[$this->mode], $levels[$this->level],
+                                          $this->error_message_prefix, $this->error_prepend, $this->error_append);
+       }
+
+    // }}}
+}
+
+register_shutdown_function("_PEAR_call_destructors");
+
+/*
+ * Local Variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
+?>
diff --git a/pear/PEAR/Installer.php b/pear/PEAR/Installer.php
new file mode 100644 (file)
index 0000000..2401826
--- /dev/null
@@ -0,0 +1,465 @@
+<?php
+//
+// +----------------------------------------------------------------------+
+// | PHP version 4.0                                                      |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997, 1998, 1999, 2000 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>                                   |
+// |                                                                      |
+// +----------------------------------------------------------------------+
+//
+
+require_once "PEAR.php";
+
+/**
+ * Administration class used to install PEAR packages and maintain the
+ * class definition cache.
+ *
+ * @since PHP 4.0.2
+ * @author Stig Bakken <ssb@fast.no>
+ */
+class PEAR_Installer extends PEAR {
+
+    // {{{ properties
+
+    /** stack of elements, gives some sort of XML context */
+    var $element_stack;
+
+    /** name of currently parsed XML element */
+    var $current_element;
+
+    /** 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 $pear_phpdir = '/usr/local/lib/php';
+
+    /** directory where PHP extension files go */
+    var $pear_extdir = '/usr/local/lib/php/extensions/debug-non-zts-20000609';
+
+    /** directory where documentation goes */
+    var $pear_docdir = '';
+
+    /** directory where the package wants to put files, relative
+     *  to one of the three previous dirs
+     */
+    var $destdir = '';
+
+    /** debug mode (boolean) */
+    var $debug = false;
+
+    /** class loading cache */
+    var $cache = array();
+
+    /** temporary directory */
+    var $tmpdir;
+
+    /** file pointer for cache file if open */
+    var $cache_fp;
+
+    // }}}
+
+    // {{{ constructor
+
+    function PEAR_Installer() {
+       $this->PEAR();
+       $this->cacheLoad("$this->pear_phpdir/.cache");
+    }
+
+    // }}}
+    // {{{ destructor
+
+    function _PEAR_Installer() {
+       $this->_PEAR();
+       if ($this->tmpdir && is_dir($this->tmpdir)) {
+           system("rm -rf $this->tmpdir");
+       }
+       if ($this->cache_fp && is_resource($this->cache_fp)) {
+           flock($this->cache_fp, LOCK_UN);
+           fclose($this->cache_fp);
+       }
+       $this->tmpdir = null;
+       $this->cache_fp = null;
+    }
+
+    // }}}
+
+    // {{{ cacheLock()
+
+    function cacheLock() {
+       $fp = $this->cache_fp;
+       if (!is_resource($fp)) {
+           $this->cache_fp = $fp = fopen($this->cache_file, "r");
+       }
+       return flock($fp, LOCK_EX);
+    }
+
+    // }}}
+    // {{{ cacheUnlock()
+
+    function cacheUnlock() {
+       $fp = $this->cache_fp;
+       if (!is_resource($fp)) {
+           $this->cache_fp = $fp = fopen($this->cache_file, "r");
+           $doclose = true;
+       }
+       $ret = flock($fp, LOCK_EX);
+       if ($doclose) {
+           fclose($fp);
+       }
+       return $ret;
+    }
+
+    // }}}
+    // {{{ cacheLoad()
+
+    function cacheLoad($file) {
+       $this->cache_file = $file;
+       if (!file_exists($file)) {
+           touch($file);
+       }
+       $fp = $this->cache_fp = fopen($file, "r");
+       $this->cacheLock();
+       while ($line = fgets($fp, 2048)) {
+           list($type, $name, $file) = explode(" ", trim($line));
+           $this->cache[$type][$name] = $file;
+       }
+    }
+
+    // }}}
+    // {{{ cacheSave()
+
+    function cacheSave() {
+       $fp = $this->cache_fp;
+       $wfp = fopen($this->cache_file, "w");
+       if (!$wfp) {
+           return false;
+       }
+       if (is_resource($fp)) {
+           fclose($fp);
+       }
+       $this->cache_fp = $fp = $wfp;
+       reset($this->cache);
+       while (list($type, $entry) = each($this->cache)) {
+           reset($entry);
+           while (list($name, $file) = each($entry)) {
+               fwrite($fp, "$type $name $file\n");
+           }
+       }
+       fclose($fp);
+       $this->cache_fp = $fp = null;
+    }
+
+    // }}}
+    // {{{ cacheUpdateFrom()
+
+    function cacheUpdateFrom($file) {
+       $new = $this->classesDeclaredBy($file);
+       reset($new);
+       while (list($i, $name) = each($new)) {
+           $this->cache['class'][$name] = $file;
+       }
+    }
+
+    // }}}
+
+    // {{{ install()
+
+    /**
+     * Installs the files within the package file specified.
+     *
+     * @param $pkgfile path to the package file
+     *
+     * @return bool true if successful, false if not
+     */
+    function install($pkgfile) {
+       if (!file_exists($pkgfile)) {
+           return new PEAR_Installer_Error("No such file: $pkgfile");
+       }
+
+       $fp = popen("gzip -dc $pkgfile | tar -tf -", "r");
+       if (!$fp) {
+           return new PEAR_Installer_Error("Unable to examine $pkgfile (gzip or tar failed)\n");
+       }
+       while ($line = fgets($fp, 4096)) {
+           $line = rtrim($line);
+           if (preg_match('!^[^/]+/package.xml$!', $line)) {
+               if ($descfile) {
+                   return new PEAR_Installer_Error("Invalid package: multiple package.xml files at depth one!\n");
+               }
+               $descfile = $line;
+           }
+       }
+       pclose($fp);
+
+       if (!$descfile) {
+           return new PEAR_Installer_Error("Invalid package: no package.xml file found!\n");
+       }
+
+       $this->tmpdir = tempnam("/tmp", "pear");
+       if (!mkdir($this->tmpdir, 0755)) {
+           return new PEAR_Installer_Error("Unable to create temporary directory $this->tmpdir.\n");
+       }
+
+       $pwd = trim(`pwd`);
+
+       if (substr($pkgfile, 0, 1) == "/") {
+           $pkgfilepath = $pkgfile;
+       } else {
+           $pkgfilepath = $pwd.'/'.$pkgfile;
+       }
+
+       if (!chdir($this->tmpdir)) {
+           return new PEAR_Installer_Error("Unable to chdir to $this->tmpdir.\n");
+       }
+
+       system("gzip -dc $pkgfilepath | tar -xf -");
+
+       if (!file_exists($descfile)) {
+           return new PEAR_Installer_Error("Huh?  No package.xml file after extracting the archive.\n");
+       }
+
+       $this->pkgdir = dirname($descfile);
+
+       $fp = fopen($descfile, "r");
+       $xp = xml_parser_create();
+       if (!$xp) {
+           return new PEAR_Installer_Error("Unable to create XML parser.\n");
+       }
+       xml_set_object($xp, &$this);
+       xml_set_element_handler($xp, "start_handler", "end_handler");
+       xml_set_character_data_handler($xp, "char_handler");
+       xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
+
+       $this->element_stack = array();
+       $this->pkginfo = array();
+       $this->current_element = false;
+       $destdir = '';
+
+       while ($data = fread($fp, 2048)) {
+           if (!xml_parse($xp, $data, feof($fp))) {
+               return new PEAR_Installer_Error(sprintf("XML error: %s at line %d",
+                                                       xml_error_string(xml_get_error_code($xp)),
+                                                       xml_get_current_line_number($xp)));
+               xml_parser_free($xp);
+           }
+       }
+
+       xml_parser_free($xp);
+
+       if ($this->pkginfo['pkgtype'] != "binary") {
+           return new PEAR_Installer_Error("Invalid package: only binary packages supported yet.\n");
+       }
+
+       return true;
+    }
+
+    // }}}
+    // {{{ start_handler()
+
+    function start_handler($xp, $name, $attribs) {
+       array_push($this->element_stack, $name);
+       $this->current_element = $name;
+       switch ($name) {
+           case "Package":
+               $this->pkginfo['pkgtype'] = strtolower($attribs["Type"]);
+               break;
+       }
+    }
+
+    // }}}
+    // {{{ end_handler()
+
+    function end_handler($xp, $name) {
+       array_pop($this->element_stack);
+       $this->current_element = $this->element_stack[sizeof($this->element_stack)-1];
+    }
+
+    // }}}
+    // {{{ char_handler()
+
+    function char_handler($xp, $data) {
+       global $debug;
+
+       switch ($this->current_element) {
+           case "DestDir":
+               $this->destdir = trim($data);
+               if (substr($this->destdir, 0, 1) == "/") {
+                   $this->destdir = substr($this->destdir, 1);
+               }
+               break;
+           case "Dir":
+               if (!$this->pear_phpdir) {
+                   break;
+               }
+               $dir = trim($data);
+               $d = "$this->pear_phpdir/$this->destdir/$dir";
+               if (is_file($d)) {
+                   print "Error: wanted to create the directory $d\n";
+                   print "       but it was already a file.\n";
+                   break;
+               }
+               if (is_dir($d)) {
+                   break;
+               }
+               if (!mkdir($d, 0755)) {
+                   print "Error: could not mkdir $d\n";
+                   break;
+               }
+               if ($debug) print "[debug] created directory $d\n";
+               break;
+           case "File":
+               if (!$this->pear_phpdir) {
+                   break;
+               }
+               $file = trim($data);
+               $d = "$this->pear_phpdir/$this->destdir";
+               if (!copy("$this->pkgdir/$file", "$d/$file")) {
+                   print "Error: failed to copy $this->pkgdir/$file to $d\n";
+                   break;
+               }
+               if ($debug) print "[debug] installed $d/$file\n";
+               break;
+           case "ExtDir":
+               if (!$this->pear_extdir) {
+                   break;
+               }
+               $dir = trim($data);
+               $d = "$this->pear_extdir/$this->destdir/$dir";
+               if (is_file($d)) {
+                   print "Error: wanted to create the directory $d\n";
+                   print "       but it was already a file.\n";
+                   break;
+               }
+               if (is_dir($d)) {
+                   continue 2;
+               }
+               if (!mkdir($d, 0755)) {
+                   print "Error: could not mkdir $d\n";
+                   break;
+               }
+               if ($debug) print "[debug] created directory $d\n";
+               break;
+           case "ExtFile":
+               if (!$this->pear_extdir) {
+                   break;
+               }
+               $file = trim($data);
+               $d = "$this->pear_extdir/$this->destdir";
+               if (!copy("$this->pkgdir/$file", "$d/$file")) {
+                   print "Error: failed to copy $this->pkgdir/$file to $d\n";
+                   break;
+               }
+               if ($debug) print "[debug] installed $d/$file\n";
+               break;
+           case "DocDir":
+               if (!$this->pear_docdir) {
+                   break;
+               }
+               $dir = trim($data);
+               $d = "$this->pear_docdir/$this->destdir/$dir";
+               if (is_file($d)) {
+                   print "Error: wanted to create the directory $d\n";
+                   print "       but it was already a file.\n";
+                   break;
+               }
+               if (is_dir($d)) {
+                   break;
+               }
+               if (!mkdir($d, 0755)) {
+                   print "Error: could not mkdir $d\n";
+                   break;
+               }
+               if ($debug) print "[debug] created directory $d\n";
+               break;
+           case "DocFile":
+               if (!$this->pear_docdir) {
+                   break;
+               }
+               $file = trim($data);
+               $d = "$this->pear_docdir/$this->destdir";
+               if (!copy("$this->pkgdir/$file", "$d/$file")) {
+                   print "Error: failed to copy $this->pkgdir/$file to $d\n";
+                   break;
+               }
+               if ($debug) {
+                   print "[debug] installed $d/$file\n";
+               }
+               break;
+       }
+    }
+
+    // }}}
+
+    // {{{ classesDeclaredBy()
+
+    /**
+     * Find out which new classes are defined by a file.
+     *
+     * @param $file file name passed to "include"
+     *
+     * @return array classes that were defined
+     */
+    function classesDeclaredBy($file) {
+       $before = get_declared_classes();
+       include($file);
+       $after = get_declared_classes();
+       // using array_slice to renumber array
+       $diff = array_slice(array_diff($after, $before), 0);
+       return $diff;
+    }
+
+// }}}
+
+    // {{{ lockDir()
+
+    /**
+     * Uses advisory locking (flock) to temporarily claim $dir as its
+     * own.
+     *
+     * @param $dir the directory to lock
+     *
+     * @return bool true if successful, false if not
+     */
+    function lockDir($dir) {
+       $lockfile = "$dir/.lock";
+       if (!file_exists($lockfile)) {
+           if (!touch($lockfile)) {
+               // could not create lockfile!
+               return false;
+           }
+       }
+       $fp = fopen($lockfile, "r");
+       if (!flock($fp, LOCK_EX)) {
+           // could not create lock!
+           return false;
+       }
+       return true;
+    }
+
+    // }}}
+}
+
+class PEAR_Installer_Error extends PEAR_Error {
+    // {{{ constructor
+
+    function PEAR_Installer_Error($msg) {
+       $this->PEAR_Error($msg, 0, PEAR_ERROR_DIE);
+    }
+
+    // }}}
+}
+
+?>
diff --git a/pear/PEAR_Error.php b/pear/PEAR_Error.php
deleted file mode 100644 (file)
index 42ebc55..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-//
-// +----------------------------------------------------------------------+
-// | PHP version 4.0                                                      |
-// +----------------------------------------------------------------------+
-// | Copyright (c) 1997, 1998, 1999, 2000 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: Sterling Hughes <sterling@php.net>                          |
-// +----------------------------------------------------------------------+
-//
-// $Id$
-//
-// Commonly needed functions searching directory trees
-//
-
-//
-// This class is based on ideas from Ulf Wendel
-//
-
-class PEAR_Error
-{
-       var $classname            = '';
-       var $error_message_prefix = '';
-       var $error_prepend        = '';
-       var $error_append         = '';
-       
-       var $die_on_error         = false;
-       var $auto_print_error     = false;
-       
-       var $level         = 0;
-       var $trigger_error = false;
-       
-       var $message = '';
-       
-       /*
-        * constructor, set the basics...
-        */
-       function PEAR_Error ($message)
-       {
-               $this->message = $message;
-       }
-       
-       /*
-        *  string getMessage (void)
-        *    Get the error message from an exception object.
-        */
-       function getMessage ()
-       {
-               return ($this->error_prepend . $this->error_message_prefix .
-                       $this->message       . $this->error_append);
-       }
-       
-       /*
-        * string getType (void)
-        *  Get the name of the exception.
-        */
-       function getType ()
-       {
-               return ($this->classname);
-       }
-}
\ No newline at end of file
index 1cc10e8809978783a8ef1fc0a80b80b58af52354..b203a427fc026cb691ae216e3c2e30b76dcd4e67 100644 (file)
@@ -15,220 +15,5 @@ $pkgfile = $argv[0];
 if (!$pkgfile) {
     die("Usage: pear <packagefile>\n");
 }
-if (!file_exists($pkgfile)) {
-    die("No such file: $pkgfile\n");
-}
-
-$fp = popen("gzip -dc $pkgfile | tar -tf -", "r");
-if (!$fp) {
-    die("Unable to examine $pkgfile (gzip or tar failed)\n");
-}
-while ($line = fgets($fp, 4096)) {
-    $line = rtrim($line);
-    if (preg_match('!^[^/]+/package.xml$!', $line)) {
-       if ($descfile) {
-           die("Invalid package: multiple package.xml files at depth one!\n");
-       }
-       $descfile = $line;
-    }
-}
-pclose($fp);
-
-if (!$descfile) {
-    die("Invalid package: no package.xml file found!\n");
-}
-
-$tmpdir = tempnam("/tmp", "pear");
-if (!mkdir($tmpdir, 0755)) {
-    die("Unable to create temporary directory $tmpdir.\n");
-}
-
-register_shutdown_function("cleanup");
-
-$pwd = trim(`pwd`);
-
-if (substr($pkgfile, 0, 1) == "/") {
-    $pkgfilepath = $pkgfile;
-} else {
-    $pkgfilepath = $pwd.'/'.$pkgfile;
-}
-
-if (!chdir($tmpdir)) {
-    die("Unable to chdir to $tmpdir.\n");
-}
-
-system("gzip -dc $pkgfilepath | tar -xf -");
-
-if (!file_exists($descfile)) {
-    die("Huh?  No package.xml file after extracting the archive.\n");
-}
-
-$pkgdir = dirname($descfile);
-
-$fp = fopen($descfile, "r");
-$xp = xml_parser_create();
-if (!$xp) {
-    die("Unable to create XML parser.\n");
-}
-xml_set_element_handler($xp, "start_handler", "end_handler");
-xml_set_character_data_handler($xp, "char_handler");
-xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
-
-$element_stack = array();
-$current_element = false;
-$destdir = '';
-$pkginfo = array();
-
-while ($data = fread($fp, 2048)) {
-    if (!xml_parse($xp, $data, feof($fp))) {
-        die(sprintf("XML error: %s at line %d",
-                    xml_error_string(xml_get_error_code($xp)),
-                    xml_get_current_line_number($xp)));
-    }
-}
-
-if ($pkginfo['pkgtype'] != "binary") {
-    die("Invalid package: only binary packages supported yet.\n");
-}
-
-print "ok so far\n";
-exit;
-
-function start_handler($xp, $name, $attribs) {
-    global $element_stack, $current_element, $pkginfo;
-    array_push($element_stack, $name);
-    $current_element = $name;
-    switch ($name) {
-       case "Package":
-           $pkginfo['pkgtype'] = strtolower($attribs["Type"]);
-           break;
-    }
-}
-
-function end_handler($xp, $name) {
-    global $element_stack, $current_element;
-    array_pop($element_stack);
-    $current_element = $element_stack[sizeof($element_stack)-1];
-}
-
-function char_handler($xp, $data) {
-    global $element_stack, $current_element, $pkginfo;
-    global $phpfiles, $extfiles, $docfiles, $pkgdir;
-    global $pear_phpdir, $pear_extdir, $pear_docdir;
-    global $destdir, $debug;
-
-    switch ($current_element) {
-       case "DestDir":
-           $destdir = trim($data);
-           if (substr($destdir, 0, 1) == "/") {
-               $destdir = substr($destdir, 1);
-           }
-           break;
-       case "Dir":
-           if (!$pear_phpdir) {
-               break;
-           }
-           $dir = trim($data);
-           $d = "$pear_phpdir/$destdir/$dir";
-           if (is_file($d)) {
-               print "Error: wanted to create the directory $d\n";
-               print "       but it was already a file.\n";
-               continue 2;
-           }
-           if (is_dir($d)) {
-               continue 2;
-           }
-           if (!mkdir($d, 0755)) {
-               print "Error: could not mkdir $d\n";
-               continue 2;
-           }
-           if ($debug) print "[debug] created directory $d\n";
-           break;
-       case "File":
-           if (!$pear_phpdir) {
-               break;
-           }
-           $file = trim($data);
-           $d = "$pear_phpdir/$destdir";
-           if (!copy("$pkgdir/$file", "$d/$file")) {
-               print "Error: failed to copy $pkgdir/$file to $d\n";
-               continue 2;
-           }
-           if ($debug) print "[debug] installed $d/$file\n";
-           break;
-       case "ExtDir":
-           if (!$pear_extdir) {
-               break;
-           }
-           $dir = trim($data);
-           $d = "$pear_extdir/$destdir/$dir";
-           if (is_file($d)) {
-               print "Error: wanted to create the directory $d\n";
-               print "       but it was already a file.\n";
-               continue 2;
-           }
-           if (is_dir($d)) {
-               continue 2;
-           }
-           if (!mkdir($d, 0755)) {
-               print "Error: could not mkdir $d\n";
-               continue 2;
-           }
-           if ($debug) print "[debug] created directory $d\n";
-           break;
-       case "ExtFile":
-           if (!$pear_extdir) {
-               break;
-           }
-           $file = trim($data);
-           $d = "$pear_extdir/$destdir";
-           if (!copy("$pkgdir/$file", "$d/$file")) {
-               print "Error: failed to copy $pkgdir/$file to $d\n";
-               continue 2;
-           }
-           if ($debug) print "[debug] installed $d/$file\n";
-           break;
-       case "DocDir":
-           if (!$pear_docdir) {
-               break;
-           }
-           $dir = trim($data);
-           $d = "$pear_docdir/$destdir/$dir";
-           if (is_file($d)) {
-               print "Error: wanted to create the directory $d\n";
-               print "       but it was already a file.\n";
-               continue 2;
-           }
-           if (is_dir($d)) {
-               continue 2;
-           }
-           if (!mkdir($d, 0755)) {
-               print "Error: could not mkdir $d\n";
-               continue 2;
-           }
-           if ($debug) print "[debug] created directory $d\n";
-           break;
-       case "DocFile":
-           if (!$pear_docdir) {
-               break;
-           }
-           $file = trim($data);
-           $d = "$pear_docdir/$destdir";
-           if (!copy("$pkgdir/$file", "$d/$file")) {
-               print "Error: failed to copy $pkgdir/$file to $d\n";
-               continue 2;
-           }
-           if ($debug) print "[debug] installed $d/$file\n";
-           break;
-    }
-}
-
-function cleanup() {
-    global $tmpdir;
-    if ($tmpdir && is_dir($tmpdir)) {
-       system("rm -rf $tmpdir");
-    }
-    $tmpdir = null;
-}
 
 ?>