home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / xamp / xampp-win32.exe / xampp / ParserData.inc < prev    next >
Encoding:
Text File  |  2004-03-24  |  21.3 KB  |  717 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | phpDocumentor                                                          |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2000-2003 Joshua Eichorn, Gregory Beaver                 |
  7. // | Email         jeichorn@phpdoc.org, cellog@phpdoc.org                   |
  8. // | Web           http://www.phpdoc.org                                    |
  9. // | Mirror        http://phpdocu.sourceforge.net/                          |
  10. // | PEAR          http://pear.php.net/package-info.php?pacid=137           |
  11. // +------------------------------------------------------------------------+
  12. // | This source file is subject to version 3.00 of the PHP License,        |
  13. // | that is available at http://www.php.net/license/3_0.txt.               |
  14. // | If you did not receive a copy of the PHP license and are unable to     |
  15. // | obtain it through the world-wide-web, please send a note to            |
  16. // | license@php.net so we can mail you a copy immediately.                 |
  17. // +------------------------------------------------------------------------+
  18. //
  19.  
  20. /**
  21.  * Parser Data Structures
  22.  * @package phpDocumentor
  23.  * @subpackage ParserData
  24.  * @author Greg Beaver <cellog@users.sourceforge.net>
  25.  * @since 1.0rc1
  26.  * @version $Id: ParserData.inc,v 1.79.2.3 2003/08/13 20:18:55 CelloG Exp $
  27.  */
  28. /**
  29.  * Contains information about a PHP file, used to group procedural elements
  30.  * together.
  31.  * @package phpDocumentor
  32.  * @subpackage ParserData
  33.  * @author Greg Beaver <cellog@users.sourceforge.net>
  34.  * @since 1.0rc1
  35.  * @version $Id: ParserData.inc,v 1.79.2.3 2003/08/13 20:18:55 CelloG Exp $
  36.  */
  37. class parserPage
  38. {
  39.     /**
  40.      * Type is used by many functions to skip the hassle of if
  41.      * <code>get_class($blah) == 'parserBlah'</code>
  42.      * @var string
  43.      */
  44.     var $type = 'page';
  45.     /**
  46.      * not implemented in this version, will be used to link xml output pages
  47.      * @var string
  48.      */
  49.     var $id = '';
  50.     /**
  51.      * filename.ext (no path)
  52.      * @var string
  53.      */
  54.     var $file = '';
  55.     /**
  56.      * relative source location
  57.      * @var string
  58.      */
  59.     var $sourceLocation = '';
  60.     /**
  61.      * phpdoc-safe name (only letters, numbers and _)
  62.      * @var string
  63.      */
  64.     var $name = '';
  65.     /**
  66.      * @var string
  67.      */
  68.     var $category = 'default';
  69.     /**
  70.      * @var string
  71.      */
  72.     var $package = 'default';
  73.     /**
  74.      * @var string
  75.      */
  76.     var $subpackage = '';
  77.     /**
  78.      * @var string
  79.      */
  80.     var $parserVersion = PHPDOCUMENTOR_VER;
  81.     /**
  82.      * not implemented yet
  83.      * file modification date, will be used for makefiles
  84.      * @var string
  85.      */
  86.     var $modDate = '';
  87.     /**
  88.      * @var string full path this page represents
  89.      */
  90.     var $path = '';
  91.     /**
  92.      * Tokenized source code of the file
  93.      * @var array
  94.      */
  95.     var $source = array();
  96.     /**
  97.      * Used to limit output, contains contents of --packageoutput commandline.
  98.      * Does not increase parsing time.  Use --ignore for that
  99.      * @see phpDocumentor_IntermediateParser::$packageoutput, Converter::$package_output
  100.      * @var mixed either false or an array of packages
  101.      */
  102.     var $packageOutput = false;
  103.     
  104.     /**
  105.      * sets package to default package
  106.      * @global string default package name
  107.      */
  108.     function parserPage()
  109.     {
  110.         global $phpDocumentor_DefaultPackageName;
  111.         $this->package = $GLOBALS['phpDocumentor_DefaultPackageName'];
  112.     }
  113.     
  114.     /**
  115.      * @return string always "page"
  116.      */
  117.     function getType()
  118.     {
  119.         return 'page';
  120.     }
  121.     
  122.     /**
  123.      * Sets the source code of the file for highlighting.
  124.      *
  125.      * PHP 4.3.0+ passes an array of tokenizer tokens by line number.  PHP
  126.      * 4.2.3- passes a string to be passed to {@link highlight_string()}
  127.      * @param string|array
  128.      */
  129.     function setSource($source)
  130.     {
  131.         $this->source = $source;
  132.     }
  133.     
  134.     /**
  135.      * Sets the name to display in documentation (can be an alias set with @name)
  136.      * @param string $file
  137.      */
  138.     function setFile($file)
  139.     {
  140.         $this->file = $file;
  141.     }
  142.     
  143.     /**
  144.      * @return string filename.ext or @name alias
  145.      */
  146.     function getFile()
  147.     {
  148.         if (!isset($this->file)) return false;
  149.         return $this->file;
  150.     }
  151.     
  152.     /**
  153.      * @param string $path full path to file
  154.      */
  155.     function setPath($path)
  156.     {
  157.         // look for special windows case
  158.         if(SMART_PATH_DELIMITER === '\\')
  159.             $this->path = strtr($path,'/','\\');
  160.         else
  161.             $this->path = $path;
  162.     }
  163.     
  164.     /**
  165.      * @return string fully delimited path (OS-dependent format)
  166.      */
  167.     function getPath()
  168.     {
  169.         if (!isset($this->path)) return false;
  170.         return $this->path;
  171.     }
  172.     
  173.     /**
  174.      * @param array $packages array of packages to display in documentation (package1,package2,...)
  175.      * @see phpDocumentor_IntermediateParser::$packageoutput
  176.      */
  177.     function setPackageOutput($packages)
  178.     {
  179.         $this->packageOutput = $packages;
  180.     }
  181.     
  182.     /**
  183.      * @return array array of packages (package1,package2,...)
  184.      * @see phpDocumentor_IntermediateParser::$packageoutput
  185.      */
  186.     function getPackageOutput()
  187.     {
  188.         return $this->packageOutput;
  189.     }
  190.     
  191.     /**
  192.      * @param string $name phpdoc-safe name (only _, numbers and letters) set by Parser::parse()
  193.      * @see Parser::parse()
  194.      */
  195.     function setName($name)
  196.     {
  197.         $this->name = $name;
  198.     }
  199.     
  200.     /**
  201.      * @return string phpdoc-safe name (only _, numbers and letters)
  202.      */
  203.     function getName()
  204.     {
  205.         if (!isset($this->name)) return false;
  206.         return $this->name;
  207.     }
  208.     
  209.     /**
  210.      * @param string $source path of this file relative to program root
  211.      */
  212.     function setSourceLocation($source)
  213.     {
  214.         $this->sourceLocation = $source;
  215.     }
  216.     
  217.     /**
  218.     * @param Converter
  219.     * @param boolean if this parameter is true, it will truncate the source location to the
  220.     * subdirectory of pear
  221.      * @return string path of this file relative to program root
  222.      */
  223.     function getSourceLocation ($c,$pearize = false)
  224.     {
  225.         global $_phpDocumentor_options;
  226.         if (!isset($this->sourceLocation)) return false;
  227.         if ($pearize)
  228.         {
  229.             $sl = $this->sourceLocation;
  230.             if (strpos($sl,'pear/'))
  231.             {
  232.                 $sl = substr($sl,strpos($sl,'pear/') + 5);
  233.                 return $sl;
  234.             } else
  235.             {
  236.                 return str_replace($_phpDocumentor_options['Program_Root'] . PATH_DELIMITER,'',$sl);
  237.             }
  238.             return $sl;
  239.         }
  240.         return $this->sourceLocation;
  241.     }
  242.     /**
  243.      * Not implemented in this version
  244.      * @return boolean tell the parser whether to parse the file, otherwise
  245.      *                   this function will retrieve the parsed data from external file
  246.      */
  247.     function getParseData()
  248.     {
  249.         return true;
  250.     }
  251. }
  252.  
  253. /**
  254.  * Contains an in-memory representation of all documentable elements
  255.  * ({@link parserPage}, {@link parserFunction}, {@link parserDefine},
  256.  * {@link parserInclude}, {@link parserClass}, {@link parserMethod},
  257.  * {@link parserVar}) and their DocBlocks ({@link parserDocBlock}).
  258.  *
  259.  * This class works in coordination with {@link phpDocumentor_IntermediateParser}
  260.  * to take output from {@link Parser::handleEvent()} and create indexes, links,
  261.  * and other assorted things (all documented in phpDocumentor_IntermediateParser
  262.  * and {@link Converter})
  263.  * @package phpDocumentor
  264.  * @subpackage ParserData
  265.  * @author Greg Beaver <cellog@users.sourceforge.net>
  266.  * @since 1.0rc1
  267.  * @version $Id: ParserData.inc,v 1.79.2.3 2003/08/13 20:18:55 CelloG Exp $
  268.  */
  269. class parserData
  270. {
  271.     /**
  272.      * {@link parserPage} element that is this parserData's parent, or false if
  273.      * not set.
  274.      * @var false|parserPage
  275.      */
  276.     var $parent = false;
  277.     /**
  278.      * array of parsed elements
  279.      * @var array
  280.      */
  281.     var $elements = array();
  282.     /**
  283.      * array of parsed elements with @access private
  284.      * @var array
  285.      */
  286.     var $privateelements = array();
  287.     /**
  288.      * array of parsed class elements
  289.      * @var array
  290.      */
  291.     var $classelements = array();
  292.     
  293.     /**
  294.      * @var parserTutorial|false
  295.      */
  296.     var $tutorial = false;
  297.     /**
  298.      * array of parsed class elements with @access private
  299.      * @var array
  300.      */
  301.     var $privateclasselements = array();
  302.     /**
  303.      * array of links descended from {@link abstractLink}
  304.      * @var array
  305.      * @see pageLink, defineLink, classLink, functionLink, methodLink, varLink
  306.      */
  307.     var $links = array();
  308.     /**
  309.      * used by {@link phpDocumentor_IntermediateParser::handleDocBlock()} to
  310.      * determine whether a docblock is a page-level docblock or not.  $clean is
  311.      * true as long as only 0 or 1 docblock has been parsed, and no element
  312.      * other than parserPage has been parsed
  313.      * @var boolean
  314.      */
  315.     var $clean = true;
  316.     /**
  317.      * DocBlock ({@link parserDocBlock}) for this page, or false if not set
  318.      * @var mixed
  319.      */
  320.     var $docblock = false;
  321.     /**
  322.      * Flag used to determine whether a page-level docblock is present
  323.      * @var boolean
  324.      * @access private
  325.      */
  326.     var $_explicitdocblock = false;
  327.     /**
  328.      * Type is used by many functions to skip the hassle of if
  329.      * <code>get_class($blah) == 'parserBlah'</code>
  330.      * always 'page', used in element indexing and conversion functions found in
  331.      * {@link Converter}
  332.      * @var string
  333.      */
  334.     var $type = 'page';
  335.     
  336.     /**
  337.      * @param parserElement add a parsed element to the {@link $elements} array,
  338.      *                      also sets {@link $clean} to false
  339.      */
  340.     function addElement(&$element)
  341.     {
  342.         $element->setPath($this->parent->path);
  343.         if ($element->getType() == 'class' || $element->getType() == 'method' || $element->getType() == 'var')
  344.         {
  345.             $this->classelements[] = $element;
  346.         } else
  347.         {
  348.             $this->elements[] = $element;
  349.         }
  350.         $this->clean = false;
  351.     }
  352.     
  353.     /**
  354.      * @param parserTutorial
  355.      * @param Converter
  356.      */
  357.     function addTutorial($t,&$c)
  358.     {
  359.         $this->tutorial = new tutorialLink;
  360.         $this->tutorial->addLink('',$t->path,$t->name,$t->package,$t->subpackage,$t->getTitle($c));
  361.     }
  362.     
  363.     /**
  364.      * If this file has a tutorial associated with it, returns a link to the
  365.      * tutorial.
  366.      * @return tutorialLink
  367.      */
  368.     function getTutorial()
  369.     {
  370.         return $this->tutorial;
  371.     }
  372.     
  373.     /**
  374.      * If the page-level DocBlock was present in the source, returns true
  375.      * @return boolean
  376.      */
  377.     function hasExplicitDocBlock()
  378.     {
  379.         return $this->_explicitdocblock;
  380.     }
  381.     
  382.     /**
  383.      * Tells this page that its DocBlock was not implicit
  384.      */
  385.     function explicitDocBlock()
  386.     {
  387.         $this->_explicitdocblock = true;
  388.     }
  389.     
  390.     /**
  391.      * @param parserElement element to add a new link (descended from
  392.      * {@link abstractLink})to the {@link $links} array
  393.      * @param string classname for elements that are class-based (this may be
  394.      *               deprecated in the future, as the classname should be
  395.      *               contained within the element.  if $element is a page, this
  396.      *               parameter is a package name
  397.      * @param string subpackage name for page elements
  398.      */
  399.     function addLink(&$element,$classorpackage = '', $subpackage = '')
  400.     {
  401.         switch($element->type)
  402.         {
  403.             case 'function':
  404.                 $x = new functionLink;
  405.                 $x->addLink($this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
  406.                 return $x;
  407.             break;
  408.             case 'define':
  409.                 $x = new defineLink;
  410.                 $x->addLink($this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
  411.                 return $x;
  412.             break;
  413.             case 'global':
  414.                 $x = new globalLink;
  415.                 $x->addLink($this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
  416.                 return $x;
  417.             break;
  418.             case 'class':
  419.                 $x = new classLink;
  420.                 $x->addLink($this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
  421.                 return $x;
  422.             break;
  423.             case 'method':
  424.                 $x = new methodLink;
  425.                 $x->addLink($classorpackage, $this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
  426.                 return $x;
  427.             break;
  428.             case 'var':
  429.                 $x = new varLink;
  430.                 $x->addLink($classorpackage, $this->parent->path, $this->parent->name, $element->name, $element->docblock->package, $element->docblock->subpackage);
  431.                 return $x;
  432.             break;
  433.             case 'page':
  434.                 if (empty($classorpackage)) $classorpackage = $GLOBALS['phpDocumentor_DefaultPackageName'];
  435.                 $x = new pageLink;
  436.                 $x->addLink($element->path,$element->name,$element->file,$classorpackage, $subpackage);
  437.                 return $x;
  438.             break;
  439.         }
  440.     }
  441.     
  442.     function &getLink(&$c, $text = false)
  443.     {
  444.         return $c->getPageLink($this->parent->file, $this->docblock->package, $this->parent->path, $text);
  445.     }
  446.     
  447.     /**
  448.      * returns a list of all classes declared in a file
  449.      * @param Converter &$c
  450.      * @return array Format: array(packagename => parserClass,packagename => parserClass,...)
  451.      */
  452.     function getClasses(&$c)
  453.     {
  454.         $r = $c->classes->getClassesInPath($this->parent->path);
  455.         $rr = array();
  456.         if ($r)
  457.         foreach($r as $class => $obj)
  458.         {
  459.             $rr[$obj->docblock->package][] = $obj;
  460.         }
  461.         return $rr;
  462.     }
  463.     
  464.     /**
  465.      * Get the output-safe filename (. changed to _)
  466.      * @return string
  467.      */
  468.     function getName()
  469.     {
  470.         if (isset($this->parent) && $this->parent)
  471.         return $this->parent->getName();
  472.     }
  473.     
  474.     /**
  475.      * @param parserPage parent element of this parsed data
  476.      */
  477.     function setParent(&$parent)
  478.     {
  479.         $this->parent = $parent;
  480.     }
  481.     
  482.     /**
  483.      * @return bool returns the value of {@link $clean}
  484.      */
  485.     function isClean()
  486.     {
  487.         return $this->clean;
  488.     }
  489.     
  490.     /**
  491.      * @param parserDocBlock
  492.      * @see parserDocBlock
  493.      */
  494.     function setDocBlock(&$docblock)
  495.     {
  496.         $this->docblock = $docblock;
  497.     }
  498. }
  499.  
  500. /**
  501.  * Base class for all elements
  502.  * @package phpDocumentor
  503.  * @subpackage ParserData
  504.  * @abstract
  505.  * @author Greg Beaver <cellog@users.sourceforge.net>
  506.  * @since 1.0rc1
  507.  * @version $Id: ParserData.inc,v 1.79.2.3 2003/08/13 20:18:55 CelloG Exp $
  508.  */
  509. class parserBase
  510. {
  511.     /**
  512.      * Type is used by many functions to skip the hassle of if get_class($blah) == 'parserBlah'
  513.      * always base
  514.      * @var string
  515.      */
  516.     var $type = 'base';
  517.     /**
  518.      * set to different things by its descendants
  519.      * @abstract
  520.      * @var mixed
  521.      */
  522.     var $value = false;
  523.  
  524.     /**
  525.      * @return string returns value of {@link $type}
  526.      */
  527.     function getType()
  528.     {
  529.         return $this->type;
  530.     }
  531.     
  532.     /**
  533.      * @param mixed set the value of this element
  534.      */
  535.     function setValue($value)
  536.     {
  537.         $this->value = $value;
  538.     }
  539.     
  540.     /**
  541.      * @return mixed get the value of this element (element-dependent)
  542.      */
  543.     function getValue()
  544.     {
  545.         return $this->value;
  546.     }
  547. }
  548.  
  549.  
  550. /**
  551.  * Used to represent strings that contain inline tags, so that they can be properly parsed at link time
  552.  * @package phpDocumentor
  553.  * @subpackage ParserData
  554.  * @author Greg Beaver <cellog@users.sourceforge.net>
  555.  * @since 1.0rc1
  556.  * @version $Id: ParserData.inc,v 1.79.2.3 2003/08/13 20:18:55 CelloG Exp $
  557.  */
  558. class parserStringWithInlineTags extends parserBase
  559. {
  560.     /**
  561.      * Type is used by many functions to skip the hassle of if get_class($blah) == 'parserBlah'
  562.      * always '_string'
  563.      * @var string
  564.      */
  565.     var $type = '_string';
  566.     /** @access private */
  567.     var $cache = false;
  568.     /**
  569.      * array of strings and {@link parserInlineTag}s
  570.      * Format:
  571.      * array(string1,string2,parserInlineTag1,string3,parserInlineTag2,...)
  572.      * @var array
  573.      */
  574.     var $value = array();
  575.  
  576.     /**
  577.      * equivalent to the . operator ($a = $b . $c)
  578.      * @param mixed either a string or a {@link parserInlineTag}
  579.      */
  580.     function add($stringOrInlineTag)
  581.     {
  582.         if (is_string($stringOrInlineTag))
  583.         {
  584.             if (!count($this->value))
  585.             {
  586.                 $this->value[] = $stringOrInlineTag;
  587.                 return;
  588.             }
  589.             if (is_string($this->value[count($this->value) - 1]))
  590.             {
  591.                 $this->value[count($this->value) - 1] .= $stringOrInlineTag;
  592.                 return;
  593.             } else
  594.             {
  595.                 $this->value[] = $stringOrInlineTag;
  596.                 return;
  597.             }
  598.         } else
  599.         {
  600.             if (is_a($stringOrInlineTag,'parserinlinetag') && phpDocumentor_setup::checkIgnoreTag($stringOrInlineTag->inlinetype, true)) return;
  601.             $this->value[] = $stringOrInlineTag;
  602.         }
  603.     }
  604.     
  605.     /**
  606.      * Determine whether the string contains any inline tags
  607.      * @tutorial inlinetags.pkg
  608.      * @return boolean
  609.      */
  610.     function hasInlineTag()
  611.     {
  612.         for($i=0;$i<count($this->value);$i++)
  613.         {
  614.             if (is_a($this->value[$i],'parserinlinetag')) return true;
  615.         }
  616.         return false;
  617.     }
  618.     
  619.     /**
  620.      * Pass source code to any {@}source} tags contained within the string
  621.      * for later conversion.
  622.      * @param string|array source code ready to be highlighted
  623.      */
  624.     function setSource($source)
  625.     {
  626.         for($i=0;$i<count($this->value);$i++)
  627.         {
  628.             if (get_class($this->value[$i]) == 'parsersourceinlinetag')
  629.             {
  630.                 $this->value[$i]->setSource($source);
  631.             }
  632.         }
  633.     }
  634.  
  635.     /**
  636.      * equivalent to trim(strlen($string))
  637.      * @return integer length of the string this object represents
  638.      */
  639.     function trimmedStrlen()
  640.     {
  641.         $a = 0;
  642.         for($i=0;$i<count($this->value);$i++)
  643.         {
  644.             if (is_string($this->value[$i]))
  645.             {
  646.                 if ($i == 0)
  647.                 {
  648.                     $a += strlen(ltrim($this->value[$i]));
  649.                 } elseif ($i == count($this->value[$i]) - 1)
  650.                 {
  651.                     $a += strlen(chop($this->value[$i]));
  652.                 }
  653.             } else
  654.             {
  655.                 $a += $this->value[$i]->Strlen();
  656.             }
  657.         }
  658.         return $a;
  659.     }
  660.     
  661.     /**
  662.      * return the string unconverted (all inline tags are taken out - this
  663.      * should only be used in pre-parsing to see if any other text
  664.      * is in the string)
  665.      * @uses parserInlineTag::getString() removes inline tag length, as it is
  666.      *       indeterminate until conversion.
  667.      * @return string trimmed value
  668.      */
  669.     function getString($trim = true)
  670.     {
  671.         $a = '';
  672.         for($i=0; $i<count($this->value); $i++)
  673.         {
  674.             if (is_string($this->value[$i]))
  675.             {
  676.                 $a .= $this->value[$i];
  677.             } else
  678.             {
  679.                 $a .= $this->value[$i]->getString();
  680.             }
  681.         }
  682.         if ($trim) $a = trim($a);
  683.         return $a;
  684.     }
  685.     
  686.     /**
  687.      * Use to convert the string to a real string with all inline tags parsed and linked
  688.      * @see Converter::returnSee()
  689.      * @param Converter
  690.      * @param boolean true if one needs to postprocess
  691.      */
  692.     function Convert(&$converter,$postprocess = true)
  693.     {
  694.         if ($this->cache)
  695.         {
  696.             if ($converter->name == $this->cache['name'] && $converter->outputformat == $this->cache['output'] && $converter->checkState($this->cache['state']) && $this->cache['postprocess'] === $postprocess) return $this->cache['contents'];
  697.         }
  698.         if (is_string($this->value)) return $this->value;
  699.         $a = '';
  700.         for($i=0; $i<count($this->value); $i++)
  701.         {
  702.             if (is_string($this->value[$i]))
  703.             {
  704.                 if ($postprocess && !method_exists($converter,'postProcess')) var_dump('a',$converter);
  705.                 if ($postprocess) $a .= $converter->postProcess($this->value[$i]);
  706.                 else $a .= $this->value[$i];
  707.             } else
  708.             {
  709.                 $a .= $this->value[$i]->Convert($converter, $postprocess);
  710.             }
  711.         }
  712.         $this->cache = array('name' => $converter->name,'output' => $converter->outputformat, 'contents' => trim($a), 'state' => $converter->getState(), 'postprocess' => $postprocess);
  713.         return trim($a);
  714.     }
  715. }
  716.  
  717. ?>