From ac5c8643ede0e64dc3014576e908d6495bf7b5b4 Mon Sep 17 00:00:00 2001 From: Edward Mann Date: Wed, 5 Sep 2007 01:35:54 +0000 Subject: [PATCH] Committing the first phase of the phpDocBuilder. --- utilities/.cvsignore | 1 + utilities/phpdocbuilder/DocBuilder.phpc | 226 +++++++++++++++++++++++++++++++ utilities/phpdocbuilder/builder.php | 34 +++++ 3 files changed, 261 insertions(+), 0 deletions(-) create mode 100644 utilities/.cvsignore create mode 100644 utilities/phpdocbuilder/DocBuilder.phpc create mode 100644 utilities/phpdocbuilder/builder.php diff --git a/utilities/.cvsignore b/utilities/.cvsignore new file mode 100644 index 0000000..3a4edf6 --- /dev/null +++ b/utilities/.cvsignore @@ -0,0 +1 @@ +.project diff --git a/utilities/phpdocbuilder/DocBuilder.phpc b/utilities/phpdocbuilder/DocBuilder.phpc new file mode 100644 index 0000000..7f148b0 --- /dev/null +++ b/utilities/phpdocbuilder/DocBuilder.phpc @@ -0,0 +1,226 @@ +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 .= "".$entry->getElementsByTagName('methodname')->item(0)->nodeValue.""; + $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 index 0000000..0fa8f2a --- /dev/null +++ b/utilities/phpdocbuilder/builder.php @@ -0,0 +1,34 @@ + + *
  • output file name
  • + * + * @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 -- 1.7.1