Source for file ParserDocBlock.inc
Documentation is available at ParserDocBlock.inc
* DocBlock Parser Classes
* phpDocumentor :: automatic documentation generator
* Copyright (c) 2002-2006 Gregory Beaver
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* @subpackage ParserDocBlock
* @copyright 2002-2006 Gregory Beaver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version CVS: $Id: ParserDocBlock.inc,v 1.9 2006/08/17 03:46:58 cellog Exp $
* @link http://www.phpdoc.org
* @link http://pear.php.net/PhpDocumentor
* @see Parser, WordParser
* represents a short or long description in a DocBlock ({@link parserDocBlock})
* @subpackage ParserDocBlock
* @version $Id: ParserDocBlock.inc,v 1.9 2006/08/17 03:46:58 cellog Exp $
* Type is used by many functions to skip the hassle of if phpDocumentor_get_class($blah) == 'parserBlah'
* @param mixed like {@link parserStringWithInlineTags::add()}, this can be a string or parserInlineTag, but it can also be a
* parserStringWithInlineTags, and the contents will be merged
function add($stringOrClass)
for($i= 0;$i< count($stringOrClass->value);$i++ )
* @return boolean whether this desc has an {@}inheritdoc} inline tag
* @return boolean whether this desc has an {@}source} inline tag
* replaces {@}inheritdoc} with the contents of the parent DocBlock
* @param parserDesc parent parserDesc, used to retrieve the description
for($i= 0;$i< count($value);$i++ )
for($j= 0;$j< count($desc->value);$j++ )
$this->add($desc->value[$j]);
} else $this->add($value[$i]);
* Represents a docblock and its components, {@link $desc}, {@link $sdesc}, {@link $tags}, and also {@link $params} for functions
* @subpackage ParserDocBlock
* @version $Id: ParserDocBlock.inc,v 1.9 2006/08/17 03:46:58 cellog Exp $
* @var array array of {@link parserDesc}s
* @var array array of {@link parserDesc}s
* Line number in the source on which this docblock begins
* Line number in the source on which this docblock ends
* array of {@link parserTag}s
* array of unrecognized {@link parserTag}s
* array(index of param in function parameter list -OR- parameter name =>
* parserStringWithInlineTags,...)
* array of global variable data.
* array(index of global variable in @global tag list -OR- global variable name =>
* array(datatype,parserStringWithInlineTags),...)
* array of static variable data.
* array(index of static variable in @global tag list -OR- static variable name =>
* {@link parserStaticvarTag},...)
* This is either a {@link parserReturnTag} or false if no return tag is present
* This is either a {@link parserVarTag} or false if no var tag is present
* whether this DocBlock has an @access tag
* whether this DocBlock has a @name tag
* description of package parsed from @package tag
* description of subpackage parsed from @package tag
* Determines whether a DocBlock can legally have a {@}source} tag
* @tutorial tags.inlinesource.pkg
* sets package to default
* @global string default package name
$this->package = $GLOBALS['phpDocumentor_DefaultPackageName'];
$this->category = $GLOBALS['phpDocumentor_DefaultCategoryName'];
* Sets the starting line number for the DocBlock
* Retrieve starting line number
* Sets the ending line number for the DocBlock
* Retrieve ending line number
* Parse out any html tags from doc comments, and make them into
* @uses parserDescParser::parse()
$parser->subscribe('*',$this);
if ($this->desc) $parser->parse($this->desc->value);
$parser->parse($this->sdesc->value,true);
* Tells the DocBlock it can have a @filesource tag
* Only page-level DocBlocks may have a @filesource tag
$this->_canSource = true;
* Tells the DocBlock it can't have a @filesource tag
* Only page-level DocBlocks may have a @filesource tag
$this->_canSource = false;
* Indirectly called after parsing by {@link postProcess}
* @param integer either 1 for long desc or 2 for short desc
* @param array data organized into paragraphs. Each entry is a {@link parserStringWithInlineTags}
* @uses $processed_desc sets to the array passed from {@link parserDescParser::parse()}
* @uses $processed_sdesc sets to the array passed from {@link parserDescParser::parse()}
function HandleEvent($event,$data)
foreach ($modifiers as $modifier)
unset ($this->tags['access']);
$this->tags['access'][] = $x;
unset ($this->tags[$modifier]);
* Set the short description of the DocBlock
* Setting the short description is possible by passing in one of three
* <li>another DocBlock's short description</li>
* <li>another DocBlock, the short description will be extracted</li>
* <li>a Zend Studio-compatible @desc tag</li>
* @param parserDesc|parserDocBlock|parserTagsets {@link $sdesc}
$this->sdesc = $desc->sdesc;
* Passes to {@link parserStringWithInlineTags::setSource()}
* After passing, it calls {@link postProcess()} to set up the new
* @param string|arraytokenized highlight-ready source code
* @param false|stringname of class if this is a method source
$this->desc->setSource($source, $class);
* @param parserDesc|parserDocBlocksets {@link $desc}
$this->desc = $desc->desc;
* Wrapper for {@link parserDesc::hasInheritDoc()}
if (!$this->desc) return false;
* Wrapper for {@link parserDesc::replaceInheritDoc()}
* Also replaces {@}inheritdoc} in the {@link $processed_desc}
if (!$this->desc) return false;
* @param Converter takes {@link $sdesc} and converts it to a string and returns it if present, otherwise returns ''
$result .= $desc->Convert($converter);
// var_dump($this->desc,$this->processed_desc);
* @param Converter takes {@link $desc} and converts it to a string and returns it if present, otherwise returns ''
$result .= $converter->EncloseParagraph($desc->Convert($converter));
// var_dump($this->desc,$this->processed_desc);
* @param string $paramVar if empty, param is indexed in the order received and set using {@link changeParam()}
* @param parserStringWithInlineTags $value
function addParam($paramVar, $paramType, $value)
* @param integer $index index of parameter in the {@link $params} array
* @param string $name name of the parameter to set in the $params array
* @param string|null$type type of the parameter
* replaces nameless parameters in the {@link $params} array with their names
* add @param tags for params in the function with no entry
* @param array $params Format: array(parameter key =>
* array(0 => parameter name[,1 => default value][,2 => type hint]),...)
for($i= 0;$i< count($countparams);$i++ , next($params))
$type = isset ($info[2]) ? $info[2] : null;
$params[key($params)] = false;
foreach ($params as $key => $info) {
$type = isset ($info[2]) ? $info[2] : null;
if (!isset ($this->params[$info[0]])) {
$this->addParam($info[0], $type, $blank);
unset ($this->tags['param']);
* Used to insert DocBlock Template tags into a docblock
* @global array used to determine whether to add ignored tags, or not
if (is_array($value)) $value = $value[0];
if ($tag->keyword == 'uses')
$this->addUses($value, $tag->_description);
* @param string $keyword tag name
* @param parserStringWithInlineTags $value the contents of the tag
* @global array used to determine whether to add the @internal tag or not
$keyword = trim($keyword);
// don't add the tag at all if it was specified to ignore it with --ignore-tags
if ($keyword == 'package' || $keyword == 'subpackage' || $keyword == 'category') return $this->addPackage($keyword, $value);
if ($keyword == 'access') return $this->addAccess($value);
if ($keyword == 'link') return $this->addLink($value);
if ($keyword == 'see' || $keyword == 'tutorial') return $this->addSee($keyword,$value);
if ($keyword == 'uses') return $this->addUses($keyword, $value);
if ($keyword == 'name') return $this->addName($value);
if (!in_array($keyword,$GLOBALS['_phpDocumentor_tags_allowed']))
if ($keyword == 'internal' && (!isset ($_phpDocumentor_setting['parseprivate']) || $_phpDocumentor_setting['parseprivate'] == 'off')) return;
if (!isset ($this->tags[$keyword])) {
$this->tags[$keyword] = array();
$ptag = 'parser'. ucfirst($keyword). 'Tag';
* @param string contents of the tag
* @param string path to the file containing this tag
* adds an unknown tag to the {@link $unknown_tags} array for use by custom converters
* @param string tag value
* set the element's package to the passed values. Used in {@link phpDocumentor_IntermediateParser} to align package of
* elements inside a class or procedural page to the package of the class/procedural page
* @param string element name
* @param string element type (include, define, var, method, global, function, const)
if ($this->package != $GLOBALS['phpDocumentor_DefaultPackageName'])
$this->package = $GLOBALS['phpDocumentor_DefaultPackageName'];
* Used if this docblock has a @package tag.
* phpDocumentor will guess package for DocBlocks that don't have
* If the DocBlock has a @package tag, then this returns true
* Used if this docblock has a @category tag.
* phpDocumentor will guess category for DocBlocks that don't have
* @uses $explicitcategory
* If the DocBlock has a @category tag, then this returns true
* @param string $keyword tag name (either package or subpackage)
* @param mixed $value either a string or a parserStringWithInlineTags. Strips all inline tags and use the text as the package
if ($keyword == 'package')
$value = $value->getString();
$value = trim($value[0]);
$value = trim($value[0]);
} else $value = trim($value[0]);
$value = preg_replace('/[^\[\]0-9\-a-zA-Z_\x7f-\xff]/', '-', $value);
} elseif ($keyword == 'subpackage')
$value = $value->getString();
} else $value = $value[0];
$value = preg_replace('/[^\[\]0-9\-a-zA-Z_\x7f-\xff]/', '-', $value);
} elseif ($keyword == 'category')
$value = $value->getString();
$value = preg_replace('/[^\[\]0-9\-a-zA-Z_\x7f-\xff]/', '-', $value);
* Adds a @name tag to the tag list
* @param string new name of element
if (is_object($value)) $value = $value->getString();
$this->tags['name'][] = $x;
* @param string if empty, staticvar is indexed in the order received and set using {@link changeStatic()}
* @param string data type
* @param parserStringWithInlineTags
* adds a function declaration of @global to the {@link $funcglobals} array
* @param string global type
* @param string description of how the global is used in the function
* @param integer $index index of parameter in the {@link $funcglobals} array
* @param string $name name of the parameter to set in the $funcglobals array
* @param integer $index index of parameter in the {@link $statics} array
* @param string $name name of the parameter to set in the $statics array
* replaces nameless global variables in the {@link $funcglobals} array with their names
for($i= 0;$i< count($funcs);$i++ )
* replaces nameless static variables in the {@link $statics} array with their names
for($i= 0;$i< count($funcs);$i++ )
* add an @access tag to the {@link tags} array
* @param string should be either public or private
if (is_object($value)) $value = $value->getString();
$this->tags['access'][] = $x;
* Adds a new @filesource tag to the DocBlock
* @tutorial tags.filesource.pkg
* @param string full path to the file
* @param array tokenized source code, ordered by line number
if (isset ($this->tags['filesource'])) return;
* creates a {@link parserLinkTag} and adds it to the {@link $tags} array
* creates a {@link parserLinkTag} and adds it to the {@link $tags} array
* @param string either see or uses
function addSee($keyword,$value)
$tag = 'parser'. ucfirst($keyword). 'Tag';
$this->tags[$keyword][] = new $tag($value);
* creates a {@link parserReturnTag} and adds it to the {@link $tags} array
* @param string $returnType the one-word name of the return type (mixed should be used if more than one type)
* @param parserStringWithInlineTags $value
// only take the first one
* creates a {@link parserVarTag} and adds it to the {@link $tags} array
* @param string $varType the one-word name of the variable type (mixed should be used if more than one type)
* @param parserStringWithInlineTags $value
function addVar($varType, $value)
// only take the first one
* Adds a virtual @usedby tag to output
* @param abstractLink link to the element that has a @uses tag
* @param parserStringWithInlinetags description of how the elements uses
function addUsedBy($link, $descrip)
* Add a @uses tag to the DocBlock
* @param string @see-style text, used for {@link Converter::getLink()}
* @param parserStringWithInlineTags description of how the used element is
* @tutorial tags.uses.pkg
function addUses($seeel, $description)
usort($this->tags['uses'], array($this, '_sortUses'));
* Custom sorting function for sorting @uses tags
function _sortUses($a, $b)
* @return mixed false if no keyword, unconverted value if one keyword, array of unconverted values if more than one keyword
if ($keyword == 'filesource' && !$this->_canSource) return false;
if (isset ($this->tags[$keyword]))
return $this->tags[$keyword][0];
} else return $this->tags[$keyword];
* @return array Format: array('var' => tag name, 'data' => unconverted tag value)
foreach($this->params as $key => $val)
$ret[] = array("var" => ucfirst($key),"data" => $val);
foreach($this->tags as $keyword => $vals)
if ($keyword == 'filesource' && !$this->_canSource) continue;
/** @return string always 'docblock' */
case 'parserstaticvartag' :
case 'parsertutorialtag' :
case 'parserstaticvartag' :
|