Committing the first phase of the phpDocBuilder.
authorEdward Mann <phpeclipse.dev@edmann.com>
Wed, 5 Sep 2007 01:35:54 +0000 (01:35 +0000)
committerEdward Mann <phpeclipse.dev@edmann.com>
Wed, 5 Sep 2007 01:35:54 +0000 (01:35 +0000)
utilities/.cvsignore [new file with mode: 0644]
utilities/phpdocbuilder/DocBuilder.phpc [new file with mode: 0644]
utilities/phpdocbuilder/builder.php [new file with mode: 0644]

diff --git a/utilities/.cvsignore b/utilities/.cvsignore
new file mode 100644 (file)
index 0000000..3a4edf6
--- /dev/null
@@ -0,0 +1 @@
+.project
diff --git a/utilities/phpdocbuilder/DocBuilder.phpc b/utilities/phpdocbuilder/DocBuilder.phpc
new file mode 100644 (file)
index 0000000..7f148b0
--- /dev/null
@@ -0,0 +1,226 @@
+<?php
+/**
+ * Created on Jul 9, 2007
+ *
+ * To change the template for this generated file go to
+ * Window - Preferences - PHPeclipse - PHP - Code Templates
+ */
+
+/**
+ * Doc Builder
+ * 
+ * Class will parse and build a custom master xml document from the phpdoc docbook xml
+ * files.
+ * @author ed_mann
+ * @copyright Copyright &copy; 2007, emann
+ * @license http://pleaseaddme.com some license that the dev team likes.
+ */
+final class Docbuilder {
+
+       /**
+         * out_dom
+         *
+         * @var object XML Document Dom Object
+         * @access private
+         */
+       private $out_dom;
+
+       /**
+        * out_file
+        * @access private
+        * @param string
+        */
+       private $out_file = NULL;
+
+       /**
+        * ref_path
+        * @access private
+        * @param string Path the the phpdoc reference directory 
+        * this shoud be in "phpdoc/en/reference/"
+        */
+       private $ref_path = NULL;
+
+       /**
+        * ref files
+        * @access private
+        * @param array our associtive array of ref directories and each file under it
+        */
+       private $ref_files = NULL;
+    
+    /**
+     * version_dom
+     * @access private
+     * @param object DomDocument object
+     */
+     private $version_dom = NULL;
+     
+     /**
+      * version_xpath
+      * @access private
+      * @param object DomXPath object
+      */
+      private $version_xpath = NULL;
+      
+     /**
+      * manual_dom
+      * @access private
+      * @param object DomDocument object
+      */
+      private $manual_dom = NULL;
+    
+       /**
+        * constructor
+        * Constructor will create our out_dom object, load the manual dom object and the function
+     * dom object.
+        * @access public
+        * @param string $out_file output file name
+     * @param string $ref_path Path to phpdoc directory
+        * @return boolean true if succeded in loading files false otherwise
+        */
+       public function __construct($out_file, $ref_path) {
+               $this->out_dom = new DOMDocument("1.0");
+        
+               $this->out_file = $out_file;
+               $this->ref_path = $ref_path;
+               if(!$this->loadManualDom()){
+                       return false;
+               }
+               if(!$this->loadVersionDom()){
+                       return false;
+               }
+        return true;
+       }
+    
+    /**
+     * loadManualDom
+     * Function will instantiate the manual dom object
+     * @access private
+     * @param void
+     * @return boolean true if successful False if cannot load
+     */
+     private function loadManualDom(){
+        try {
+            $this->manual_dom = new DomDocument();
+           $this->manual_dom->validateOnParse = true;
+            $this->manual_dom->substituteEntities = true;
+            $this->manual_dom->resolveExternals = true;
+            $this->manual_dom->preserveWhiteSpace = false;
+            if(!$this->manual_dom->Load($this->ref_path."/.manual.xml")){
+                  throw new Exception('Could not load the .manual.xml file');
+            }
+       } catch (Exception $e){
+               print($e->__toString());
+            return false;
+        }
+        $this->manual_dom_xpath = new DomXPath($this->manual_dom);
+        return true;
+     }
+     
+    /**
+     * loadVersionDom
+     * Function will instantiate the version dom object. Also we will create the xpath
+     * object that we will use to get our version info.
+     * @access private
+     * @param void
+     * @return boolean true if successful False if cannot load
+     */
+     private function loadVersionDom(){
+        try {
+        $this->version_dom = new DomDocument();
+        $this->version_dom->validateOnParse = true;
+        $this->version_dom->preserveWhiteSpace = false;
+        if(!$this->version_dom->Load($this->ref_path."/phpbook/phpbook-xsl/version.xml")){
+            throw new Exception('Could not load the version.xml file');
+        }
+        } catch (Exception $e){
+            print($e->__toString());
+            return false;
+        }
+        $this->version_xpath = new DomXPath($this->version_dom);
+        return true;
+     }
+    
+    /**
+     * buildDoc
+     * 
+     * Build our output document
+     * @access public
+     * @param void
+     * @return boolean true if successful false if not
+     */
+     public function buildDoc(){
+        $entries = $this->manual_dom->getElementsByTagName('refentry');
+        
+  foreach($entries as $entry){
+        /*
+         * note: you use the xpath to get the different roles. You need to loop the roles
+         * to get good output. Each role should be it's own function. It is left here
+         * because i am going home, and don't have time to finish this right now.
+         */
+        $query = "*[@role = 'changelog']";
+        $info = $this->manual_dom_xpath->query($query, $entry);
+        
+        print($info->item(0)->getElementsByTagName('entry')->item(3)->nodeValue); die;
+        // end of xpath stuff.
+    $ref_name = $entry->getElementsByTagName('refname')->item(0)->nodeValue;
+    $ref_purp = $entry->getElementsByTagName('refpurpose')->item(0)->nodeValue;
+    $type = $entry->getElementsByTagName('type')->item(0)->nodeValue;
+    $synopsis = $this->buildSynopsis($entry);
+    if($entry->getElementsByTagName('para')->item(0)){
+       print ("yes"); die;
+    }
+    die;
+    $desc = 
+    $version = $this->getVersionInfo($ref_name);
+    print($ref_name."  ".$ref_purp." ".$type ." ". $synopsis. "\n"); die;
+  }
+  die;
+     }
+     
+    /**
+     * build Synopsis
+     * Function will build the php function synopsis
+     * @access private
+     * @param string $entry xml entry to parse
+     * @return string $synopsis Synopsis output string
+     */
+     private function buildSynopsis($entry){
+        $meth = $entry->getElementsByTagName('methodsynopsis')->item(0);
+        $output = $entry->getElementsByTagName('type')->item(0)->nodeValue;
+        $output .= "<strong>".$entry->getElementsByTagName('methodname')->item(0)->nodeValue."</strong>";
+        $output .= ("(");
+        $count = 0;
+        $end = "";
+        foreach ($meth->getElementsByTagName('methodparam') as $meth){
+            if($count == 1){
+               $output .= (" [, ");
+                $end .= "]";
+            }
+               $output .= ($meth->getElementsByTagName('type')->item(0)->nodeValue."  $".$meth->getElementsByTagName('parameter')->item(0)->nodeValue);
+            $count = 1;
+        }
+        $output .= ($end.")");
+        return $output;
+     }
+     
+    /**
+     * getVersionInfo
+     * Function will query the version xml file and find the version information for 
+     * function paramater. We are using xpath query to get our name of the function, then we
+     * can use the results to get the Node 'from' value. Calls explode to strip the string into
+     * an array.
+     * @access private
+     * @param string $function Function to search for
+     * @return array Function version info in array 
+     */
+     private function getVersionInfo($function){
+       $query = "/versions/function[@name = '$function']";
+        $info = $this->version_xpath->query($query);
+        if($info->length > 0){           
+               return explode(',', $this->version_xpath->query($query)->item(0)->getAttributeNode('from')->nodeValue);
+        } else {
+               return array('(No version information available, might be only in CVS)');
+        }
+     }
+}
+?>
\ No newline at end of file
diff --git a/utilities/phpdocbuilder/builder.php b/utilities/phpdocbuilder/builder.php
new file mode 100644 (file)
index 0000000..0fa8f2a
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/*
+ * Created on Jul 9, 2007
+ *
+ * To change the template for this generated file go to
+ * Window - Preferences - PHPeclipse - PHP - Code Templates
+ * @author ed_mann
+ */
+ /**
+  * required files
+  */
+  require_once ('DocBuilder.phpc');
+ /**
+  * File will call the xml build doc class to read the php Doc 
+  * xml files and build our master file. You can pass the following
+  * paramaters
+  * <ol>
+  * <li> output file name</li>
+  * </ol>
+  * @author ed_mann
+  */  
+  $out_file = $argv[1];
+  $ref_path = $argv[2];
+  $path = "/data/home/emann/sandbox/php/phpdoc/phpdoc/";
+  //$ver = "/data/home/emann/sandbox/php/phpdoc/phpdoc/phpbook/phpbook-xsl/version.xml";
+  
+  /**
+   * instantiate DocBuilder
+   */
+   $doc = new DocBuilder('out.xml', $path);
+   $doc->buildDoc();
+?>
\ No newline at end of file