]> granicus.if.org Git - php/commitdiff
extend infoFromDescriptionFile() to:
authorTomas V.V.Cox <cox@php.net>
Mon, 16 Jul 2001 18:01:09 +0000 (18:01 +0000)
committerTomas V.V.Cox <cox@php.net>
Mon, 16 Jul 2001 18:01:09 +0000 (18:01 +0000)
- Handle the new FileList->Dir tag format (see
http://marc.theaimsgroup.com/?l=pear-dev&m=99071271521558&w=2)
- Attributes of Files can inherit from Dir
- Support for the experimental LibFile/LibName/Sources tags

other indents and fixes

pear/PEAR/Common.php

index 6b3bf3dc5a6e0b2400e26dfaa78032bf2f7f432b..bc50e3523c1a98f9678c068f5c45fb24cee3b65b 100644 (file)
@@ -25,7 +25,7 @@ class PEAR_Common extends PEAR
     // {{{ properties
 
     /** stack of elements, gives some sort of XML context */
-    var $element_stack;
+    var $element_stack = array();
 
     /** name of currently parsed XML element */
     var $current_element;
@@ -51,8 +51,9 @@ class PEAR_Common extends PEAR
     // }}}
     // {{{ destructor
 
-    function _PEAR_Common() {
-       $this->_PEAR();
+    function _PEAR_Common()
+    {
+        $this->_PEAR();
         while (is_array($this->_tempfiles) &&
                $file = array_shift($this->_tempfiles))
         {
@@ -77,9 +78,29 @@ class PEAR_Common extends PEAR
 
     function _element_start($xp, $name, $attribs)
     {
-       array_push($this->element_stack, $name);
-       $this->current_element = $name;
-       $this->current_attributes = $attribs;
+        array_push($this->element_stack, $name);
+        $this->current_element = $name;
+        $this->current_attributes = $attribs;
+        switch ($name) {
+            case 'Dir':
+                if (isset($this->dir_names)) {
+                    $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'];
+                }
+                if (isset($attribs['Role'])) {
+                    $this->dir_role = $attribs['Role'];
+                }
+                break;
+            case 'LibFile':
+                $this->lib_atts = $attribs;
+                $this->lib_atts['Role'] = 'extension';
+                break;
+        }
     }
 
     // }}}
@@ -87,8 +108,52 @@ class PEAR_Common extends PEAR
 
     function _element_end($xp, $name)
     {
-       array_pop($this->element_stack);
-       $this->current_element = $this->element_stack[sizeof($this->element_stack)-1];
+        switch ($name) {
+            case 'Dir':
+                array_pop($this->dir_names);
+                unset($this->dir_install);
+                unset($this->dir_role);
+                break;
+            case 'File':
+                $path = '';
+                foreach ($this->dir_names as $dir) {
+                    $path .= $dir . DIRECTORY_SEPARATOR;
+                }
+                $path .= $this->current_file;
+                $this->filelist[$path] = $this->current_attributes;
+                // Set the baseinstalldir only if the file don't have this attrib
+                if (!isset($this->filelist[$path]['BaseInstallDir']) &&
+                    isset($this->dir_install))
+                {
+                    $this->filelist[$path]['BaseInstallDir'] = $this->dir_install;
+                }
+                // Set the Role
+                if (!isset($this->filelist[$path]['Role']) && isset($this->dir_role)) {
+                    $this->filelist[$path]['Role'] = $this->dir_role;
+                }
+                break;
+            case 'LibFile':
+                $path = '';
+                foreach ($this->dir_names as $dir) {
+                    $path .= $dir . DIRECTORY_SEPARATOR;
+                }
+                $path .= $this->lib_name;
+                $this->filelist[$path] = $this->lib_atts;
+                // Set the baseinstalldir only if the file don't have this attrib
+                if (!isset($this->filelist[$path]['BaseInstallDir']) &&
+                    isset($this->dir_install))
+                {
+                    $this->filelist[$path]['BaseInstallDir'] = $this->dir_install;
+                }
+                if (isset($this->lib_sources)) {
+                    $this->filelist[$path]['sources'] = $this->lib_sources;
+                }
+                unset($this->lib_atts);
+                unset($this->lib_sources);
+                break;
+        }
+        array_pop($this->element_stack);
+        $this->current_element = $this->element_stack[sizeof($this->element_stack)-1];
     }
 
     // }}}
@@ -96,49 +161,54 @@ class PEAR_Common extends PEAR
 
     function _pkginfo_cdata($xp, $data)
     {
-        $next = $this->element_stack[sizeof($this->element_stack)-1];
-       switch ($this->current_element) {
-            case "Name":
-                switch ($next) {
-                    case "Package":
-                        $this->pkginfo["package"] .= $data;
+        $prev = $this->element_stack[sizeof($this->element_stack)-2];
+        switch ($this->current_element) {
+            case 'Name':
+                switch ($prev) {
+                    case 'Package':
+                        $this->pkginfo['package'] .= $data;
                         break;
-                    case "Maintainer":
-                        $this->pkginfo["maintainer_name"] .= $data;
+                    case 'Maintainer':
+                        $this->pkginfo['maintainer_name'] .= $data;
                         break;
                 }
                 break;
-            case "Summary":
-                $this->pkginfo["summary"] .= $data;
+            case 'Summary':
+                $this->pkginfo['summary'] .= $data;
                 break;
-            case "Initials":
-                $this->pkginfo["maintainer_handle"] .= $data;
+            case 'Initials':
+                $this->pkginfo['maintainer_handle'] .= $data;
                 break;
-            case "Email":
-                $this->pkginfo["maintainer_email"] .= $data;
+            case 'Email':
+                $this->pkginfo['maintainer_email'] .= $data;
                 break;
-            case "Version":
-                $this->pkginfo["version"] .= $data;
+            case 'Version':
+                $this->pkginfo['version'] .= $data;
                 break;
-            case "Date":
-                $this->pkginfo["release_date"] .= $data;
+            case 'Date':
+                $this->pkginfo['release_date'] .= $data;
                 break;
-            case "Notes":
-                $this->pkginfo["release_notes"] .= $data;
+            case 'Notes':
+                $this->pkginfo['release_notes'] .= $data;
                 break;
-           case "Dir":
-               if (!$this->phpdir) {
-                   break;
-               }
+            case 'Dir':
+                if (!$this->phpdir) {
+                    break;
+                }
                 $dir = trim($data);
                 // XXX add to file list
-               break;
-           case "File":
-                $role = strtolower($this->current_attributes["Role"]);
-               $file = trim($data);
-                // XXX add to file list
-               break;
-       }
+                break;
+            case 'File':
+                $role = strtolower($this->current_attributes['Role']);
+                $this->current_file = trim($data);
+                break;
+            case 'LibName':
+                $this->lib_name = trim($data);
+                break;
+            case 'Sources':
+                $this->lib_sources[] = trim($data);
+                break;
+        }
     }
 
     // }}}
@@ -146,42 +216,42 @@ class PEAR_Common extends PEAR
 
     function infoFromDescriptionFile($descfile)
     {
-       $fp = fopen($descfile, "r");
-       $xp = @xml_parser_create();
-       if (!$xp) {
-           return $this->raiseError("Unable to create XML parser.");
-       }
-       xml_set_object($xp, $this);
-       xml_set_element_handler($xp, "_element_start", "_element_end");
-       xml_set_character_data_handler($xp, "_pkginfo_cdata");
-       xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
-
-       $this->element_stack = array();
-       $this->pkginfo = array();
-       $this->current_element = false;
-       $this->destdir = '';
+        $fp = fopen($descfile, 'r');
+        $xp = @xml_parser_create();
+        if (!$xp) {
+            return $this->raiseError('Unable to create XML parser');
+        }
+        xml_set_object($xp, $this);
+        xml_set_element_handler($xp, '_element_start', '_element_end');
+        xml_set_character_data_handler($xp, '_pkginfo_cdata');
+        xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
+
+        $this->element_stack = array();
+        $this->pkginfo = array();
+        $this->current_element = false;
+        $this->destdir = '';
+        $this->filelist = array();
 
         // read the whole thing so we only get one cdata callback
         // for each block of cdata
-       $data = fread($fp, filesize($descfile));
+        $data = fread($fp, filesize($descfile));
         if (!@xml_parse($xp, $data, 1)) {
             $msg = 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);
             return $this->raiseError($msg);
-       }
+        }
 
-       xml_parser_free($xp);
+        xml_parser_free($xp);
 
         foreach ($this->pkginfo as $k => $v) {
             $this->pkginfo[$k] = trim($v);
         }
-
+        $this->pkginfo['filelist'] = &$this->filelist;
         return $this->pkginfo;
     }
 
     // }}}
 }
-
-?>
+?>
\ No newline at end of file