home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 August / PCWorld_2001-08_cd.bin / Komunikace / phptriad / phptriadsetup2-11.exe / php / pear / PHPDoc / parser / PhpdocClassParser.php next >
PHP Script  |  2001-02-18  |  4KB  |  128 lines

  1. <?php
  2. /**
  3. * Parses phpcode to extract classes and their documentation.
  4. *
  5. * @version    $Id: PhpdocClassParser.php,v 1.3 2001/02/18 14:45:27 uw Exp $
  6. */
  7. class PhpdocClassParser extends PhpdocFunctionParser {
  8.  
  9.     /**
  10.     * Array of all classes in the given code
  11.     * 
  12.     * The array is indexed by the classname.
  13.     * See $emptyClass to see the internal structure.
  14.     * 
  15.     * @var    array $classes
  16.     * @see    $emptyClass
  17.     */ 
  18.     var $classes = array();
  19.     
  20.     /**
  21.     * Default values of a class
  22.     *
  23.     * @var    array    $emptyClass
  24.     */
  25.     var $emptyClass = array (
  26.                                "name"       => "",
  27.                                "extends"    => "",
  28.                                "undoc"        => true
  29.                         );
  30.     
  31.     /**
  32.     * Array of tags that are allowed in front of the class keyword
  33.     *
  34.     * @var    array    $classTags
  35.     * @see    analyseClassParagraph()
  36.     */
  37.     var $classTags = array(
  38.                             "access"        => true,
  39.                             "abstract"      => true,
  40.                             "static"        => true,
  41.                             "final"         => true,
  42.                             
  43.                             "see"           => true,
  44.                             "link"          => true,
  45.                             
  46.                             "author"        => true,
  47.                             "copyright"     => true,
  48.                             
  49.                             "version"       => true,
  50.                             "since"         => true,
  51.                             
  52.                             "deprecated"    => true,
  53.                             "deprec"        => true,
  54.                             
  55.                             "brother"       => true,
  56.                             "sister"        => true,
  57.                             
  58.                             "exclude"       => true,
  59.                             
  60.                             "package"       => true,
  61.                             
  62.                             "magic"         => true,
  63.                             "todo"          => true
  64.                          );
  65.     
  66.     /**
  67.     * Analyse a class
  68.     * 
  69.     * Calls all neccessary analyse functions.
  70.     * 
  71.     * @param    array
  72.     * @return    array
  73.     */
  74.     function analyseClass($para) {
  75.  
  76.         $class = $this->analyseClassDoc($para["classes"][0]);
  77.         
  78.         reset($para["functions"]);
  79.         while (list($k, $data)=each($para["functions"]))
  80.             $class["functions"][strtolower($data["name"])] = $this->analyseFunction($data);
  81.         unset($para["functions"]);
  82.             
  83.         reset($para["variables"]);
  84.         while (list($k, $data)=each($para["variables"]))
  85.             $class["variables"][strtolower($data["name"])] = $this->analyseVariable($data);
  86.         unset($para["variables"]);
  87.  
  88.         reset($para["consts"]);
  89.         while (list($k, $data)=each($para["consts"]))
  90.             $class["consts"][strtolower($data["name"])] = $this->analyseConstant($data);
  91.         unset($para["consts"]);
  92.         
  93.         reset($para["uses"]);
  94.         while (list($k, $data)=each($para["uses"]))
  95.             $class["uses"][strtolower($data["file"])] = $this->analyseUse($data);
  96.         
  97.         return $class;
  98.     } // end func analyseClass
  99.  
  100.     /**
  101.     * Analyses a class doc comment.
  102.     * @param    array    Hash returned by getPhpdocParagraph()
  103.     * @return    array
  104.     */    
  105.     function analyseClassDoc($para) {
  106.     
  107.         $class              = $this->emptyClass;
  108.         $class["name"]      = $para["name"];
  109.         $class["extends"]   = $para["extends"];
  110.         
  111.         if ("" != $para["doc"]) {
  112.             
  113.             $class = $this->analyseTags($this->getTags($para["doc"]), $class, $this->classTags);
  114.             
  115.             list($msg, $class) = $this->checkParserErrors($class, "class");
  116.             if ("" != $msg)
  117.                 $this->warn->addDocWarning($this->currentFile, "class", $class["name"], $msg, "mismatch");
  118.                 
  119.             list($class["sdesc"], $class["desc"]) = $this->getDescription($para["doc"]);
  120.             
  121.             $class["undoc"] = false;
  122.         }
  123.         
  124.         return $class;
  125.     } // end func analyseClassDoc
  126.     
  127. } // end class PhpdocClassParser
  128. ?>