3 * Created on Jul 9, 2007
5 * To change the template for this generated file go to
6 * Window - Preferences - PHPeclipse - PHP - Code Templates
12 * Class will parse and build a custom master xml document from the phpdoc docbook xml
15 * @copyright Copyright © 2007, emann
16 * @license http://pleaseaddme.com some license that the dev team likes.
18 final class Docbuilder {
23 * @var object XML Document Dom Object
33 private $out_file = NULL;
38 * @param string Path the the phpdoc reference directory
39 * this shoud be in "phpdoc/en/reference/"
41 private $ref_path = NULL;
46 * @param array our associtive array of ref directories and each file under it
48 private $ref_files = NULL;
53 * @param object DomDocument object
55 private $version_dom = NULL;
60 * @param object DomXPath object
62 private $version_xpath = NULL;
67 * @param object DomDocument object
69 private $manual_dom = NULL;
73 * Constructor will create our out_dom object, load the manual dom object and the function
76 * @param string $out_file output file name
77 * @param string $ref_path Path to phpdoc directory
78 * @return boolean true if succeded in loading files false otherwise
80 public function __construct($out_file, $ref_path) {
81 $this->out_dom = new DOMDocument("1.0");
83 $this->out_file = $out_file;
84 $this->ref_path = $ref_path;
85 if(!$this->loadManualDom()){
88 if(!$this->loadVersionDom()){
96 * Function will instantiate the manual dom object
99 * @return boolean true if successful False if cannot load
101 private function loadManualDom(){
103 $this->manual_dom = new DomDocument();
104 $this->manual_dom->validateOnParse = true;
105 $this->manual_dom->substituteEntities = true;
106 $this->manual_dom->resolveExternals = true;
107 $this->manual_dom->preserveWhiteSpace = false;
108 if(!$this->manual_dom->Load($this->ref_path."/.manual.xml")){
109 throw new Exception('Could not load the .manual.xml file');
111 } catch (Exception $e){
112 print($e->__toString());
115 $this->manual_dom_xpath = new DomXPath($this->manual_dom);
121 * Function will instantiate the version dom object. Also we will create the xpath
122 * object that we will use to get our version info.
125 * @return boolean true if successful False if cannot load
127 private function loadVersionDom(){
129 $this->version_dom = new DomDocument();
130 $this->version_dom->validateOnParse = true;
131 $this->version_dom->preserveWhiteSpace = false;
132 if(!$this->version_dom->Load($this->ref_path."/phpbook/phpbook-xsl/version.xml")){
133 throw new Exception('Could not load the version.xml file');
135 } catch (Exception $e){
136 print($e->__toString());
139 $this->version_xpath = new DomXPath($this->version_dom);
146 * Build our output document
149 * @return boolean true if successful false if not
151 public function buildDoc(){
152 $entries = $this->manual_dom->getElementsByTagName('refentry');
154 foreach($entries as $entry){
156 * note: you use the xpath to get the different roles. You need to loop the roles
157 * to get good output. Each role should be it's own function. It is left here
158 * because i am going home, and don't have time to finish this right now.
160 $query = "*[@role = 'changelog']";
161 $info = $this->manual_dom_xpath->query($query, $entry);
163 print($info->item(0)->getElementsByTagName('entry')->item(3)->nodeValue); die;
164 // end of xpath stuff.
165 $ref_name = $entry->getElementsByTagName('refname')->item(0)->nodeValue;
166 $ref_purp = $entry->getElementsByTagName('refpurpose')->item(0)->nodeValue;
167 $type = $entry->getElementsByTagName('type')->item(0)->nodeValue;
168 $synopsis = $this->buildSynopsis($entry);
169 if($entry->getElementsByTagName('para')->item(0)){
174 $version = $this->getVersionInfo($ref_name);
175 print($ref_name." ".$ref_purp." ".$type ." ". $synopsis. "\n"); die;
182 * Function will build the php function synopsis
184 * @param string $entry xml entry to parse
185 * @return string $synopsis Synopsis output string
187 private function buildSynopsis($entry){
188 $meth = $entry->getElementsByTagName('methodsynopsis')->item(0);
189 $output = $entry->getElementsByTagName('type')->item(0)->nodeValue;
190 $output .= "<strong>".$entry->getElementsByTagName('methodname')->item(0)->nodeValue."</strong>";
194 foreach ($meth->getElementsByTagName('methodparam') as $meth){
199 $output .= ($meth->getElementsByTagName('type')->item(0)->nodeValue." $".$meth->getElementsByTagName('parameter')->item(0)->nodeValue);
202 $output .= ($end.")");
208 * Function will query the version xml file and find the version information for
209 * function paramater. We are using xpath query to get our name of the function, then we
210 * can use the results to get the Node 'from' value. Calls explode to strip the string into
213 * @param string $function Function to search for
214 * @return array Function version info in array
216 private function getVersionInfo($function){
217 $query = "/versions/function[@name = '$function']";
218 $info = $this->version_xpath->query($query);
219 if($info->length > 0){
220 return explode(',', $this->version_xpath->query($query)->item(0)->getAttributeNode('from')->nodeValue);
222 return array('(No version information available, might be only in CVS)');