home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Web Server / PHP.EXE / pear / PHPDoc / xmlexporter / PhpdocXMLDocumentExporter.php < prev    next >
Encoding:
PHP Script  |  2001-02-18  |  14.2 KB  |  420 lines

  1. <?php
  2. /**
  3. * Base of the class and module exporter.
  4. * @version $Id: PhpdocXMLDocumentExporter.php,v 1.3 2001/02/18 16:53:00 uw Exp $
  5. */
  6. class PhpdocXMLDocumentExporter extends PhpdocXMLExporter {
  7.     
  8.     /**
  9.     * Mapping from internal result array index name to xml tag name.
  10.     *
  11.     * @var  array   $docTags
  12.     */
  13.     var $docTags = array(
  14.                             "desc"      => "description",
  15.                             "sdesc"     => "shortdescription",
  16.                             
  17.                             "version"   => "version",
  18.                             "since"     => "since",
  19.                             "version"   => "version",
  20.                             "deprec"    => "deprecated",
  21.                             "copyright" => "copyright",
  22.                             "exclude"   => "exclude",
  23.                             "brother"   => "brother",
  24.                             "magic"     => "magic"
  25.                         );
  26.  
  27.     /**
  28.     * Attributes of the <see> container.
  29.     *
  30.     * @var  array
  31.     */                                            
  32.     var $seeAttributes = array(
  33.                                 "type"  => "CDATA",
  34.                                 "group" => "CDATA"
  35.                             );
  36.     
  37.     /**
  38.     * Attributes of the <link> container.
  39.     *
  40.     * @var  array
  41.     */
  42.     var $linkAttributes = array( "url"    => "CDATA" );
  43.  
  44.     /**
  45.     * Attributes of the <author> container.
  46.     *
  47.     * @var  array
  48.     */                                                        
  49.     var $authorAttributes = array( "email"    => "CDATA" );
  50.                                                             
  51.     /**
  52.     * Attributes of <inherited> and <overriden> container.
  53.     *
  54.     * @var  array
  55.     */                                                            
  56.     var $inheritedOverridenAttributes = array(
  57.                                                 "src"   => "CDATA",
  58.                                                 "type"  => "CDATA"
  59.                                          );                                    
  60.  
  61.     /**
  62.     * Attributes of the <constant> container.
  63.     *
  64.     * @var  array
  65.     */                                                                                
  66.     var $constAttributes = array(
  67.                                     "name"      => "CDATA",
  68.                                     "undoc"     => "Boolean",
  69.                                     "access"    => "CDATA",
  70.                                     "case"      => "CDATA"
  71.                                 );
  72.  
  73.     /**
  74.     * Attribues of the <uses> container.
  75.     *
  76.     * @var  array
  77.     */                                                            
  78.     var $usesAttributes = array(
  79.                                 "type"  => "CDATA",
  80.                                 "file"  => "CDATA",
  81.                                 "undoc" => "Boolean"
  82.                         );
  83.                                                     
  84.     /**
  85.     * Attribues of the <function> container.
  86.     *
  87.     * @var  array
  88.     */                                                        
  89.     var $functionAttributes = array(
  90.                                     "name"      => "CDATA",
  91.                                     "undoc"     => "Boolean",
  92.                                     "access"    => "CDATA",
  93.                                     "abstract"  => "Boolean",
  94.                                     "static"    => "CDATA"
  95.                                 );
  96.  
  97.     /**
  98.     * Attributes of the <return> container.
  99.     *
  100.     * @var  array
  101.     */                                                                
  102.     var $returnAttributes = array( 
  103.                                     "name"  => "CDATA",
  104.                                     "type"  => "CDATA"
  105.                                 );            
  106.  
  107.     /**
  108.     * Attributes of the <global> container.
  109.     *
  110.     * @var  array
  111.     */                                                            
  112.     var $globalAttributes = array(
  113.                                     "name"  => "CDATA",
  114.                                     "type"  => "CDATA"
  115.                                 );            
  116.  
  117.     /**
  118.     * Attributes of the <param> container.
  119.     *
  120.     * @var  array
  121.     */                                                            
  122.     var $paramAttributes    = array(
  123.                                     "name"      => "CDATA",
  124.                                     "default"   => "CDATA",
  125.                                     "type"      => "CDATA",
  126.                                     "undoc"     => "Boolean"
  127.                                 );    
  128.     
  129.     /**
  130.     * Writes a <file> container.
  131.     *
  132.     * @param    string  $file   Filename
  133.     */
  134.     function filenameXML($file) {
  135.         $this->xmlwriter->addElement("file", $file);
  136.     } // end func filenameXML
  137.     
  138.     /**
  139.     * Adds all constants (define(), const) to the xml document.
  140.     *
  141.     * @param    array   Array of constants
  142.     * @return   boolean Returns false on failure otherwise true
  143.     */
  144.     function constsXML($consts) {
  145.         if (!is_array($consts) || 0 == count($consts)) 
  146.             return true;
  147.     
  148.         reset($consts);
  149.         while (list($k, $data)=each($consts)) {
  150.         
  151.             $attribs = $this->getAttributes($data, $this->constAttributes);
  152.             $this->xmlwriter->startElement("constant", (isset($data["value"])) ? $data["value"] : "", $attribs, false, true);
  153.             $this->docXML($data);
  154.             $this->xmlwriter->endElement("constant", true);
  155.             
  156.         }
  157.         
  158.         return true;
  159.     } // end func constsXML
  160.     
  161.     /**
  162.     * Adds a list of used files (include, require...) to the xml document.
  163.     * 
  164.     * @param    array
  165.     */
  166.     function usesXML($uses) {
  167.         if (!is_array($uses)) {
  168.             $this->err[] = new PhpdocError("No array given.", __FILE__, __LINE__);
  169.             return false;
  170.         }
  171.     
  172.         reset($uses);
  173.         while (list($k, $data) = each($uses)) {
  174.         
  175.             $attribs = $this->getAttributes($data, $this->usesAttributes);
  176.             $this->xmlwriter->startElement("uses", "", $attribs, false, true);
  177.             $this->docXML($data);    
  178.             $this->xmlwriter->endElement("uses", true);
  179.             
  180.         }
  181.         
  182.         return true;
  183.     } // end func usesXML
  184.     
  185.     /**
  186.     * Adds a list of functions to the xml file.
  187.     * 
  188.     * @param    array
  189.     */
  190.     function functionsXML($functions) {
  191.         if (!is_array($functions)) {
  192.             $this->err[] = new PhpdocError("No array given.", __FILE__, __LINE__);
  193.             return false;
  194.         }
  195.  
  196.         reset($functions);
  197.         while (list($k, $data) = each($functions)) {
  198.         
  199.             $attribs = $this->getAttributes($data, $this->functionAttributes);                    
  200.             $this->xmlwriter->startElement("function", "", $attribs, false, true);
  201.             $this->docXML($data);        
  202.             $this->xmlwriter->endElement("function", true);
  203.             
  204.         }
  205.                                                             
  206.     } // end functionsXML
  207.     
  208.     /**
  209.     * Adds a documentation block (author, links, see, params...) to the xml document
  210.     * 
  211.     * @param    sarray
  212.     */
  213.     function docXML($data) {
  214.         
  215.         $this->xmlwriter->startElement("doc", "", "", false, true);
  216.         
  217.         if (isset($data["link"]))
  218.             $this->linkXML($data["link"]);        
  219.         
  220.         if (isset($data["author"]))
  221.             $this->authorXML($data["author"]);
  222.             
  223.         if (isset($data["see"]))
  224.             $this->seeXML($data["see"]);
  225.             
  226.         if (isset($data["params"]))
  227.             $this->paramsXML($data["params"]);
  228.             
  229.         if (isset($data["return"]))
  230.             $this->returnXML($data["return"]);
  231.             
  232.         if (isset($data["throws"])) 
  233.             $this->throwsXML($data["throws"]);
  234.         
  235.         if (isset($data["global"]))
  236.             $this->globalsXML($data["global"]);
  237.  
  238.         if (isset($data["inherited"])) {
  239.             
  240.             
  241.             $attribs = array(
  242.                                 "src"    => array(
  243.                                                     "type"  => $this->inheritedOverridenAttributes["src"],
  244.                                                     "value" => $data["inherited"]
  245.                                                 )
  246.                                             );
  247.             $this->xmlwriter->addElement("inherited", "", $attribs);
  248.         }
  249.         
  250.         if (isset($data["overrides"])) {
  251.             $attribs = array( 
  252.                             "src"    => array(
  253.                                                 "type"    => $this->inheritedOverridenAttributes["src"],
  254.                                                 "value"    => $data["overrides"]
  255.                                             )
  256.                             );
  257.             $this->xmlwriter->addElement("overriden", "", $attribs);                                            
  258.         }
  259.             
  260.         reset($this->docTags);
  261.         while (list($field, $tag) = each($this->docTags))
  262.             if (isset($data[$field]))
  263.                 $this->xmlwriter->addElement($tag, $data[$field], "");
  264.             
  265.         $this->xmlwriter->endElement("doc", true);
  266.     } // end func docXML
  267.  
  268.     /**
  269.     * Adds <global> container to the xml document.
  270.     * 
  271.     * @param    array
  272.     */
  273.     function globalsXML($globals) {
  274.     
  275.         reset($globals);
  276.         while (list($k, $data) = each($globals)) {
  277.             $attribs = $this->getAttributes($data, $this->globalAttributes);
  278.             $this->xmlwriter->addElement("global", (isset($data["desc"])) ? $data["desc"] : "", $attribs);
  279.         }
  280.         
  281.     } // end func globalsXML
  282.     
  283.     /**
  284.     * Adds <throws> container to the xml document.
  285.     * 
  286.     * @param    array
  287.     */
  288.     function throwsXML($exceptions) {
  289.         
  290.         reset($exceptions);
  291.         while (list($k, $exception) = each($exceptions)) 
  292.             $this->xmlwriter->addElement("throws", $exception, "", true);
  293.         
  294.     } // end func throwsXML
  295.     
  296.     /**
  297.     * Adds <return> container to the xml document.
  298.     * 
  299.     * @param    array
  300.     */
  301.     function returnXML($return) {
  302.  
  303.         $desc = "";    
  304.         
  305.         if (is_array($return)) {
  306.         
  307.             if (isset($return["desc"])) {
  308.                 $desc = $return["desc"];
  309.                 unset($return["desc"]);
  310.             }
  311.             $attribs = $this->getAttributes($return, $this->returnAttributes);
  312.             
  313.         } else {
  314.         
  315.             $attribs["type"] = array( "type"    => "CDATA", "value"    => $return );
  316.             
  317.         }
  318.         
  319.         $this->xmlwriter->addElement("return", $desc, $attribs);
  320.         
  321.     } // end func returnXML    
  322.     
  323.     /**
  324.     * Adds <parameter> container to the xml document.
  325.     * 
  326.     * @param    array
  327.     */
  328.     function paramsXML($params) {
  329.     
  330.         reset($params);
  331.         while (list($k, $data) = each($params)) {
  332.             $attribs = $this->getAttributes($data, $this->paramAttributes);
  333.             $this->xmlwriter->addElement("parameter", (isset($data["desc"])) ? $data["desc"] : "", $attribs);
  334.         }
  335.  
  336.     } // end func paramsXML
  337.     
  338.     /**
  339.     * Adds <author> container to the xml document.
  340.     *
  341.     * @param    array
  342.     */
  343.     function authorXML($authors) {
  344.         
  345.         reset($authors);
  346.         while (list($k, $data) = each($authors)) {
  347.             
  348.             $attribs = array();
  349.             
  350.             if (isset($data["mail"]))
  351.                 $attribs = array(
  352.                                     "email"    => array(
  353.                                                         "type"  => $this->authorAttributes["email"],
  354.                                                         "value" => $data["mail"]
  355.                                                     )
  356.                                 );
  357.             $this->xmlwriter->addElement("author",$data["name"], $attribs);
  358.                                                                             
  359.         }
  360.             
  361.     } // end func authorXML
  362.     
  363.     /**
  364.     * Adds <link> container to the xml document.
  365.     *
  366.     * @param    array
  367.     */
  368.     function linkXML($links) {
  369.         
  370.         reset($links);
  371.         while (list($k, $data) = each($links)) {
  372.         
  373.             $attribs = array(
  374.                                 "url"    => array(
  375.                                                     "type"  => $this->linkAttributes["url"],
  376.                                                     "value" => $data["url"]
  377.                                                 )
  378.                             );
  379.             $this->xmlwriter->addElement("link",  (isset($data["desc"])) ? $data["desc"] : "", $attribs);                                                
  380.             
  381.         }
  382.         
  383.     } // end func linkXML
  384.     
  385.     /**
  386.     * Adds <see> container to the xml document.
  387.     * 
  388.     * @param    array
  389.     */
  390.     function seeXML($see) {
  391.         
  392.         reset($see);
  393.         while (list($type, $data) = each($see)) {
  394.             
  395.             reset($data);
  396.             while (list($k, $data2) = each($data)) {
  397.             
  398.                 $attribs = array(
  399.                                 "type"    => array(
  400.                                                     "type"  => $this->seeAttributes["type"],
  401.                                                     "value" => strtolower($type)
  402.                                                 )
  403.                             );
  404.                 if (isset($data2["group"]))
  405.                     $attribs["group"] = array(
  406.                                                 "type"  => $this->seeAttributes["group"],
  407.                                                 "value" => $data2["group"]
  408.                                             );
  409.                                                                     
  410.                 $this->xmlwriter->addElement("see", $data2["name"], $attribs);
  411.                 
  412.             }
  413.                                                         
  414.         }
  415.         
  416.     } // end func SeeXML
  417.  
  418. } // end class PhpdocXMLDocumentExporter
  419. ?>