cvs: pear /PHP_Parser/Parser/DocBlock DefaultInlineTagLexer.php DefaultInlineTagParser.php DefaultTagLexer.php DefaultTagParser.php
| From: | Greg Beaver | Date: | Sat, 13 Mar 2004 06:35:49 +0000 |
| Subject: | cvs: pear /PHP_Parser/Parser/DocBlock DefaultInlineTagLexer.php DefaultInlineTagParser.php DefaultTagLexer.php DefaultTagParser.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-17362@lists.php.net to get a copy of this message | ||
cellog Sat Mar 13 01:35:49 2004 EDT
Added files:
/pear/PHP_Parser/Parser/DocBlock DefaultInlineTagLexer.php
DefaultInlineTagParser.php
DefaultTagLexer.php
DefaultTagParser.php
Log:
new tag/inline tag lexing/parsing
http://cvs.php.net/co.php/pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagLexer.php?r=1.1&p=1 Index: pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagLexer.php +++ pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagLexer.php <?php /** * @package PHP_Parser */ class PHP_Parser_DocBlock_DefaultInlineTagLexer { /** * Run-time options * @access protected * @var array */ var $_options = array(); /** * @var string * @access private */ var $_buf; /** * @var integer * @access private */ var $_index; /** * Indicates whether the current Inline Tag contains separate sections * * This parameter is a flag used to determine whether the input buffer * has been split into sections such as what happens in a {@}link} tag. * (Sections are delimited by commas.) * @var boolean */ var $_multipleBuffers = false; /** * Mapping of inline tag field types to lexer function name * * Use this array to extend the inlinetag parser, simply add a mapping of * typename => lexer function name. The function name must exist or * an exception will be thrown * @access protected */ var $_typeMap = array( 'word' => 'getWord', 'link' => 'getLink', 'multi-word' => 'getWords', 'allwords' => 'getAllWords', ); /** * return something useful, when a parse error occurs. * * used to build error messages if the parser fails, and needs to know the line number.. * * @return string * @access public */ function parseError() { return "Error at line {$this->yyline}"; } /** * Set Lexer options * * Valid options are * - separator: this is a string or false. If it is * a string, then the lexer will assume * the inline tag can have multiple * values, and will split the contents * on the separator, and loop over each * segment as if it were a separate tag * @param array */ function setOptions($options = array()) { $this->_options['separator'] = false; $this->_options = array_merge($this->_options, $options); } /** * Return a link expected by phpDocumentor * * This will be either 1 or two words. This is to * allow links like "function mine()" and so on * @return false|string */ function getLink() { // must have at least 1 word to be a valid link $ret = $this->getWord(); if (!$ret) { return false; } $save = $ret; if (strpos($ret, '#')) { $ret = substr($ret, strpos($ret, '#') + 1); // chop off package selector } // if the word is function or global if (in_array($ret, array('function', 'global'))) { $ret = $save; if ($this->_readBuf(false)) { $ret .= $ret . ' ' . $this->_readBuf(); } else { return false; } } else { return $save; } return $ret; } /** * Retrieve the next word from the tag contents * @return string|false */ function getWord() { return $this->_readBuf(); } /** * Retrieve multiple words from the tag contents * @param integer the number of words to return * @return false|string */ function getWords($param) { $count = $param['count']; $ret = ''; for ($i = 0; $i < $count; $i++) { if ($word = $this->_readBuf(true, true)) { $ret .= $word; } } return rtrim($ret); } /** * Retrieve all remaining words from the tag contents * @return string|false */ function getAllWords() { $ret = ''; while ($word = $this->_readBuf(true)) { if ($ret != '') { $ret .= ' '; } $ret .= $word; } if ($ret == '') { return false; } else { return $ret; } } /** * Read a word from the buffer * @param boolean whether to increment the index into the buffer * @param boolean whether to include whitespace * @access private */ function _readBuf($inc = true, $whitespace = false) { $index = $this->_index; $buf = $this->_getBuf(); if ($inc) { $this->_index++; } if (!isset($buf[1][$index])) { return null; } if ($whitespace) { return $buf[0][$index]; } return $buf[1][$index]; } /** * Returns true if there is another segment of the multi-segment * inline tag to parse. * @return boolean */ function hasNextBuf() { if (!$this->_multipleBuffers) { return false; } if (!isset($this->_buf[$this->_bufIndex][0][$this->_index]) && !isset($this->_buf[$this->_bufIndex + 1])) { return false; } return $this->_bufIndex < count($this->_buf); } /** * Move to next buffer in the multi-section tag * @return boolean Success is returned */ function moveNextBuf() { if (isset($this->_buf[++$this->_bufIndex][0])) { $this->_index = 0; return $this->_buf[$this->_bufIndex]; } else { return false; } } /** * Return the input buffer * * For single-segment inline tags, this returns the whole buffer. For * multi-segment inline tags, this returns the current buffer, or if it * is empty, returns the next one * @return array */ function _getBuf() { if ($this->_multipleBuffers) { if (isset($this->_buf[$this->_bufIndex][0][$this->_index])) { return $this->_buf[$this->_bufIndex]; } else { return false; } } else { return $this->_buf; } } /** * Prepare inline tag contents for lexing. * * This function replaces the current buffer with the data after * splitting it along whitespace, and along any separators * passed to {@link setOptions()} * @param string */ function newTag($data) { $data = ltrim($data); if ($this->_options['separator']) { $data2 = explode($this->_options['separator'], $data); $this->_bufIndex = 0; foreach($data2 as $data) { // strip open and close {@ } and collapse all whitespace preg_match_all('/([^\s]+)(\s+)?/', ltrim($data), $this->_buf[$this->_bufIndex++]); // $this->_buf[$this->_bufIndex++] = preg_split("/\s+/", ltrim($data)); } $this->_bufIndex = 0; $this->_multipleBuffers = true; } else { // strip open and close {@ } and collapse all whitespace preg_match_all('/([^\s]+)(\s+)?/', ltrim($data), $this->_buf); } $this->_index = 0; } /** * Passes data to {@link newTag()} * @var string */ function PHP_Parser_DocBlock_DefaultInlineTagLexer($data = '') { $this->debug = false; $this->setOptions(); $this->newTag($data); } } http://cvs.php.net/co.php/pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagParser.php?r=1.1&p=1 Index: pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagParser.php +++ pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagParser.php <?php /** * @package PHP_Parser */ class PHP_Parser_DocBlock_DefaultInlineTagParser { /** * Run-time options * @access protected * @var array */ var $_options = array(); /** * @var array * @access protected */ var $_loadedTags = array(); function PHP_Parser_DocBlock_DefaultInlineTagParser($options = array()) { $this->_options['taglocation'] = 'PHP/Parser/DocBlock/InlineTags/'; $this->_options['tagprefix'] = 'PHP_Parser_DocBlock_InlineTags_'; $this->_options['taglexer'] = 'PHP_Parser_DocBlock_DefaultInlineTagLexer'; $this->_options = array_merge($this->_options, $options); if (is_object($this->_options['taglexer']) || (is_string($this->_options['taglexer']) && !class_exists($this->_options['taglexer']))) { $this->_options['taglexer'] = false; } } /** * @param string inline tag name * @param string inline tag contents * @return object|array returns either a user-specified tag class, or an unparsed array */ function parseInlineTag($name, $contents) { if (!($lexer = $this->_options['taglexer'])) { return false; } elseif (is_string($lexer)) { $lexer = new $lexer($contents); if (!is_a($lexer, 'PHP_Parser_DocBlock_DefaultInlineTagLexer')) { return false; } } $name = strtolower($name); $a = $this->_getLoadedTag($name); if (is_array($a) && !count($a)) { $return = $this->_loadInlineTag($name); if ($return) { return $return; } } $a = $this->_getLoadedTag($name); if (!$a) { return array('tag' => $name, 'contents' => $contents); } $structure = $a['structure']; $tagname = $a['class']; $inlinetag = new $tagname; if (!is_a($inlinetag, 'PHP_Parser_DocBlock_InlineTags_Base')) { return false; } if (!count($structure['params'])) { // tags like {@inheritdoc} have no params return $inlinetag; } $lexer->setOptions($lexoptions = $inlinetag->getLexerOptions()); $lexer->newTag($contents); foreach($structure['params'] as $param) { $setparam = 'set' . $param['name']; if (!isset($lexer->_typeMap[$param['type']])) { // throw exception } $handler = $lexer->_typeMap[$param['type']]; if (!method_exists($lexer, $handler)) { // throw exception } if (isset($lexoptions['separator'])) { $val = $this->_getMultiOptions($lexer, $handler, $param); } else { $val = $lexer->$handler($param); } if ($param['required'] && !$val) { return false; } $e = $inlinetag->$setparam($val); if (PEAR::isError($e)) { return $e; } } return $inlinetag; } function _getMultiOptions(&$lexer, $handler, $param) { $val = array(); while ($lexer->hasNextBuf()) { $val[] = $lexer->$handler($param); if (!$lexer->moveNextBuf()) { break; } } return $val; } /** * Load the file containing an inline tag class. * * In phpDocumentor version 2.x, inline tags can be located in one of * two locations, which are specified in the options passed to * the constructor. The first location is a user-specified location * which is designed to allow multi-user installations with a central * phpDocumentor install to specify a local location for inline tag files. * * User A, for example, may have a specialized inline tag {@homepage} that * spits out a project homepage. This tag is located in ~A/itags/homepage.php. * The user will pass this location on the command-line as the location to * search for user-defined tags. By default, phpDocumentor will look for a * PhpDocumentor_Structures_DocBlock_InlineTags_Homepage class. This can * also be changed so that a shorter classname may be used. * * This flexibility allows users to extend phpDocumentor in ways we haven't * imagined without breaking forward compatibility to future phpDocumentor * versions. * * Every inline tag class must specify the tag structure in an array * returned by function getTagStructure(). * @param string * @return null|array null on successful tag load, an array with failed parse * if the tag is not loaded successfully */ function _loadInlineTag($name) { if (!class_exists($this->_options['tagprefix'] . ucfirst($name)) && !class_exists('PHP_Parser_DocBlock_InlineTags_' . ucfirst($name))) { // try to include it $filename = $this->_options['taglocation'] . ucfirst($name) . '.php'; if (PhpDocumentor::isIncludeable($filename)) { include_once($filename); } if (!class_exists($this->_options['tagprefix'] . ucfirst($name)) && !class_exists('PHP_Parser_DocBlock_InlineTags_' . ucfirst($name))) { $filename = 'PHP_Parser_DocBlock_InlineTags_' . ucfirst($name) . '.php'; if (PhpDocumentor::isIncludeable($filename)) { include_once($filename); } } } // try the user tagname first if (class_exists($this->_options['tagprefix'] . ucfirst($name))) { $this->_setLoadedTag($name, array('class' => $this->_options['tagprefix'] . ucfirst($name))); if (!in_array('gettagstructure', get_class_methods($this->_options['tagprefix'] . ucfirst($name)))) { $this->_setLoadedTag($name, false); return false; } else { $a = $this->_getLoadedTag($name); $a['structure'] = call_user_func(array($a['class'], 'structure')); $this->_setLoadedTag($name, $a); } } elseif (class_exists('PHP_Parser_DocBlock_InlineTags_' . ucfirst($name))) { $this->_setLoadedTag($name, array('class' => 'PHP_Parser_DocBlock_InlineTags_' . ucfirst($name))); if (!in_array('gettagstructure', get_class_methods('PHP_Parser_DocBlock_InlineTags_' . ucfirst($name)))) { $this->_setLoadedTag($name, false); return false; } else { $a = $this->_getLoadedTag($name); $a['structure'] = call_user_func(array($a['class'], 'structure')); $this->_setLoadedTag($name, $a); } } return false; } function _getLoadedTag($tagname) { if (!isset($this->_loadedTags[$tagname])) { return array(); } return $this->_loadedTags[$tagname]; } function _setLoadedTag($tagname, $value) { $this->_loadedTags[$tagname] = $value; } } ?> http://cvs.php.net/co.php/pear/PHP_Parser/Parser/DocBlock/DefaultTagLexer.php?r=1.1&p=1 Index: pear/PHP_Parser/Parser/DocBlock/DefaultTagLexer.php +++ pear/PHP_Parser/Parser/DocBlock/DefaultTagLexer.php <?php /** * @package PHP_Parser */ class PHP_Parser_DocBlock_DefaultTagLexer { /** * @var string */ var $_buf; /** * @var integer */ var $_index; /** * Indicates whether the current Tag contains separate sections * * This parameter is a flag used to determine whether the input buffer * has been split into sections such as what happens in a @see tag. * Sections are delimited by commas. * @var boolean */ var $_multipleBuffers = false; /** * Mapping of tag field types to lexer function name * * Use this array to extend the tag parser, simply add a mapping of * typename => lexer function name. The function name must exist or * an exception will be thrown * @access protected */ var $_typeMap = array( 'desc' => 'getDesc', 'type' => 'getType', 'var' => 'getVar', 'typewithvar' => 'getTypeWithVar', 'word' => 'getWord', 'link' => 'getLink', 'multi-word' => 'getWords', 'allwords' => 'getAllWords', 'authoremails' => 'getAuthorEmails', ); /** * return something useful, when a parse error occurs. * * used to build error messages if the parser fails, and needs to know the line number.. * * @return string * @access public */ function parseError() { return "Error at line {$this->yyline}"; } /** * Set Lexer options * * Valid options are * - separator: this is a string or false. If it is * a string, then the lexer will assume * the inline tag can have multiple * values, and will split the contents * on the separator, and loop over each * segment as if it were a separate tag * @param array */ function setOptions($options = array()) { $this->_options['descParserClass'] = $this->_options['descLexerClass'] = false; $this->_options['lineNumber'] = 1; $this->_options = array_merge($this->_options, $options); if (!is_object($this->_options['descParserClass']) || !is_object($this->_options['descLexerClass'])) { return false; } } /** * Retrieve the next word from the tag contents * @return string|false */ function getWord() { return $this->_readBuf(); } /** * Retrieve multiple words from the tag contents * @param integer the number of words to return * @return false|string */ function getWords($param) { $count = $param['count']; $ret = ''; for ($i = 0; $i < $count; $i++) { if ($word = $this->_readBuf(true, true)) { $ret .= $word; } } return rtrim($ret); } /** * Retrieve all remaining words from the tag contents * @return string|false */ function getAllWords() { $ret = ''; while ($word = $this->_readBuf(true, true)) { $ret .= $word; } if ($ret == '') { return false; } else { return $ret; } } /** * Return a long description * * This returns the results of parsing * @return false|object|array */ function getDesc() { $desc = $this->getAllWords(); return $this->_parseDesc($desc); } /** * Return the description section from an @author tag * * Handles emails like <cellog@users.sourceforge.net>, converting them into * inline links */ function getAuthorEmails() { $desc = $this->getAllWords(); // replace emails with an inline link before processing $desc = preg_replace('/<([a-zA-Z0-9\._-]+\@[a-zA-Z0-9\-\.]+\.' . '(?:[a-zA-Z]{2,4}|[0-9]{1,3}))>/', '<{@link mailto:\\1 \\1}>', $desc); return $this->_parseDesc($desc); } /** * Parse a description for inline tags/HTML * @param string * @access private * @return array */ function _parseDesc($desc) { $lex = $this->_options['descLexerClass']; $parser = $this->_options['descParserClass']; $description = $parser->parse( array('lexer' => $lex, 'nosummary' => true, 'tagdesc' => true, 'comment' => $desc, 'commentline' => $this->_options['lineNumber'], 'commenttoken' => false )); return $description['documentation']; } /** * Return a type array like array("array") or * array("array", "object PhpDocumentor"). * * All valid types must begin with a letter or underscore. Anything else is * assumed to be a variable name or description * @return false|object|array */ function getType() { // need at least 1 word to be a valid type $word = $this->getWord(); if (!$word) { return false; } $types = array(); $typeindex = 0; if ($word == 'object') { $types[$typeindex] .= $word; $word = $this->getWord(); if (!$word) { // found the complete type return $types; } // this checks for object classname. Classname may only begin // with alphanumeric and _ if (!preg_match('/[a-zA-Z_]/', $word{0})) { $this->_index--; return $types; } else { // prepare for addition of classname $types[$typeindex] = ' '; } } $done = false; do { // this loop checks for type|type|type and for // type|object classname|type|object classname2 if (!preg_match('/[a-zA-Z_]/', $word{0})) { break; } if (strpos($word, '|')) { if (!isset($types[$typeindex])) { $types[$typeindex] = ''; } $temptypes = explode('|', $word); while (count($temptypes) - 1) { if (!isset($types[$typeindex])) { $types[$typeindex] = ''; } // grab all but the last type into its own array $types[$typeindex++] .= array_shift($temptypes); } if (!isset($types[$typeindex])) { $types[$typeindex] = ''; } // this is just in case we have type1|type2|object classname // it will not increment $typeindex $types[$typeindex] .= $word = array_shift($temptypes); if ($word != 'object') { // we're done if (!count($types)) { return false; } return $types; } else { $typeindex++; } } else { if (!isset($types[$typeindex])) { $types[$typeindex] = ''; } if (!preg_match('/[a-zA-Z_]/', $word{0})) { $this->_index--; if (!count($types)) { return false; } return $types; } else { $types[$typeindex] .= $word; } return $types; } $word = $this->getWord(); } while ($word); if (!count($types)) { return false; } return $types; } /** * Retrieve a type and optional variable name. * * This uses {@link getType()} to retrieve the type portion, and then uses * {@link getVar()} to retrieve the variable name portion * @return array Format: array('types' => type array|false, 'var' => * false|variable) */ function getTypeWithVar() { return array('types' => $this->getType(), 'var' => $this->getVar()); } /** * Retrieve an optional variable name * * This checks the next word to see if it is begins with $ or &$, and * returns it as a variable name if so. * @return string|false */ function getVar() { $word = $this->getWord(); if ($word) { if (!preg_match('/^(?:\$|&\$)/', $word)) { $word = false; $this->_index--; } } return $word; } /** * Return a link expected by phpDocumentor * * This will be either 1 or two words. This is to * allow links like "function mine()" and so on * @return false|string */ function getLink() { // must have at least 1 word to be a valid link $ret = $this->getWord(); if (!$ret) { return false; } $save = $ret; if (strpos($ret, '#')) { $ret = substr($ret, strpos($ret, '#') + 1); // chop off package selector } // if the word is function or global if (in_array($ret, array('function', 'global'))) { if ($this->_readBuf(false)) { $ret = $save; $ret .= ' ' . $this->_readBuf(); return $ret; } else { return false; } } else { return $save; } } /** * Read a word from the buffer * @param boolean whether to increment the index into the buffer * @param boolean whether to include whitespace * @access private */ function _readBuf($inc = true, $whitespace = false) { $index = $this->_index; $buf = $this->_getBuf(); if ($inc) { $this->_index++; } if (!isset($buf[1][$index])) { return null; } if ($whitespace) { return $buf[0][$index]; } return $buf[1][$index]; } /** * Returns true if there is another segment of the multi-segment * inline tag to parse. * @return boolean */ function hasNextBuf() { if (!$this->_multipleBuffers) { return false; } if (!isset($this->_buf[$this->_bufIndex][0][$this->_index]) && !isset($this->_buf[$this->_bufIndex + 1])) { return false; } return $this->_bufIndex < count($this->_buf); } /** * Move to next buffer in the multi-section tag * @return boolean Success is returned */ function moveNextBuf() { if (isset($this->_buf[++$this->_bufIndex][0])) { $this->_index = 0; return $this->_buf[$this->_bufIndex]; } else { return false; } } /** * Return the input buffer * * For single-segment tags, this returns the whole buffer. For * multi-segment tags, this returns the current buffer, or if it * is empty, returns the next one * @return array */ function _getBuf() { if ($this->_multipleBuffers) { if (isset($this->_buf[$this->_bufIndex][0][$this->_index])) { return $this->_buf[$this->_bufIndex]; } else { return false; } } else { return $this->_buf; } } /** * Prepare tag contents for lexing. * * This function replaces the current buffer with the data after * splitting it along whitespace, and along any separators * passed to {@link setOptions()} * @param string */ function newTag($data) { $data = ltrim($data); if ($this->_options['separator']) { $data2 = explode($this->_options['separator'], $data); $this->_bufIndex = 0; foreach($data2 as $data) { // strip out all whitespace preg_match_all('/([^\s]+)(\s+)?/', ltrim($data), $this->_buf[$this->_bufIndex++]); // $this->_buf[$this->_bufIndex++] = preg_split("/\s+/", ltrim($data)); } $this->_bufIndex = 0; $this->_multipleBuffers = true; } else { $this->_multipleBuffers = false; // strip out all whitespace preg_match_all('/([^\s]+)(\s+)?/', ltrim($data), $this->_buf); // $this->_buf = preg_split("/\s+/", $data); } $this->_index = 0; } /** * Passes data to {@link newTag()} * @var string */ function PHP_Parser_DocBlock_DefaultTagLexer($data = '') { $this->debug = false; if (!empty($data)) { $this->setOptions(); $this->newTag($data); } } } http://cvs.php.net/co.php/pear/PHP_Parser/Parser/DocBlock/DefaultTagParser.php?r=1.1&p=1 Index: pear/PHP_Parser/Parser/DocBlock/DefaultTagParser.php +++ pear/PHP_Parser/Parser/DocBlock/DefaultTagParser.php <?php /** * @package PHP_Parser */ class PHP_Parser_DocBlock_DefaultTagParser { /** * Run-time options * @access protected * @var array */ var $_options = array(); /** * @var array * @access protected */ var $_loadedTags = array(); function PHP_Parser_DocBlock_DefaultTagParser($options = array()) { $this->_options['taglocation'] = 'PHP/Parser/DocBlock/Tags/'; $this->_options['tagprefix'] = 'PHP_Parser_DocBlock_Tags_'; $this->_options['lexeroptions'] = array(); $this->_options['taglexer'] = 'PHP_Parser_DocBlock_DefaultTagLexer'; $this->_options = array_merge($this->_options, $options); if (is_object($this->_options['taglexer']) || (is_string($this->_options['taglexer']) && !class_exists($this->_options['TagLexer']))) { $this->_options['taglexer'] = 'PHP_Parser_DocBlock_DefaultTagLexer'; } } /** * @param string inline tag name * @param string inline tag contents * @return object|array returns either a user-specified tag class, or an unparsed array */ function parseTag($name, $contents) { $lexer = $this->_options['taglexer']; if (is_string($lexer)) { $lexer = new $lexer; } $lexer->setOptions($this->_options['lexeroptions']); $name = strtolower($name); // attempt to load the tag parser class for this tag $a = $this->_getLoadedTag($name); if ($a === false) { return array('tag' => $name, 'contents' => $contents); } if (is_array($a) && !count($a)) { $return = $this->_loadTag($name); if ($return) { return $return; } } $a = $this->_getLoadedTag($name); if (is_array($a) && !count($a)) { return array('tag' => $name, 'contents' => $contents); } $structure = $a['structure']; $tagname = $a['class']; $tag = new $tagname; if (!is_a($tag, 'PHP_Parser_DocBlock_Tags_Base')) { return false; } if (!count($structure['params'])) { // tags like @abstract have no params return $tag; } $this->_options['lexeroptions']['separator'] = false; $lexer->setOptions(array_merge($this->_options['lexerOptions'], $lexoptions = $tag->getLexerOptions())); $lexer->newTag($contents); foreach($structure['params'] as $param) { $setparam = 'set' . $param['name']; if (!isset($lexer->_typeMap[$param['type']])) { // throw exception } $handler = $lexer->_typeMap[$param['type']]; if (!method_exists($lexer, $handler)) { // throw exception } if (isset($lexoptions['separator'])) { $val = $this->_getMultiOptions($lexer, $handler, $param); } else { $val = $lexer->$handler($param); } if ($param['required'] && !$val) { return false; } $e = $tag->$setparam($val); if (PEAR::isError($e)) { return $e; } } return $tag; } function _getMultiOptions(&$lexer, $handler, $param) { $val = array(); while ($lexer->hasNextBuf()) { $val[] = $lexer->$handler($param); if (!$lexer->moveNextBuf()) { break; } } return $val; } /** * Load the file containing a tag class. * * Tags can be located in one of two locations, * PHP/Parser/DocBlock/Tags/ or a user-specified location * which is designed to allow multi-user installations with a central * PHP_Parser install to specify a local location for tag files. * * User A, for example, may have a specialized tag @homepage that * spits out a project homepage. This tag is located in ~A/tags/homepage.php. * The user will pass this location on the command-line as the location to * search for user-defined tags. By default, PHP_Parser will look for a * PHP_Parser_DocBlock_Tags_Homepage class. This can * also be changed so that a shorter classname may be used. * * This flexibility allows users to extend PHP_Parser in ways we haven't * imagined without breaking forward compatibility to future PHP_Parser * versions. * * Every tag class must specify the tag structure in an array * returned by function structure() * @param string * @return null|array null on successful tag load, an array with failed parse * if the tag is not loaded successfully */ function _loadTag($name) { if (!class_exists($this->_options['tagprefix'] . ucfirst($name)) && !class_exists($this->_options['tagprefix'] . ucfirst($name))) { // try to include it $filename = $this->_options['defaultTagLocation'] . ucfirst($name) . '.php'; if (PhpDocumentor::isIncludeable($filename)) { include_once($filename); } if (!class_exists('PHP_Parser_DocBlock_Tags_' . ucfirst($name)) && !class_exists('PHP_Parser_DocBlock_Tags_' . ucfirst($name))) { $filename = 'PHP/Parser/DocBlock/Tags/' . ucfirst($name) . '.php'; if (PhpDocumentor::isIncludeable($filename)) { include_once($filename); } } } // try the user tagname first if (class_exists($this->_options['tagprefix'] . ucfirst($name))) { $this->_setLoadedTag($name, array('class' => $this->_options['tagprefix'] . ucfirst($name))); if (!in_array('structure', get_class_methods($this->_options['tagprefix'] . ucfirst($name)))) { // failure - doesn't have the structure() static method $this->_setLoadedTag($name, false); return false; } else { $a = $this->_getLoadedTag($name); $a['structure'] = call_user_func(array($a['class'], 'structure')); $this->_setLoadedTag($name, $a); } } elseif (class_exists($this->_options['tagprefix'] . ucfirst($name))) { $this->_setLoadedTag($name, array('class' => $this->_options['tagprefix'] . ucfirst($name))); if (!in_array('gettagstructure', get_class_methods($this->_options['tagprefix'] . ucfirst($name)))) { // failure - doesn't have the structure() static method $this->_setLoadedTag($name, false); return false; } else { $a = $this->_getLoadedTag($name); $a['structure'] = call_user_func(array($a['class'], 'structure')); $this->_setLoadedTag($name, $a); } } return false; } function _getLoadedTag($tagname) { if (!isset($this->_loadedTags[$tagname])) { return array(); } return $this->_loadedTags[$tagname]; } function _setLoadedTag($tagname, $value) { $this->_loadedTags[$tagname] = $value; } } ?>
http://cvs.php.net/co.php/pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagLexer.php?r=1.1&p=1 Index: pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagLexer.php +++ pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagLexer.php <?php /** * @package PHP_Parser */ class PHP_Parser_DocBlock_DefaultInlineTagLexer { /** * Run-time options * @access protected * @var array */ var $_options = array(); /** * @var string * @access private */ var $_buf; /** * @var integer * @access private */ var $_index; /** * Indicates whether the current Inline Tag contains separate sections * * This parameter is a flag used to determine whether the input buffer * has been split into sections such as what happens in a {@}link} tag. * (Sections are delimited by commas.) * @var boolean */ var $_multipleBuffers = false; /** * Mapping of inline tag field types to lexer function name * * Use this array to extend the inlinetag parser, simply add a mapping of * typename => lexer function name. The function name must exist or * an exception will be thrown * @access protected */ var $_typeMap = array( 'word' => 'getWord', 'link' => 'getLink', 'multi-word' => 'getWords', 'allwords' => 'getAllWords', ); /** * return something useful, when a parse error occurs. * * used to build error messages if the parser fails, and needs to know the line number.. * * @return string * @access public */ function parseError() { return "Error at line {$this->yyline}"; } /** * Set Lexer options * * Valid options are * - separator: this is a string or false. If it is * a string, then the lexer will assume * the inline tag can have multiple * values, and will split the contents * on the separator, and loop over each * segment as if it were a separate tag * @param array */ function setOptions($options = array()) { $this->_options['separator'] = false; $this->_options = array_merge($this->_options, $options); } /** * Return a link expected by phpDocumentor * * This will be either 1 or two words. This is to * allow links like "function mine()" and so on * @return false|string */ function getLink() { // must have at least 1 word to be a valid link $ret = $this->getWord(); if (!$ret) { return false; } $save = $ret; if (strpos($ret, '#')) { $ret = substr($ret, strpos($ret, '#') + 1); // chop off package selector } // if the word is function or global if (in_array($ret, array('function', 'global'))) { $ret = $save; if ($this->_readBuf(false)) { $ret .= $ret . ' ' . $this->_readBuf(); } else { return false; } } else { return $save; } return $ret; } /** * Retrieve the next word from the tag contents * @return string|false */ function getWord() { return $this->_readBuf(); } /** * Retrieve multiple words from the tag contents * @param integer the number of words to return * @return false|string */ function getWords($param) { $count = $param['count']; $ret = ''; for ($i = 0; $i < $count; $i++) { if ($word = $this->_readBuf(true, true)) { $ret .= $word; } } return rtrim($ret); } /** * Retrieve all remaining words from the tag contents * @return string|false */ function getAllWords() { $ret = ''; while ($word = $this->_readBuf(true)) { if ($ret != '') { $ret .= ' '; } $ret .= $word; } if ($ret == '') { return false; } else { return $ret; } } /** * Read a word from the buffer * @param boolean whether to increment the index into the buffer * @param boolean whether to include whitespace * @access private */ function _readBuf($inc = true, $whitespace = false) { $index = $this->_index; $buf = $this->_getBuf(); if ($inc) { $this->_index++; } if (!isset($buf[1][$index])) { return null; } if ($whitespace) { return $buf[0][$index]; } return $buf[1][$index]; } /** * Returns true if there is another segment of the multi-segment * inline tag to parse. * @return boolean */ function hasNextBuf() { if (!$this->_multipleBuffers) { return false; } if (!isset($this->_buf[$this->_bufIndex][0][$this->_index]) && !isset($this->_buf[$this->_bufIndex + 1])) { return false; } return $this->_bufIndex < count($this->_buf); } /** * Move to next buffer in the multi-section tag * @return boolean Success is returned */ function moveNextBuf() { if (isset($this->_buf[++$this->_bufIndex][0])) { $this->_index = 0; return $this->_buf[$this->_bufIndex]; } else { return false; } } /** * Return the input buffer * * For single-segment inline tags, this returns the whole buffer. For * multi-segment inline tags, this returns the current buffer, or if it * is empty, returns the next one * @return array */ function _getBuf() { if ($this->_multipleBuffers) { if (isset($this->_buf[$this->_bufIndex][0][$this->_index])) { return $this->_buf[$this->_bufIndex]; } else { return false; } } else { return $this->_buf; } } /** * Prepare inline tag contents for lexing. * * This function replaces the current buffer with the data after * splitting it along whitespace, and along any separators * passed to {@link setOptions()} * @param string */ function newTag($data) { $data = ltrim($data); if ($this->_options['separator']) { $data2 = explode($this->_options['separator'], $data); $this->_bufIndex = 0; foreach($data2 as $data) { // strip open and close {@ } and collapse all whitespace preg_match_all('/([^\s]+)(\s+)?/', ltrim($data), $this->_buf[$this->_bufIndex++]); // $this->_buf[$this->_bufIndex++] = preg_split("/\s+/", ltrim($data)); } $this->_bufIndex = 0; $this->_multipleBuffers = true; } else { // strip open and close {@ } and collapse all whitespace preg_match_all('/([^\s]+)(\s+)?/', ltrim($data), $this->_buf); } $this->_index = 0; } /** * Passes data to {@link newTag()} * @var string */ function PHP_Parser_DocBlock_DefaultInlineTagLexer($data = '') { $this->debug = false; $this->setOptions(); $this->newTag($data); } } http://cvs.php.net/co.php/pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagParser.php?r=1.1&p=1 Index: pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagParser.php +++ pear/PHP_Parser/Parser/DocBlock/DefaultInlineTagParser.php <?php /** * @package PHP_Parser */ class PHP_Parser_DocBlock_DefaultInlineTagParser { /** * Run-time options * @access protected * @var array */ var $_options = array(); /** * @var array * @access protected */ var $_loadedTags = array(); function PHP_Parser_DocBlock_DefaultInlineTagParser($options = array()) { $this->_options['taglocation'] = 'PHP/Parser/DocBlock/InlineTags/'; $this->_options['tagprefix'] = 'PHP_Parser_DocBlock_InlineTags_'; $this->_options['taglexer'] = 'PHP_Parser_DocBlock_DefaultInlineTagLexer'; $this->_options = array_merge($this->_options, $options); if (is_object($this->_options['taglexer']) || (is_string($this->_options['taglexer']) && !class_exists($this->_options['taglexer']))) { $this->_options['taglexer'] = false; } } /** * @param string inline tag name * @param string inline tag contents * @return object|array returns either a user-specified tag class, or an unparsed array */ function parseInlineTag($name, $contents) { if (!($lexer = $this->_options['taglexer'])) { return false; } elseif (is_string($lexer)) { $lexer = new $lexer($contents); if (!is_a($lexer, 'PHP_Parser_DocBlock_DefaultInlineTagLexer')) { return false; } } $name = strtolower($name); $a = $this->_getLoadedTag($name); if (is_array($a) && !count($a)) { $return = $this->_loadInlineTag($name); if ($return) { return $return; } } $a = $this->_getLoadedTag($name); if (!$a) { return array('tag' => $name, 'contents' => $contents); } $structure = $a['structure']; $tagname = $a['class']; $inlinetag = new $tagname; if (!is_a($inlinetag, 'PHP_Parser_DocBlock_InlineTags_Base')) { return false; } if (!count($structure['params'])) { // tags like {@inheritdoc} have no params return $inlinetag; } $lexer->setOptions($lexoptions = $inlinetag->getLexerOptions()); $lexer->newTag($contents); foreach($structure['params'] as $param) { $setparam = 'set' . $param['name']; if (!isset($lexer->_typeMap[$param['type']])) { // throw exception } $handler = $lexer->_typeMap[$param['type']]; if (!method_exists($lexer, $handler)) { // throw exception } if (isset($lexoptions['separator'])) { $val = $this->_getMultiOptions($lexer, $handler, $param); } else { $val = $lexer->$handler($param); } if ($param['required'] && !$val) { return false; } $e = $inlinetag->$setparam($val); if (PEAR::isError($e)) { return $e; } } return $inlinetag; } function _getMultiOptions(&$lexer, $handler, $param) { $val = array(); while ($lexer->hasNextBuf()) { $val[] = $lexer->$handler($param); if (!$lexer->moveNextBuf()) { break; } } return $val; } /** * Load the file containing an inline tag class. * * In phpDocumentor version 2.x, inline tags can be located in one of * two locations, which are specified in the options passed to * the constructor. The first location is a user-specified location * which is designed to allow multi-user installations with a central * phpDocumentor install to specify a local location for inline tag files. * * User A, for example, may have a specialized inline tag {@homepage} that * spits out a project homepage. This tag is located in ~A/itags/homepage.php. * The user will pass this location on the command-line as the location to * search for user-defined tags. By default, phpDocumentor will look for a * PhpDocumentor_Structures_DocBlock_InlineTags_Homepage class. This can * also be changed so that a shorter classname may be used. * * This flexibility allows users to extend phpDocumentor in ways we haven't * imagined without breaking forward compatibility to future phpDocumentor * versions. * * Every inline tag class must specify the tag structure in an array * returned by function getTagStructure(). * @param string * @return null|array null on successful tag load, an array with failed parse * if the tag is not loaded successfully */ function _loadInlineTag($name) { if (!class_exists($this->_options['tagprefix'] . ucfirst($name)) && !class_exists('PHP_Parser_DocBlock_InlineTags_' . ucfirst($name))) { // try to include it $filename = $this->_options['taglocation'] . ucfirst($name) . '.php'; if (PhpDocumentor::isIncludeable($filename)) { include_once($filename); } if (!class_exists($this->_options['tagprefix'] . ucfirst($name)) && !class_exists('PHP_Parser_DocBlock_InlineTags_' . ucfirst($name))) { $filename = 'PHP_Parser_DocBlock_InlineTags_' . ucfirst($name) . '.php'; if (PhpDocumentor::isIncludeable($filename)) { include_once($filename); } } } // try the user tagname first if (class_exists($this->_options['tagprefix'] . ucfirst($name))) { $this->_setLoadedTag($name, array('class' => $this->_options['tagprefix'] . ucfirst($name))); if (!in_array('gettagstructure', get_class_methods($this->_options['tagprefix'] . ucfirst($name)))) { $this->_setLoadedTag($name, false); return false; } else { $a = $this->_getLoadedTag($name); $a['structure'] = call_user_func(array($a['class'], 'structure')); $this->_setLoadedTag($name, $a); } } elseif (class_exists('PHP_Parser_DocBlock_InlineTags_' . ucfirst($name))) { $this->_setLoadedTag($name, array('class' => 'PHP_Parser_DocBlock_InlineTags_' . ucfirst($name))); if (!in_array('gettagstructure', get_class_methods('PHP_Parser_DocBlock_InlineTags_' . ucfirst($name)))) { $this->_setLoadedTag($name, false); return false; } else { $a = $this->_getLoadedTag($name); $a['structure'] = call_user_func(array($a['class'], 'structure')); $this->_setLoadedTag($name, $a); } } return false; } function _getLoadedTag($tagname) { if (!isset($this->_loadedTags[$tagname])) { return array(); } return $this->_loadedTags[$tagname]; } function _setLoadedTag($tagname, $value) { $this->_loadedTags[$tagname] = $value; } } ?> http://cvs.php.net/co.php/pear/PHP_Parser/Parser/DocBlock/DefaultTagLexer.php?r=1.1&p=1 Index: pear/PHP_Parser/Parser/DocBlock/DefaultTagLexer.php +++ pear/PHP_Parser/Parser/DocBlock/DefaultTagLexer.php <?php /** * @package PHP_Parser */ class PHP_Parser_DocBlock_DefaultTagLexer { /** * @var string */ var $_buf; /** * @var integer */ var $_index; /** * Indicates whether the current Tag contains separate sections * * This parameter is a flag used to determine whether the input buffer * has been split into sections such as what happens in a @see tag. * Sections are delimited by commas. * @var boolean */ var $_multipleBuffers = false; /** * Mapping of tag field types to lexer function name * * Use this array to extend the tag parser, simply add a mapping of * typename => lexer function name. The function name must exist or * an exception will be thrown * @access protected */ var $_typeMap = array( 'desc' => 'getDesc', 'type' => 'getType', 'var' => 'getVar', 'typewithvar' => 'getTypeWithVar', 'word' => 'getWord', 'link' => 'getLink', 'multi-word' => 'getWords', 'allwords' => 'getAllWords', 'authoremails' => 'getAuthorEmails', ); /** * return something useful, when a parse error occurs. * * used to build error messages if the parser fails, and needs to know the line number.. * * @return string * @access public */ function parseError() { return "Error at line {$this->yyline}"; } /** * Set Lexer options * * Valid options are * - separator: this is a string or false. If it is * a string, then the lexer will assume * the inline tag can have multiple * values, and will split the contents * on the separator, and loop over each * segment as if it were a separate tag * @param array */ function setOptions($options = array()) { $this->_options['descParserClass'] = $this->_options['descLexerClass'] = false; $this->_options['lineNumber'] = 1; $this->_options = array_merge($this->_options, $options); if (!is_object($this->_options['descParserClass']) || !is_object($this->_options['descLexerClass'])) { return false; } } /** * Retrieve the next word from the tag contents * @return string|false */ function getWord() { return $this->_readBuf(); } /** * Retrieve multiple words from the tag contents * @param integer the number of words to return * @return false|string */ function getWords($param) { $count = $param['count']; $ret = ''; for ($i = 0; $i < $count; $i++) { if ($word = $this->_readBuf(true, true)) { $ret .= $word; } } return rtrim($ret); } /** * Retrieve all remaining words from the tag contents * @return string|false */ function getAllWords() { $ret = ''; while ($word = $this->_readBuf(true, true)) { $ret .= $word; } if ($ret == '') { return false; } else { return $ret; } } /** * Return a long description * * This returns the results of parsing * @return false|object|array */ function getDesc() { $desc = $this->getAllWords(); return $this->_parseDesc($desc); } /** * Return the description section from an @author tag * * Handles emails like <cellog@users.sourceforge.net>, converting them into * inline links */ function getAuthorEmails() { $desc = $this->getAllWords(); // replace emails with an inline link before processing $desc = preg_replace('/<([a-zA-Z0-9\._-]+\@[a-zA-Z0-9\-\.]+\.' . '(?:[a-zA-Z]{2,4}|[0-9]{1,3}))>/', '<{@link mailto:\\1 \\1}>', $desc); return $this->_parseDesc($desc); } /** * Parse a description for inline tags/HTML * @param string * @access private * @return array */ function _parseDesc($desc) { $lex = $this->_options['descLexerClass']; $parser = $this->_options['descParserClass']; $description = $parser->parse( array('lexer' => $lex, 'nosummary' => true, 'tagdesc' => true, 'comment' => $desc, 'commentline' => $this->_options['lineNumber'], 'commenttoken' => false )); return $description['documentation']; } /** * Return a type array like array("array") or * array("array", "object PhpDocumentor"). * * All valid types must begin with a letter or underscore. Anything else is * assumed to be a variable name or description * @return false|object|array */ function getType() { // need at least 1 word to be a valid type $word = $this->getWord(); if (!$word) { return false; } $types = array(); $typeindex = 0; if ($word == 'object') { $types[$typeindex] .= $word; $word = $this->getWord(); if (!$word) { // found the complete type return $types; } // this checks for object classname. Classname may only begin // with alphanumeric and _ if (!preg_match('/[a-zA-Z_]/', $word{0})) { $this->_index--; return $types; } else { // prepare for addition of classname $types[$typeindex] = ' '; } } $done = false; do { // this loop checks for type|type|type and for // type|object classname|type|object classname2 if (!preg_match('/[a-zA-Z_]/', $word{0})) { break; } if (strpos($word, '|')) { if (!isset($types[$typeindex])) { $types[$typeindex] = ''; } $temptypes = explode('|', $word); while (count($temptypes) - 1) { if (!isset($types[$typeindex])) { $types[$typeindex] = ''; } // grab all but the last type into its own array $types[$typeindex++] .= array_shift($temptypes); } if (!isset($types[$typeindex])) { $types[$typeindex] = ''; } // this is just in case we have type1|type2|object classname // it will not increment $typeindex $types[$typeindex] .= $word = array_shift($temptypes); if ($word != 'object') { // we're done if (!count($types)) { return false; } return $types; } else { $typeindex++; } } else { if (!isset($types[$typeindex])) { $types[$typeindex] = ''; } if (!preg_match('/[a-zA-Z_]/', $word{0})) { $this->_index--; if (!count($types)) { return false; } return $types; } else { $types[$typeindex] .= $word; } return $types; } $word = $this->getWord(); } while ($word); if (!count($types)) { return false; } return $types; } /** * Retrieve a type and optional variable name. * * This uses {@link getType()} to retrieve the type portion, and then uses * {@link getVar()} to retrieve the variable name portion * @return array Format: array('types' => type array|false, 'var' => * false|variable) */ function getTypeWithVar() { return array('types' => $this->getType(), 'var' => $this->getVar()); } /** * Retrieve an optional variable name * * This checks the next word to see if it is begins with $ or &$, and * returns it as a variable name if so. * @return string|false */ function getVar() { $word = $this->getWord(); if ($word) { if (!preg_match('/^(?:\$|&\$)/', $word)) { $word = false; $this->_index--; } } return $word; } /** * Return a link expected by phpDocumentor * * This will be either 1 or two words. This is to * allow links like "function mine()" and so on * @return false|string */ function getLink() { // must have at least 1 word to be a valid link $ret = $this->getWord(); if (!$ret) { return false; } $save = $ret; if (strpos($ret, '#')) { $ret = substr($ret, strpos($ret, '#') + 1); // chop off package selector } // if the word is function or global if (in_array($ret, array('function', 'global'))) { if ($this->_readBuf(false)) { $ret = $save; $ret .= ' ' . $this->_readBuf(); return $ret; } else { return false; } } else { return $save; } } /** * Read a word from the buffer * @param boolean whether to increment the index into the buffer * @param boolean whether to include whitespace * @access private */ function _readBuf($inc = true, $whitespace = false) { $index = $this->_index; $buf = $this->_getBuf(); if ($inc) { $this->_index++; } if (!isset($buf[1][$index])) { return null; } if ($whitespace) { return $buf[0][$index]; } return $buf[1][$index]; } /** * Returns true if there is another segment of the multi-segment * inline tag to parse. * @return boolean */ function hasNextBuf() { if (!$this->_multipleBuffers) { return false; } if (!isset($this->_buf[$this->_bufIndex][0][$this->_index]) && !isset($this->_buf[$this->_bufIndex + 1])) { return false; } return $this->_bufIndex < count($this->_buf); } /** * Move to next buffer in the multi-section tag * @return boolean Success is returned */ function moveNextBuf() { if (isset($this->_buf[++$this->_bufIndex][0])) { $this->_index = 0; return $this->_buf[$this->_bufIndex]; } else { return false; } } /** * Return the input buffer * * For single-segment tags, this returns the whole buffer. For * multi-segment tags, this returns the current buffer, or if it * is empty, returns the next one * @return array */ function _getBuf() { if ($this->_multipleBuffers) { if (isset($this->_buf[$this->_bufIndex][0][$this->_index])) { return $this->_buf[$this->_bufIndex]; } else { return false; } } else { return $this->_buf; } } /** * Prepare tag contents for lexing. * * This function replaces the current buffer with the data after * splitting it along whitespace, and along any separators * passed to {@link setOptions()} * @param string */ function newTag($data) { $data = ltrim($data); if ($this->_options['separator']) { $data2 = explode($this->_options['separator'], $data); $this->_bufIndex = 0; foreach($data2 as $data) { // strip out all whitespace preg_match_all('/([^\s]+)(\s+)?/', ltrim($data), $this->_buf[$this->_bufIndex++]); // $this->_buf[$this->_bufIndex++] = preg_split("/\s+/", ltrim($data)); } $this->_bufIndex = 0; $this->_multipleBuffers = true; } else { $this->_multipleBuffers = false; // strip out all whitespace preg_match_all('/([^\s]+)(\s+)?/', ltrim($data), $this->_buf); // $this->_buf = preg_split("/\s+/", $data); } $this->_index = 0; } /** * Passes data to {@link newTag()} * @var string */ function PHP_Parser_DocBlock_DefaultTagLexer($data = '') { $this->debug = false; if (!empty($data)) { $this->setOptions(); $this->newTag($data); } } } http://cvs.php.net/co.php/pear/PHP_Parser/Parser/DocBlock/DefaultTagParser.php?r=1.1&p=1 Index: pear/PHP_Parser/Parser/DocBlock/DefaultTagParser.php +++ pear/PHP_Parser/Parser/DocBlock/DefaultTagParser.php <?php /** * @package PHP_Parser */ class PHP_Parser_DocBlock_DefaultTagParser { /** * Run-time options * @access protected * @var array */ var $_options = array(); /** * @var array * @access protected */ var $_loadedTags = array(); function PHP_Parser_DocBlock_DefaultTagParser($options = array()) { $this->_options['taglocation'] = 'PHP/Parser/DocBlock/Tags/'; $this->_options['tagprefix'] = 'PHP_Parser_DocBlock_Tags_'; $this->_options['lexeroptions'] = array(); $this->_options['taglexer'] = 'PHP_Parser_DocBlock_DefaultTagLexer'; $this->_options = array_merge($this->_options, $options); if (is_object($this->_options['taglexer']) || (is_string($this->_options['taglexer']) && !class_exists($this->_options['TagLexer']))) { $this->_options['taglexer'] = 'PHP_Parser_DocBlock_DefaultTagLexer'; } } /** * @param string inline tag name * @param string inline tag contents * @return object|array returns either a user-specified tag class, or an unparsed array */ function parseTag($name, $contents) { $lexer = $this->_options['taglexer']; if (is_string($lexer)) { $lexer = new $lexer; } $lexer->setOptions($this->_options['lexeroptions']); $name = strtolower($name); // attempt to load the tag parser class for this tag $a = $this->_getLoadedTag($name); if ($a === false) { return array('tag' => $name, 'contents' => $contents); } if (is_array($a) && !count($a)) { $return = $this->_loadTag($name); if ($return) { return $return; } } $a = $this->_getLoadedTag($name); if (is_array($a) && !count($a)) { return array('tag' => $name, 'contents' => $contents); } $structure = $a['structure']; $tagname = $a['class']; $tag = new $tagname; if (!is_a($tag, 'PHP_Parser_DocBlock_Tags_Base')) { return false; } if (!count($structure['params'])) { // tags like @abstract have no params return $tag; } $this->_options['lexeroptions']['separator'] = false; $lexer->setOptions(array_merge($this->_options['lexerOptions'], $lexoptions = $tag->getLexerOptions())); $lexer->newTag($contents); foreach($structure['params'] as $param) { $setparam = 'set' . $param['name']; if (!isset($lexer->_typeMap[$param['type']])) { // throw exception } $handler = $lexer->_typeMap[$param['type']]; if (!method_exists($lexer, $handler)) { // throw exception } if (isset($lexoptions['separator'])) { $val = $this->_getMultiOptions($lexer, $handler, $param); } else { $val = $lexer->$handler($param); } if ($param['required'] && !$val) { return false; } $e = $tag->$setparam($val); if (PEAR::isError($e)) { return $e; } } return $tag; } function _getMultiOptions(&$lexer, $handler, $param) { $val = array(); while ($lexer->hasNextBuf()) { $val[] = $lexer->$handler($param); if (!$lexer->moveNextBuf()) { break; } } return $val; } /** * Load the file containing a tag class. * * Tags can be located in one of two locations, * PHP/Parser/DocBlock/Tags/ or a user-specified location * which is designed to allow multi-user installations with a central * PHP_Parser install to specify a local location for tag files. * * User A, for example, may have a specialized tag @homepage that * spits out a project homepage. This tag is located in ~A/tags/homepage.php. * The user will pass this location on the command-line as the location to * search for user-defined tags. By default, PHP_Parser will look for a * PHP_Parser_DocBlock_Tags_Homepage class. This can * also be changed so that a shorter classname may be used. * * This flexibility allows users to extend PHP_Parser in ways we haven't * imagined without breaking forward compatibility to future PHP_Parser * versions. * * Every tag class must specify the tag structure in an array * returned by function structure() * @param string * @return null|array null on successful tag load, an array with failed parse * if the tag is not loaded successfully */ function _loadTag($name) { if (!class_exists($this->_options['tagprefix'] . ucfirst($name)) && !class_exists($this->_options['tagprefix'] . ucfirst($name))) { // try to include it $filename = $this->_options['defaultTagLocation'] . ucfirst($name) . '.php'; if (PhpDocumentor::isIncludeable($filename)) { include_once($filename); } if (!class_exists('PHP_Parser_DocBlock_Tags_' . ucfirst($name)) && !class_exists('PHP_Parser_DocBlock_Tags_' . ucfirst($name))) { $filename = 'PHP/Parser/DocBlock/Tags/' . ucfirst($name) . '.php'; if (PhpDocumentor::isIncludeable($filename)) { include_once($filename); } } } // try the user tagname first if (class_exists($this->_options['tagprefix'] . ucfirst($name))) { $this->_setLoadedTag($name, array('class' => $this->_options['tagprefix'] . ucfirst($name))); if (!in_array('structure', get_class_methods($this->_options['tagprefix'] . ucfirst($name)))) { // failure - doesn't have the structure() static method $this->_setLoadedTag($name, false); return false; } else { $a = $this->_getLoadedTag($name); $a['structure'] = call_user_func(array($a['class'], 'structure')); $this->_setLoadedTag($name, $a); } } elseif (class_exists($this->_options['tagprefix'] . ucfirst($name))) { $this->_setLoadedTag($name, array('class' => $this->_options['tagprefix'] . ucfirst($name))); if (!in_array('gettagstructure', get_class_methods($this->_options['tagprefix'] . ucfirst($name)))) { // failure - doesn't have the structure() static method $this->_setLoadedTag($name, false); return false; } else { $a = $this->_getLoadedTag($name); $a['structure'] = call_user_func(array($a['class'], 'structure')); $this->_setLoadedTag($name, $a); } } return false; } function _getLoadedTag($tagname) { if (!isset($this->_loadedTags[$tagname])) { return array(); } return $this->_loadedTags[$tagname]; } function _setLoadedTag($tagname, $value) { $this->_loadedTags[$tagname] = $value; } } ?>