3 * DocBlock Parser Classes
\r
5 * phpDocumentor :: automatic documentation generator
\r
7 * PHP versions 4 and 5
\r
9 * Copyright (c) 2002-2006 Gregory Beaver
\r
13 * This library is free software; you can redistribute it
\r
14 * and/or modify it under the terms of the GNU Lesser General
\r
15 * Public License as published by the Free Software Foundation;
\r
16 * either version 2.1 of the License, or (at your option) any
\r
19 * This library is distributed in the hope that it will be useful,
\r
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
22 * Lesser General Public License for more details.
\r
24 * You should have received a copy of the GNU Lesser General Public
\r
25 * License along with this library; if not, write to the Free Software
\r
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
28 * @package phpDocumentor
\r
29 * @subpackage ParserDocBlock
\r
30 * @author Gregory Beaver <cellog@php.net>
\r
31 * @copyright 2002-2006 Gregory Beaver
\r
32 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
\r
33 * @version CVS: $Id: ParserDocBlock.inc,v 1.12 2007/04/19 20:20:57 ashnazg Exp $
\r
34 * @link http://www.phpdoc.org
\r
35 * @link http://pear.php.net/PhpDocumentor
\r
36 * @see Parser, WordParser
\r
40 * represents a short or long description in a DocBlock ({@link parserDocBlock})
\r
41 * @package phpDocumentor
\r
42 * @subpackage ParserDocBlock
\r
43 * @author Greg Beaver <cellog@php.net>
\r
45 * @version $Id: ParserDocBlock.inc,v 1.12 2007/04/19 20:20:57 ashnazg Exp $
\r
47 class parserDesc extends parserStringWithInlineTags
\r
50 * Type is used by many functions to skip the hassle of if phpDocumentor_get_class($blah) == 'parserBlah'
\r
54 var $type = '_desc';
\r
57 * @param mixed like {@link parserStringWithInlineTags::add()}, this can be a string or parserInlineTag, but it can also be a
\r
58 * parserStringWithInlineTags, and the contents will be merged
\r
60 function add($stringOrClass)
\r
62 if (is_object($stringOrClass))
\r
64 if (phpDocumentor_get_class($stringOrClass) == 'parserstringwithinlinetags' ||
\r
65 phpDocumentor_get_class($stringOrClass) == 'parserdesc')
\r
67 for($i=0;$i<count($stringOrClass->value);$i++)
\r
69 parserStringWithInlineTags::add($stringOrClass->value[$i]);
\r
73 parserStringWithInlineTags::add($stringOrClass);
\r
75 } else return parserStringWithInlineTags::add($stringOrClass);
\r
79 * @return boolean whether this desc has an {@}inheritdoc} inline tag
\r
81 function hasInheritDoc()
\r
83 for($i=0;$i<count($this->value);$i++)
\r
85 if (phpDocumentor_get_class($this->value[$i])=='parserinheritdocinlinetag') return true;
\r
90 * @return boolean whether this desc has an {@}source} inline tag
\r
92 function hasSource()
\r
94 for($i=0;$i<count($this->value);$i++)
\r
96 if (phpDocumentor_get_class($this->value[$i])=='parsersourceinlinetag') return true;
\r
101 * replaces {@}inheritdoc} with the contents of the parent DocBlock
\r
102 * @param parserDesc parent parserDesc, used to retrieve the description
\r
104 function replaceInheritDoc($desc)
\r
106 $value = $this->value;
\r
107 $this->value = array();
\r
108 for($i=0;$i<count($value);$i++)
\r
110 if (phpDocumentor_get_class($value[$i])=='parserinheritdocinlinetag')
\r
112 for($j=0;$j<count($desc->value);$j++)
\r
114 $this->add($desc->value[$j]);
\r
116 } else $this->add($value[$i]);
\r
122 * Represents a docblock and its components, {@link $desc}, {@link $sdesc}, {@link $tags}, and also {@link $params} for functions
\r
123 * @package phpDocumentor
\r
124 * @subpackage ParserDocBlock
\r
125 * @author Greg Beaver <cellog@php.net>
\r
127 * @version $Id: ParserDocBlock.inc,v 1.12 2007/04/19 20:20:57 ashnazg Exp $
\r
129 class parserDocBlock
\r
136 * @var array array of {@link parserDesc}s
\r
138 var $processed_desc = false;
\r
140 * @var array array of {@link parserDesc}s
\r
142 var $processed_sdesc = false;
\r
146 var $sdesc = false;
\r
148 * Line number in the source on which this docblock begins
\r
150 * @var false|integer
\r
152 var $linenumber = false;
\r
154 * Line number in the source on which this docblock ends
\r
156 * @var false|integer
\r
158 var $endlinenumber = false;
\r
160 * array of {@link parserTag}s
\r
163 var $tags = array();
\r
165 * array of unrecognized {@link parserTag}s
\r
168 var $unknown_tags = array();
\r
170 * array of param data.
\r
172 * array(index of param in function parameter list -OR- parameter name =>
\r
173 * parserStringWithInlineTags,...)
\r
176 var $params = array();
\r
178 * array of global variable data.
\r
180 * array(index of global variable in @global tag list -OR- global variable name =>
\r
181 * array(datatype,parserStringWithInlineTags),...)
\r
184 var $funcglobals = array();
\r
187 * array of static variable data.
\r
189 * array(index of static variable in @global tag list -OR- static variable name =>
\r
190 * {@link parserStaticvarTag},...)
\r
193 var $statics = array();
\r
195 * array of {@link parserPropertyTag}, {@link parserPropertyReadTag}, {@link parserPropertyWriteTag}, {@link parserMethodTag} magic tags
\r
197 var $properties = array();
\r
199 * This is either a {@link parserReturnTag} or false if no return tag is present
\r
202 var $return = false;
\r
204 * This is either a {@link parserVarTag} or false if no var tag is present
\r
209 * fix for bug 591396
\r
212 var $explicitpackage = false;
\r
214 * fix for bug 708559
\r
217 var $explicitcategory = false;
\r
221 var $package = 'default';
\r
223 var $subpackage = '';
\r
225 * whether this DocBlock has an @access tag
\r
227 var $hasaccess = false;
\r
229 * whether this DocBlock has a @name tag
\r
231 var $hasname = false;
\r
233 * description of package parsed from @package tag
\r
234 * Unused in this version
\r
237 var $packagedescrip = '';
\r
239 * description of subpackage parsed from @package tag
\r
240 * Unused in this version
\r
243 var $subpackagedescrip = '';
\r
245 * Determines whether a DocBlock can legally have a {@}source} tag
\r
246 * @tutorial tags.inlinesource.pkg
\r
250 var $_canSource = false;
\r
253 * sets package to default
\r
254 * @global string default package name
\r
256 function parserDocBlock()
\r
258 global $phpDocumentor_DefaultPackageName;
\r
259 $this->package = $GLOBALS['phpDocumentor_DefaultPackageName'];
\r
260 $this->category = $GLOBALS['phpDocumentor_DefaultCategoryName'];
\r
264 * Sets the starting line number for the DocBlock
\r
267 function setLineNumber($number)
\r
269 $this->linenumber = $number;
\r
273 * Retrieve starting line number
\r
276 function getLineNumber()
\r
278 return $this->linenumber;
\r
282 * Sets the ending line number for the DocBlock
\r
285 function setEndLineNumber($number)
\r
287 $this->endlinenumber = $number;
\r
291 * Retrieve ending line number
\r
294 function getEndLineNumber()
\r
296 return $this->endlinenumber;
\r
300 * Parse out any html tags from doc comments, and make them into
\r
301 * abstract structures
\r
302 * @uses parserDescParser::parse()
\r
304 function postProcess()
\r
308 $parser = new parserDescParser;
\r
309 $parser->subscribe('*',$this);
\r
310 if ($this->desc) $parser->parse($this->desc->value);
\r
311 $parser->parse($this->sdesc->value,true);
\r
316 * Tells the DocBlock it can have a @filesource tag
\r
318 * Only page-level DocBlocks may have a @filesource tag
\r
320 function canSource()
\r
322 $this->_canSource = true;
\r
326 * Tells the DocBlock it can't have a @filesource tag
\r
328 * Only page-level DocBlocks may have a @filesource tag
\r
330 function cantSource()
\r
332 $this->_canSource = false;
\r
336 * Indirectly called after parsing by {@link postProcess}
\r
338 * @param integer either 1 for long desc or 2 for short desc
\r
339 * @param array data organized into paragraphs. Each entry is a {@link parserStringWithInlineTags}
\r
340 * @uses $processed_desc sets to the array passed from {@link parserDescParser::parse()}
\r
341 * @uses $processed_sdesc sets to the array passed from {@link parserDescParser::parse()}
\r
344 function HandleEvent($event,$data)
\r
347 $this->processed_desc = $data;
\r
349 $this->processed_sdesc = $data;
\r
355 function updateModifiers($modifiers)
\r
357 if (is_array($modifiers) && count($modifiers))
\r
359 foreach ($modifiers as $modifier)
\r
366 unset($this->tags['access']);
\r
367 $x = new parserAccessTag($modifier);
\r
370 $this->hasaccess = true;
\r
371 $this->tags['access'][] = $x;
\r
376 unset($this->tags[$modifier]);
\r
377 $this->addKeyword($modifier, '');
\r
385 * Set the short description of the DocBlock
\r
387 * Setting the short description is possible by passing in one of three
\r
388 * possible parameters:
\r
390 * <li>another DocBlock's short description</li>
\r
391 * <li>another DocBlock, the short description will be extracted</li>
\r
392 * <li>a Zend Studio-compatible @desc tag</li>
\r
394 * @param parserDesc|parserDocBlock|parserTag sets {@link $sdesc}
\r
396 function setShortDesc($desc)
\r
398 if (phpDocumentor_get_class($desc) == 'parsertag')
\r
400 $this->sdesc = new parserDesc;
\r
401 $this->processed_sdesc = $desc->value;
\r
404 if (phpDocumentor_get_class($desc) == 'parserdesc') {
\r
405 $this->sdesc = $desc;
\r
408 $this->sdesc = $desc->sdesc;
\r
409 $this->processed_sdesc = $desc->processed_sdesc;
\r
412 if ($this->sdesc && $this->sdesc->hasSource())
\r
414 addWarning(PDERROR_SOURCE_TAG_IGNORED,$this->sdesc->getString());
\r
419 * Passes to {@link parserStringWithInlineTags::setSource()}
\r
421 * After passing, it calls {@link postProcess()} to set up the new
\r
423 * @param string|array tokenized highlight-ready source code
\r
424 * @param false|string name of class if this is a method source
\r
426 function setSource($source, $class = false)
\r
430 $this->desc->setSource($source, $class);
\r
431 $this->postProcess();
\r
436 * @param parserDesc|parserDocBlock sets {@link $desc}
\r
438 function setDesc($desc)
\r
440 if (phpDocumentor_get_class($desc) == 'parserdesc')
\r
441 $this->desc = $desc;
\r
444 $this->desc = $desc->desc;
\r
445 $this->processed_desc = $desc->processed_desc;
\r
450 * Wrapper for {@link parserDesc::hasInheritDoc()}
\r
453 function hasInheritDoc()
\r
455 if (!$this->desc) return false;
\r
456 return $this->desc->hasInheritDoc();
\r
460 * Wrapper for {@link parserDesc::replaceInheritDoc()}
\r
462 * Also replaces {@}inheritdoc} in the {@link $processed_desc}
\r
463 * @param parserDesc
\r
465 function replaceInheritDoc($desc)
\r
467 if (!$this->desc) return false;
\r
468 $this->desc->replaceInheritDoc($desc->desc);
\r
469 $this->postProcess();
\r
473 * @param Converter takes {@link $sdesc} and converts it to a string and returns it if present, otherwise returns ''
\r
476 function getSDesc(&$converter)
\r
478 if ($this->sdesc && $this->processed_sdesc)
\r
481 foreach($this->processed_sdesc as $desc)
\r
483 if (count($desc->value))
\r
484 $result .= $desc->Convert($converter);
\r
489 // var_dump($this->desc,$this->processed_desc);
\r
495 * @param Converter takes {@link $desc} and converts it to a string and returns it if present, otherwise returns ''
\r
498 function getDesc(&$converter)
\r
500 if ($this->desc && $this->processed_desc)
\r
503 foreach($this->processed_desc as $desc)
\r
505 if (count($desc->value))
\r
506 $result .= $converter->EncloseParagraph($desc->Convert($converter));
\r
511 // var_dump($this->desc,$this->processed_desc);
\r
517 * @param string $paramVar if empty, param is indexed in the order received and set using {@link changeParam()}
\r
518 * @param parserStringWithInlineTags $value
\r
520 function addParam($paramVar, $paramType, $value)
\r
522 if (empty($paramVar))
\r
523 $this->params[count($this->params)] = new parserParamTag($paramType,$value);
\r
525 $this->params[$paramVar] = new parserParamTag($paramType,$value);
\r
528 function resetParams()
\r
530 $this->params = array();
\r
533 * @param integer $index index of parameter in the {@link $params} array
\r
534 * @param string $name name of the parameter to set in the $params array
\r
535 * @param string|null $type type of the parameter
\r
537 function changeParam($index, $name, $type)
\r
539 if ($name === $index) {
\r
542 $this->params[$name] = $this->params[$index];
\r
543 unset($this->params[$index]);
\r
547 * replaces nameless parameters in the {@link $params} array with their names
\r
548 * add @param tags for params in the function with no entry
\r
549 * @param array $params Format: array(parameter key =>
\r
550 * array(0 => parameter name[,1 => default value][,2 => type hint]),...)
\r
552 function updateParams($params)
\r
554 $countparams = array_values($params);
\r
556 for($i=0;$i<count($countparams);$i++, next($params))
\r
558 if (isset($this->params[$i]))
\r
560 $info = current($params);
\r
561 $type = isset($info[2]) ? $info[2] : null;
\r
562 $this->changeParam($i, key($params), $type);
\r
563 $params[key($params)] = false;
\r
566 $blank = new parserStringWithInlineTags;
\r
567 foreach ($params as $key => $info) {
\r
571 $type = isset($info[2]) ? $info[2] : null;
\r
572 if (!isset($this->params[$info[0]])) {
\r
573 $this->addParam($info[0], $type, $blank);
\r
578 if (isset($this->tags))
\r
579 unset($this->tags['param']);
\r
583 * Used to insert DocBlock Template tags into a docblock
\r
584 * @param parserTag tag
\r
585 * @global array used to determine whether to add ignored tags, or not
\r
587 function addTag($tag)
\r
589 global $_phpDocumentor_setting;
\r
590 if (phpDocumentor_setup::checkIgnoreTag($tag->keyword)) return;
\r
591 $value = $tag->value;
\r
592 if (is_array($value)) $value = $value[0];
\r
593 if ($tag->keyword == 'uses')
\r
595 $this->addUses($value, $tag->_description);
\r
598 $this->addKeyword($tag->keyword, $value);
\r
603 * @param string $keyword tag name
\r
604 * @param parserStringWithInlineTags $value the contents of the tag
\r
605 * @global array used to determine whether to add the @internal tag or not
\r
607 function addKeyword($keyword, $value)
\r
609 global $_phpDocumentor_setting;
\r
610 $keyword = trim($keyword);
\r
611 if (phpDocumentor_setup::checkIgnoreTag($keyword)) return;
\r
612 // don't add the tag at all if it was specified to ignore it with --ignore-tags
\r
613 if ($keyword == 'package' || $keyword == 'subpackage' || $keyword == 'category') return $this->addPackage($keyword, $value);
\r
614 if ($keyword == 'access') return $this->addAccess($value);
\r
615 if ($keyword == 'link') return $this->addLink($value);
\r
616 if ($keyword == 'see' || $keyword == 'tutorial') return $this->addSee($keyword,$value);
\r
617 if ($keyword == 'uses') return $this->addUses($keyword, $value);
\r
618 if ($keyword == 'name') return $this->addName($value);
\r
619 if (!in_array($keyword,$GLOBALS['_phpDocumentor_tags_allowed']))
\r
620 $this->addUnknownTag($keyword,$value);
\r
623 if ($keyword == 'internal' && (!isset($_phpDocumentor_setting['parseprivate']) || $_phpDocumentor_setting['parseprivate'] == 'off')) return;
\r
624 if (!isset($this->tags[$keyword])) {
\r
625 $this->tags[$keyword] = array();
\r
627 $ptag = 'parserTag';
\r
628 if (class_exists('parser'.$keyword.'tag'))
\r
629 $ptag = 'parser'.ucfirst($keyword).'Tag';
\r
630 array_unshift($this->tags[$keyword], new $ptag($keyword, $value));
\r
635 * adds an @example tag
\r
636 * @param string contents of the tag
\r
637 * @param string path to the file containing this tag
\r
639 function addExample($value, $path)
\r
641 $this->tags['example'][] = new parserExampleTag($value, $path);
\r
645 * adds an unknown tag to the {@link $unknown_tags} array for use by custom converters
\r
646 * @param string tag name
\r
647 * @param string tag value
\r
649 function addUnknownTag($keyword, $value)
\r
651 addWarning(PDERROR_UNKNOWN_TAG,$keyword);
\r
652 $this->unknown_tags[$keyword][] = new parserTag($keyword, $value);
\r
656 * set the element's package to the passed values. Used in {@link phpDocumentor_IntermediateParser} to align package of
\r
657 * elements inside a class or procedural page to the package of the class/procedural page
\r
661 * @param string element name
\r
662 * @param string element type (include, define, var, method, global, function, const)
\r
664 function overridePackage($category, $package,$subpackage,$elname,$type)
\r
666 if ($this->package != $GLOBALS['phpDocumentor_DefaultPackageName'])
\r
668 addError(PDERROR_OVERRIDDEN_PACKAGE_TAGS,$elname,$type,$this->package);
\r
669 $this->explicitpackage = false;
\r
671 if (!empty($this->subpackage))
\r
672 addError(PDERROR_OVERRIDDEN_SUBPACKAGE_TAGS,$type,$elname,$this->subpackage);
\r
673 $this->package = $GLOBALS['phpDocumentor_DefaultPackageName'];
\r
674 $this->subpackage = '';
\r
675 $this->category = $category;
\r
676 $this->addPackage('package',$package);
\r
677 $this->addPackage('subpackage',$subpackage);
\r
681 * Used if this docblock has a @package tag.
\r
683 * phpDocumentor will guess package for DocBlocks that don't have
\r
685 * @uses $explicitpackage
\r
687 function setExplicitPackage()
\r
689 $this->explicitpackage = true;
\r
693 * If the DocBlock has a @package tag, then this returns true
\r
696 function getExplicitPackage()
\r
698 return $this->explicitpackage;
\r
702 * Used if this docblock has a @category tag.
\r
704 * phpDocumentor will guess category for DocBlocks that don't have
\r
706 * @uses $explicitcategory
\r
708 function setExplicitCategory()
\r
710 $this->explicitcategory = true;
\r
714 * If the DocBlock has a @category tag, then this returns true
\r
717 function getExplicitCategory()
\r
719 return $this->explicitcategory;
\r
723 * @param string $keyword tag name (either package or subpackage)
\r
724 * @param mixed $value either a string or a parserStringWithInlineTags. Strips all inline tags and use the text as the package
\r
726 function addPackage($keyword, $value)
\r
728 if ($keyword == 'package')
\r
730 if (!$this->explicitpackage)
\r
732 if (!is_string($value))
\r
733 $value = $value->getString();
\r
735 $value = explode(' ',$value);
\r
736 if (count($value) - 1)
\r
739 $value = trim($value[0]);
\r
741 $rest = implode($rest,' ');
\r
744 $value = explode("\t",$value[0]);
\r
745 if (count($value) - 1)
\r
748 $value = trim($value[0]);
\r
750 $rest = implode($rest,"\t");
\r
751 } else $value = trim($value[0]);
\r
753 $value = preg_replace('/[^\[\]0-9\-a-zA-Z_\x7f-\xff]/', '-', $value);
\r
754 $this->packagedescrip = $this->package = trim($value);
\r
755 if (!empty($rest)) $this->packagedescrip = $rest;
\r
758 if (is_string($value))
\r
759 addError(PDERROR_MULTIPLE_PACKAGE_TAGS,$value);
\r
761 addError(PDERROR_MULTIPLE_PACKAGE_TAGS,$value->getString());
\r
763 } elseif ($keyword == 'subpackage')
\r
765 if (empty($this->subpackage))
\r
767 if (!is_string($value))
\r
768 $value = $value->getString();
\r
770 $value = explode(' ',$value);
\r
771 if (count($value) - 1)
\r
774 $value = $value[0];
\r
776 $rest = implode($rest,' ');
\r
779 $value = explode("\t",$value[0]);
\r
780 if (count($value) - 1)
\r
783 $value = $value[0];
\r
785 $rest = implode($rest,"\t");
\r
786 } else $value = $value[0];
\r
788 if (!empty($value))
\r
790 $value = preg_replace('/[^\[\]0-9\-a-zA-Z_\x7f-\xff]/', '-', $value);
\r
792 $this->subpackage = trim($value);
\r
793 if (!empty($rest)) $this->subpackagedescrip = $rest;
\r
796 if (is_string($value))
\r
797 addError(PDERROR_MULTIPLE_SUBPACKAGE_TAGS,$value);
\r
799 addError(PDERROR_MULTIPLE_SUBPACKAGE_TAGS,$value->getString());
\r
801 } elseif ($keyword == 'category')
\r
803 if (!$this->explicitcategory)
\r
805 if (!is_string($value))
\r
806 $value = $value->getString();
\r
807 $value = preg_replace('/[^\[\]0-9\-a-zA-Z_\x7f-\xff]/', '-', $value);
\r
808 $this->category = $value;
\r
811 if (is_string($value))
\r
812 addError(PDERROR_MULTIPLE_CATEGORY_TAGS,$value);
\r
814 addError(PDERROR_MULTIPLE_CATEGORY_TAGS,$value->getString());
\r
820 * Adds a @name tag to the tag list
\r
821 * @param string new name of element
\r
823 function addName($value)
\r
825 if (is_object($value)) $value = $value->getString();
\r
826 if (!$this->hasname)
\r
828 $x = new parserNameTag('name',$value);
\r
829 $this->hasname = true;
\r
830 $this->tags['name'][] = $x;
\r
833 addError(PDERROR_MULTIPLE_NAME_TAGS,$value);
\r
838 * @param string if empty, staticvar is indexed in the order received and set using {@link changeStatic()}
\r
839 * @param string data type
\r
840 * @param parserStringWithInlineTags
\r
842 function addStaticVar($staticvar, $type, $descrip)
\r
844 if (empty($staticvar))
\r
845 $this->statics[] = new parserStaticvarTag($type,$descrip);
\r
847 $this->statics[$staticvar] = new parserStaticvarTag($type,$descrip);
\r
851 * adds a function declaration of @global to the {@link $funcglobals} array
\r
852 * @param string global type
\r
853 * @param string description of how the global is used in the function
\r
855 function addFuncGlobal($type,$value)
\r
857 $this->funcglobals[] = array($type,$value);
\r
861 * @param integer $index index of parameter in the {@link $funcglobals} array
\r
862 * @param string $name name of the parameter to set in the $funcglobals array
\r
864 function changeGlobal($index,$name)
\r
866 $this->funcglobals[$name] = $this->funcglobals[$index];
\r
867 unset($this->funcglobals[$index]);
\r
871 * @param integer $index index of parameter in the {@link $statics} array
\r
872 * @param string $name name of the parameter to set in the $statics array
\r
874 function changeStatic($index,$name)
\r
876 $this->statics[$name] = $this->statics[$index];
\r
877 unset($this->statics[$index]);
\r
881 * replaces nameless global variables in the {@link $funcglobals} array with their names
\r
884 function updateGlobals($funcs)
\r
886 for($i=0;$i<count($funcs);$i++)
\r
888 if (isset($this->funcglobals[$i]))
\r
890 $this->changeGlobal($i,$funcs[$i]);
\r
896 * replaces nameless static variables in the {@link $statics} array with their names
\r
899 function updateStatics($funcs)
\r
901 for($i=0;$i<count($funcs);$i++)
\r
903 if (isset($this->statics[$i]))
\r
905 $this->changeStatic($i,$funcs[$i]);
\r
911 * add an @access tag to the {@link tags} array
\r
912 * @param string should be either public or private
\r
914 function addAccess($value)
\r
916 if (is_object($value)) $value = $value->getString();
\r
917 $value = strtolower($value);
\r
918 if (!$this->hasaccess)
\r
920 $x = new parserAccessTag($value);
\r
923 $this->hasaccess = true;
\r
924 $this->tags['access'][] = $x;
\r
928 if (is_string($value))
\r
929 addError(PDERROR_MULTIPLE_ACCESS_TAGS,$value);
\r
931 addError(PDERROR_MULTIPLE_ACCESS_TAGS,$value->getString());
\r
936 * Adds a new @filesource tag to the DocBlock
\r
937 * @tutorial tags.filesource.pkg
\r
938 * @param string full path to the file
\r
939 * @param array tokenized source code, ordered by line number
\r
941 function addFileSource($path, $source)
\r
943 if (isset($this->tags['filesource'])) return;
\r
944 $this->tags['filesource'][] = new parserFileSourceTag($path, $source);
\r
948 * creates a {@link parserLinkTag} and adds it to the {@link $tags} array
\r
949 * @param string $link
\r
951 function addLink($link)
\r
953 if (phpDocumentor_setup::checkIgnoreTag('@link')) return;
\r
954 $this->tags['link'][] = new parserLinkTag($link);
\r
958 * creates a {@link parserLinkTag} and adds it to the {@link $tags} array
\r
959 * @param string either see or uses
\r
960 * @param string $value
\r
962 function addSee($keyword,$value)
\r
964 if (phpDocumentor_setup::checkIgnoreTag($keyword)) return;
\r
965 $tag = 'parser'.ucfirst($keyword).'Tag';
\r
966 $this->tags[$keyword][] = new $tag($value);
\r
970 * creates a {@link parserReturnTag} and adds it to the {@link $tags} array
\r
971 * @param string $returnType the one-word name of the return type (mixed should be used if more than one type)
\r
972 * @param parserStringWithInlineTags $value
\r
974 function addReturn($returnType, $value)
\r
976 // only take the first one
\r
977 if (!$this->return)
\r
979 $this->return = new parserReturnTag($returnType, $value);
\r
982 addError(PDERROR_MULTIPLE_RETURN_TAGS,$returnType,$value->getString());
\r
987 * creates a {@link parserVarTag} and adds it to the {@link $tags} array
\r
988 * @param string $varType the one-word name of the variable type (mixed should be used if more than one type)
\r
989 * @param parserStringWithInlineTags $value
\r
991 function addVar($varType, $value)
\r
993 // only take the first one
\r
996 $this->var = new parserVarTag($varType, $value);
\r
999 addError(PDERROR_MULTIPLE_VAR_TAGS,$varType,$value->getString());
\r
1004 * Adds a virtual @usedby tag to output
\r
1005 * @param abstractLink link to the element that has a @uses tag
\r
1006 * @param parserStringWithInlinetags description of how the elements uses
\r
1010 function addUsedBy($link, $descrip)
\r
1012 $this->tags['usedby'][] = new parserUsedByTag($link, $descrip);
\r
1016 * Add a @uses tag to the DocBlock
\r
1017 * @param string @see-style text, used for {@link Converter::getLink()}
\r
1018 * @param parserStringWithInlineTags description of how the used element is
\r
1020 * @tutorial tags.uses.pkg
\r
1022 function addUses($seeel, $description)
\r
1024 $this->tags['uses'][] = new parserUsesTag($seeel, $description);
\r
1025 usort($this->tags['uses'], array($this, '_sortUses'));
\r
1029 * Adds a @property(-read or -write) or @method magic tag to the DocBlock
\r
1031 function addProperty( $tagName, $propertyName, $propertyType, $value )
\r
1033 if ( empty( $propertyName ) )
\r
1035 addWarning ( PDERROR_MISSING_PROPERTY_TAG_NAME, $tagName, $tagName, $propertyType, $value->getString() );
\r
1039 switch ( $tagName )
\r
1042 $this->properties[ $propertyName ] = new parserPropertyTag( $propertyType, $value );
\r
1044 case 'property-read':
\r
1045 $this->properties[ $propertyName ] = new parserPropertyReadTag( $propertyType, $value );
\r
1047 case 'property-write':
\r
1048 $this->properties[ $propertyName ] = new parserPropertyWriteTag( $propertyType, $value );
\r
1051 $this->properties[ $propertyName ] = new parserMethodTag( $propertyType, $value );
\r
1058 * Custom sorting function for sorting @uses tags
\r
1060 * @param parserTag $a
\r
1061 * @param parserTag $b
\r
1065 function _sortUses($a, $b)
\r
1067 return strnatcasecmp($a->getString(), $b->getString());
\r
1072 * @return mixed false if no keyword, unconverted value if one keyword, array of unconverted values if more than one keyword
\r
1074 function getKeyword($keyword)
\r
1076 if ($keyword == 'filesource' && !$this->_canSource) return false;
\r
1077 if (isset($this->tags[$keyword]))
\r
1079 if (count($this->tags[$keyword]) == 1)
\r
1081 return $this->tags[$keyword][0];
\r
1082 } else return $this->tags[$keyword];
\r
1083 } else return false;
\r
1087 * @return array Format: array('var' => tag name, 'data' => unconverted tag value)
\r
1089 function listParams()
\r
1091 if (isset($this->params))
\r
1094 foreach($this->params as $key => $val)
\r
1096 $ret[] = array("var" => ucfirst($key),"data" => $val);
\r
1105 * @return array Format: array('var' => tag name, 'data' => unconverted tag value)
\r
1107 function listProperties()
\r
1110 if (isset($this->properties))
\r
1112 foreach($this->properties as $key => $val)
\r
1114 $ret[] = array("var" => ucfirst($key),"data" => $val);
\r
1121 * @param Converter
\r
1123 function listTags()
\r
1126 foreach($this->tags as $keyword => $vals)
\r
1128 if ($keyword == 'filesource' && !$this->_canSource) continue;
\r
1129 foreach($vals as $val)
\r
1134 usort($tags,'tagsort');
\r
1138 /** @return string always 'docblock' */
\r
1139 function getType()
\r
1141 return 'docblock';
\r
1146 * Determines the arbitrary tag rank value for a given tag
\r
1149 function getTagRanking($tag)
\r
1151 switch(phpDocumentor_get_class($tag))
\r
1153 case 'parserreturntag' :
\r
1156 case 'parservartag' :
\r
1159 case 'parsertutorialtag' :
\r
1162 case 'parserstaticvartag' :
\r
1165 case 'parserseetag' :
\r
1168 case 'parserlinktag' :
\r
1171 case 'parsertag' :
\r
1172 switch ($tag->keyword)
\r
1180 case 'copyright' :
\r
1183 case 'deprecated' :
\r
1199 case 'parseraccesstag' :
\r
1202 case 'parsernametag' :
\r
1213 * Utilizes the getTagRanking method to determine tag sort order of two given tags
\r
1216 function tagsort($a, $b)
\r
1219 $o = getTagRanking($a);
\r
1220 $p = getTagRanking($b);
\r
1221 if ($o == $p) return 0;
\r
1222 if ($o < $p) return -1;
\r
1223 if ($o > $p) return 1;
\r