Add Horde_Config::getVersion()
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 14 Jul 2009 19:11:58 +0000 (13:11 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 14 Jul 2009 19:16:26 +0000 (13:16 -0600)
framework/Core/lib/Horde/Config.php

index 2961fc8..f1a0890 100644 (file)
@@ -128,17 +128,13 @@ class Horde_Config
         include_once 'Horde/DOM.php';
         $doc = Horde_DOM_Document::factory(array('filename' => $path . '/conf.xml'));
 
-        /* Check if there is a CVS version tag and store it. */
+        /* Check if there is a CVS/Git version tag and store it. */
         $node = $doc->first_child();
         while (!empty($node)) {
-            if ($node->type == XML_COMMENT_NODE) {
-                // @TODO: Old CVS tag
-                if (preg_match('/\$.*?conf\.xml,v .*? .*\$/', $node->node_value(), $match) ||
-                // New Git tag
-                    preg_match('/\$Id:\s*[0-9a-f]+\s*\$/', $node->node_value(), $match)) {
-                    $this->_versionTag = $match[0] . "\n";
-                    break;
-                }
+            if (($node->type == XML_COMMENT_NODE) &&
+                ($vers_tag = $this->getVersion($node->node_value()))) {
+                $this->_versionTag = $vers_tag . "\n";
+                break;
             }
             $node = $node->next_sibling();
         }
@@ -154,6 +150,25 @@ class Horde_Config
     }
 
     /**
+     * Get the Horde version string for a config file.
+     *
+     * @param string $text  The text to parse.
+     *
+     * @return string  The version string or false if not found.
+     */
+    static public function getVersion($text)
+    {
+        // @TODO: Old CVS tag
+        if (preg_match('/\$.*?conf\.xml,v .*? .*\$/', $text, $match) ||
+            // New Git tag
+            preg_match('/\$Id:\s*[0-9a-f]+\s*\$/', $text, $match)) {
+            return $match[0];
+        }
+
+        return false;
+    }
+
+    /**
      * Returns the file content of the current configuration file.
      *
      * @return string  The unparsed configuration file content.