3 * Exporter used to export phpdoc internals data structures as xml documents.
\r
5 * @version $Id: PhpdocXMLExporter.php,v 1.2 2000/12/03 22:37:38 uw Exp $
\r
7 class PhpdocXMLExporter extends PhpdocObject {
\r
10 * Filename prefix for the generated xml document.
\r
12 * This class variable must be overriden by all derived classes.
\r
13 * PHPDoc uses the filename prefix to detect the content of
\r
16 * @var string $fileprefix
\r
18 var $fileprefix = "";
\r
21 * Target directory where the xml documents get saved.
\r
28 * Data to save as a xml document.
\r
29 * @var array $result
\r
30 * @see setResult(), export()
\r
32 var $result = array();
\r
35 * Instance of PhpdocXMLWriter used to generate the xml document.
\r
36 * @var object PhpdocXMLWriter
\r
37 * @see PhpdocXMLExporter()
\r
42 * Creates a PhpdocXMLWriter object.
\r
44 * Make sure that all derived classes call this constructor.
\r
48 function PhpdocXMLExporter() {
\r
50 $this->xmlwriter = new PhpdocXMLWriter;
\r
52 } // end constructor
\r
55 * Sets the target path for the generated xml documents.
\r
61 function setPath($path) {
\r
62 $this->path = $path;
\r
63 } // end func setPath
\r
66 * Exports the given result array as xml document.
\r
69 * @param string name of the target xml file
\r
71 * @see create(), $result
\r
73 function export($result, $xmlfile="") {
\r
75 if (0 == count($result))
\r
78 $this->result = $result;
\r
80 $this->xmlwriter->addXML('<?xml version="1.0"?>');
\r
81 $this->xmlwriter->startElement("phpdoc", "", "", false, true);
\r
85 $this->xmlwriter->endElement("phpdoc", true);
\r
88 $xmlfile = $this->result["name"];
\r
91 if (file_exists($this->path.$xmlfile)) {
\r
93 while (file_exists($this->path.$name."_".$i.".xml"))
\r
96 $xmlfile = $name."_".$i.".xml";
\r
100 $xmlfile = $this->nameToURL($xmlfile);
\r
101 $xmlfile = $this->path.$this->fileprefix.$xmlfile.".xml";
\r
103 $this->xmlwriter->export($xmlfile);
\r
104 $this->xmlwriter->free();
\r
106 } // end func export
\r
111 function setResult($result) {
\r
112 $this->result = $result;
\r
114 } // end func setResult
\r
117 * Kind of array_intersect for xml attributes.
\r
119 * This functions takes a data array and a list of allowed fields in the data
\r
120 * array. All of the allowed fields that exists in the data array will be
\r
121 * copied to returned array which looks like:
\r
122 * $attribs[name] = array ( type => allowed[name], value => data[name] ).
\r
123 * This structure is used by PhpdocXMLWriter->addElement().
\r
125 * @param array data array
\r
126 * @param array array of allowed fields and their attribute type
\r
127 * @return array $attribs
\r
129 function getAttributes($data, $allowed) {
\r
131 $attribs = array();
\r
134 while (list($tag, $type)=each($allowed))
\r
135 if (isset($data[$tag]))
\r
136 $attribs[$tag] = array( "type" => $type, "value" => $data[$tag] );
\r
139 } // end func getAttributes
\r
141 } // end PhpdocXMLExporter
\r