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

  1. <?php
  2. /**
  3. * Provides functions to access phpdoc xml documents that contain classes.
  4. *
  5. * @author     Ulf Wendel <ulf.wendel@phpdoc.de>
  6. * @version    $Id: PhpdocClassAccessor.php,v 1.2 2001/02/18 15:03:05 uw Exp $
  7. */
  8. class PhpdocClassAccessor extends PhpdocDocumentAccessor {
  9.  
  10.     /**
  11.     * TODO: add documentation
  12.     */
  13.     var $xmlkey = "class";
  14.     
  15.     /**
  16.     * Array of inherited elements
  17.     *
  18.     * @var    array    $inherited
  19.     */    
  20.     var $inherited = array();
  21.     
  22.     /**
  23.     * Returns an array with the data of a class (no functions etc, just the class docs).
  24.     *
  25.     * @return   array   $class
  26.     * @access   public
  27.     */
  28.     function getClassdata() {
  29.         
  30.         $class = $this->xml["class"];
  31.  
  32.         unset($class["variable"]);
  33.         unset($class["function"]);
  34.         unset($class["uses"]);
  35.         unset($class["constant"]);
  36.         unset($class["inherited"]);
  37.         unset($class["overriden"]);
  38.         unset($class["path"]);
  39.         
  40.         return $class;
  41.     } // end func getClassdata
  42.     
  43.     /**
  44.     * Returns an array of inherited functions.
  45.     *
  46.     * @return   array    
  47.     * @access   public
  48.     * @see      getInheritedVariables(), getInheritedUses(), getInheritedConstants()
  49.     */
  50.     function getInheritedFunctions() {
  51.         return $this->inherited["functions"];
  52.     } // end func getInheritedFunctions
  53.  
  54.     /**
  55.     * Returns an array of inherited variables.
  56.     *
  57.     * @return   array
  58.     * @access   public
  59.     * @see      getInheritedFunctions(), getInheritedUses(), getInheritedConstants()
  60.     */    
  61.     function getInheritedVariables() {
  62.         return $this->inherited["variables"];
  63.     } // end func getInheritedVariables
  64.     
  65.     /**
  66.     * Returns an array of inherited included files.
  67.     *
  68.     * @return   array
  69.     * @access   public
  70.     * @see      getInheritedFunctions(), getInheritedUses(), getInheritedConstants()
  71.     */
  72.     function getInheritedUses() {
  73.         return $this->inherited["uses"];
  74.     } // end func getInheritedUses()
  75.     
  76.     /**
  77.     * Returns an array of inherited constants.
  78.     *
  79.     * @return    array
  80.     * @access    public
  81.     * @see       getInheritedFunctions(), getInheritedVariables(), getInheritedUses()
  82.     */
  83.     function getInheritedConstants() {
  84.         return $this->inherited["constants"];
  85.     } // end func getInheritedConstants
  86.     
  87.     /**
  88.     * Returns an array with the "path" of a class.
  89.     *
  90.     * @return   array   $path
  91.     * @access   public
  92.     * @see      getSubclasses()
  93.     */    
  94.     function getClasstree() {
  95.         
  96.         if (isset($this->xml["class"]["path"]))
  97.             return $this->convertPath($this->xml["class"]["path"]);
  98.         else 
  99.             return array();
  100.             
  101.     } // end func getClasstree
  102.     
  103.     /**
  104.     * Returns an array with all subclasses of a class.
  105.     *
  106.     * @return   array
  107.     * @access   public
  108.     * @see      getClasstree()
  109.     */
  110.     function getSubclasses() {
  111.         return $this->data["subclasses"];
  112.     } // end func getSubclasses
  113.     
  114.  
  115.     /**
  116.     * Converts a xml path array to a path that can be passed to the user.
  117.     * 
  118.     * The path is an array like path[0..n] = classname where path[0] is the 
  119.     * directs parent (extends path[0]) and path[n] is the baseclass.
  120.     *
  121.     * @param    array   $xmlpath
  122.     * @return   array   $path
  123.     */
  124.     function convertPath($xmlpath) {
  125.  
  126.         $path = array();
  127.         
  128.         if (!isset($xmlpath["parent"][0])) {
  129.             
  130.             $path[0] = $xmlpath["parent"]["value"];        
  131.                 
  132.         } else {
  133.         
  134.             reset($xmlpath["parent"]);
  135.             while (list($k, $parent) = each($xmlpath["parent"]))
  136.                 $path[] = $parent["value"];
  137.                 
  138.         }
  139.  
  140.         return $path;
  141.     } // end func convertPath
  142.     
  143.     /**
  144.     * Builds a list of inherited elements.
  145.     *
  146.     * @see    $inherited
  147.     */
  148.     function buildInheritedlist() {
  149.         
  150.         $this->inherited = array(
  151.                                     "functions"    => array(),
  152.                                     "variables"    => array(),
  153.                                     "constants"    => array(),
  154.                                     "uses"         => array()
  155.                                 );
  156.     
  157.         if (isset($this->xml["class"]["inherited"])) {
  158.  
  159.             if (isset($this->xml["class"]["inherited"][0])) {
  160.             
  161.                 reset($this->xml["class"]["inherited"]);
  162.                 while (list($k, $inherited) = each($this->xml["class"]["inherited"])) {
  163.                         
  164.                     $type   = $inherited["type"];
  165.                     $src    = $inherited["src"];
  166.         
  167.                     if (isset($inherited["element"][0])) {
  168.                     
  169.                         reset($inherited["element"]);
  170.                         while (list($k2, $element) = each($inherited["element"])) 
  171.                             $this->inherited[$type][$src][] = $element["value"];
  172.                             
  173.                     }    else {
  174.                     
  175.                         $this->inherited[$type][$src][] = $inherited["element"]["value"];
  176.                         
  177.                     }
  178.                     
  179.                 }
  180.             
  181.             }    else {
  182.                 
  183.                 $inherited = $this->xml["class"]["inherited"];
  184.                 $type      = $inherited["type"];
  185.                 $src       = $inherited["src"];
  186.                 
  187.                 if (isset($inherited["element"][0])) {
  188.                     
  189.                     reset($inherited["element"]);
  190.                     while (list($k, $element) = each($inherited["element"])) 
  191.                         $this->inherited[$type][$src][] = $element["value"];
  192.                         
  193.                 } else {
  194.                 
  195.                     $this->inherited[$type][$src][] = $inherited["element"]["value"];
  196.                     
  197.                 }
  198.  
  199.             }
  200.             
  201.             unset($this->xml["class"]["inherited"]);
  202.             
  203.         }
  204.             
  205.     } // end func buildInheritedlist
  206.     
  207.     /**
  208.     * Builds a list of subclasses
  209.     */
  210.     function buildSubclasslist() {
  211.         
  212.         $this->data["subclasses"] = array();
  213.         
  214.         if (isset($this->xml["class"]["subclasses"])) {
  215.         
  216.             if (isset($this->xml["class"]["subclasses"]["subclass"][0])) {
  217.  
  218.                 reset($this->xml["class"]["subclasses"]["subclass"]);
  219.                 while (list($k, $subclass) = each($this->xml["class"]["subclasses"]["subclass"]))
  220.                     $this->data["subclasses"][] = $subclass["value"];
  221.  
  222.             } else {
  223.  
  224.                 $this->data["subclasses"][] = $this->xml["class"]["subclasses"]["subclass"]["value"];
  225.                 
  226.             }
  227.  
  228.         }
  229.         
  230.     } // end func buildSubclasslist
  231.     
  232.     function init() {
  233.  
  234.         $this->buildInheritedlist();
  235.         $this->buildSubclasslist();
  236.         
  237.         list($this->data["functions"], $this->data["functionsaccess"]) = $this->getElementlist("function");        
  238.         list($this->data["variables"], $this->data["variablesaccess"]) = $this->getElementlist("variable");
  239.         list($this->data["constants"], $this->data["constantsaccess"]) = $this->getElementlist("constant");
  240.         
  241.         $this->buildUseslist();        
  242.  
  243.     } // end func Init
  244.     
  245. } // end class PhpdocClassAccessor
  246. ?>