+++ /dev/null
-<?php\r
-/**\r
- * Source Code Highlighting\r
- *\r
- * The classes in this file are responsible for the dynamic @example, @filesource\r
- * and {@}source} tags output. Using the phpDocumentor_HighlightWordParser,\r
- * the phpDocumentor_HighlightParser retrieves PHP tokens one by one from the\r
- * array generated by {@link phpDocumentorTWordParser} source retrieval functions\r
- * and then highlights them individually.\r
- *\r
- * It accomplishes this highlighting through the assistance of methods in\r
- * the output Converter passed to its parse() method, and then returns the\r
- * fully highlighted source as a string\r
- *\r
- * phpDocumentor :: automatic documentation generator\r
- * \r
- * PHP versions 4 and 5\r
- *\r
- * Copyright (c) 2002-2007 Gregory Beaver\r
- * \r
- * LICENSE:\r
- * \r
- * This library is free software; you can redistribute it\r
- * and/or modify it under the terms of the GNU Lesser General\r
- * Public License as published by the Free Software Foundation;\r
- * either version 2.1 of the License, or (at your option) any\r
- * later version.\r
- * \r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Lesser General Public License for more details.\r
- * \r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * @category ToolsAndUtilities\r
- * @package phpDocumentor\r
- * @subpackage Parsers\r
- * @author Gregory Beaver <cellog@php.net>\r
- * @copyright 2002-2007 Gregory Beaver\r
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL\r
- * @version CVS: $Id: HighlightParser.inc,v 1.15 2007/11/18 17:44:15 ashnazg Exp $\r
- * @filesource\r
- * @link http://www.phpdoc.org\r
- * @link http://pear.php.net/PhpDocumentor\r
- * @tutorial tags.example.pkg, tags.filesource.pkg, tags.inlinesource.pkg\r
- * @since 1.2.0beta3\r
- * @todo CS cleanup - change package to PhpDocumentor\r
- */\r
-\r
-/**\r
- * Retrieve tokens from an array of tokens organized by line numbers\r
- *\r
- * @category ToolsAndUtilities\r
- * @package phpDocumentor\r
- * @subpackage Parsers\r
- * @author Gregory Beaver <cellog@php.net>\r
- * @copyright 2002-2007 Gregory Beaver\r
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL\r
- * @version Release: 1.4.1\r
- * @link http://www.phpdoc.org\r
- * @link http://pear.php.net/PhpDocumentor\r
- * @since 1.2.0beta3\r
- * @todo CS cleanup - change package to PhpDocumentor\r
- * @todo CS cleanup - change class name to PhpDocumentor_*\r
- */\r
-class phpDocumentor_HighlightWordParser extends phpDocumentorTWordParser\r
-{\r
- /**\r
- * Hash used to keep track of line numbers that have already been initialized\r
- * @var array\r
- * @access private\r
- */\r
- var $_listLineNums = array();\r
- /**\r
- * Initialize the parser object\r
- *\r
- * @param array &$input the input\r
- * @param phpDocumentor_HighlightParser &$parser the parser\r
- *\r
- * @return void\r
- */\r
- function setup(&$input, &$parser)\r
- {\r
- $this->_parser = &$parser;\r
- $this->data = &$input;\r
- $this->_all = $input;\r
- $this->_sourceline = 0;\r
- $this->pos = 0;\r
- $this->linenum = 0;\r
- }\r
- \r
- /**\r
- * debugging function\r
- *\r
- * @return void\r
- * @access private\r
- */\r
- function printState()\r
- {\r
- $linenum = $this->linenum;\r
- $pos = $this->pos;\r
- if (!isset($this->_all[$this->linenum][$this->pos])) {\r
- $linenum++;\r
- $pos = 0;\r
- }\r
- $details = '';\r
- $token = $this->_all[$linenum][$pos];\r
- if (is_array($token)) {\r
- $details = token_name($token[0]);\r
- $token = htmlspecialchars($token[1]);\r
- } else {\r
- $token = htmlspecialchars($token);\r
- }\r
- debug('Next Token ' . $this->linenum . '-' . $this->pos . ':' . $details);\r
- var_dump($token);\r
- }\r
- \r
- /**\r
- * Retrieve the position of the next token that will be parsed\r
- * in the internal token array\r
- *\r
- * @return array format: array(line number, position)\r
- */\r
- function nextToken()\r
- {\r
- $linenum = $this->linenum;\r
- $pos = $this->pos;\r
- if (!isset($this->_all[$this->linenum][$this->pos])) {\r
- $linenum++;\r
- $pos = 0;\r
- }\r
- if (!isset($this->_all[$linenum][$pos])) {\r
- return false;\r
- }\r
- return array($linenum, $pos);\r
- }\r
- \r
- /**\r
- * Retrieve the next token\r
- *\r
- * @return array|string either array(PHP token constant, token) or string\r
- * non-specific separator\r
- */\r
- function getWord()\r
- {\r
- if (!isset($this->_all[$this->linenum][$this->pos])) {\r
- $this->linenum++;\r
- $this->pos = 0;\r
- if (!isset($this->_all[$this->linenum])) {\r
- return false;\r
- }\r
- $this->_parser->newLineNum();\r
- return $this->getWord();\r
- }\r
- $word = $this->_all[$this->linenum][$this->pos++];\r
- return str_replace("\t", ' ', $word);\r
- }\r
-\r
- /**\r
- * back the word parser to the previous token as defined by $last_token\r
- *\r
- * @param array|string $last_token token, or output from {@link nextToken()}\r
- * @param bool $is_pos if true, backupPos interprets $last_token \r
- * to be the position in the internal token\r
- * array of the last token\r
- *\r
- * @return void\r
- */\r
- function backupPos($last_token, $is_pos = false)\r
- {\r
- if (!$last_token) {\r
- return;\r
- }\r
- if ($is_pos) {\r
- $this->linenum = $last_token[0];\r
- $this->pos = $last_token[1];\r
- return;\r
- }\r
- if ($last_token === false) {\r
- return;\r
- }\r
-\r
- //fancy_debug('before', $this->linenum, $this->pos, \r
- // token_name($this->_all[$this->linenum][$this->pos][0]),\r
- // htmlentities($this->_all[$this->linenum][$this->pos][1]),\r
- // $this->_all[$this->linenum]);\r
-\r
- do {\r
- $this->pos--;\r
- if ($this->pos < 0) {\r
- $this->linenum--;\r
- if ($this->linenum < 0) {\r
- var_dump($last_token);\r
- break;\r
- }\r
- $this->pos = count($this->_all[$this->linenum]) - 1;\r
- }\r
- } while (!$this->tokenEquals($last_token, str_replace("\t", ' ', \r
- $this->_all[$this->linenum][$this->pos])));\r
-\r
- //fancy_debug('after', $this->linenum, $this->pos,\r
- // token_name($this->_all[$this->linenum][$this->pos][0]),\r
- // htmlentities($this->_all[$this->linenum][$this->pos][1]));\r
- }\r
-}\r
-\r
-/**\r
- * Highlights source code using {@link parse()}\r
- *\r
- * @category ToolsAndUtilities\r
- * @package phpDocumentor\r
- * @subpackage Parsers\r
- * @author Gregory Beaver <cellog@php.net>\r
- * @copyright 2002-2007 Gregory Beaver\r
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL\r
- * @version Release: 1.4.1\r
- * @link http://www.phpdoc.org\r
- * @link http://pear.php.net/PhpDocumentor\r
- * @since 1.2.0beta3\r
- * @todo CS cleanup - change package to PhpDocumentor\r
- * @todo CS cleanup - change class name to PhpDocumentor_*\r
- */\r
-class phpDocumentor_HighlightParser extends phpDocumentorTParser\r
-{\r
- /**#@+\r
- * @access private\r
- */\r
-\r
- /**\r
- * Highlighted source is built up in this string\r
- * @var string\r
- */\r
- var $_output;\r
-\r
- /**\r
- * contents of the current source code line as it is parsed\r
- * @var string\r
- */\r
- var $_line;\r
-\r
- /**\r
- * Used to retrieve highlighted tokens\r
- * @var Converter a descendant of Converter\r
- */\r
- var $_converter;\r
-\r
- /**\r
- * Path to file being highlighted, if this is from a @filesource tag\r
- * @var false|string full path\r
- */\r
- var $_filesourcepath;\r
-\r
- /**\r
- * @var array\r
- */\r
- var $eventHandlers = array(\r
- PARSER_EVENT_ARRAY => 'defaultHandler',\r
- PARSER_EVENT_CLASS => 'handleClass',\r
- PARSER_EVENT_COMMENT => 'handleComment',\r
- PARSER_EVENT_DOCBLOCK_TEMPLATE => 'handleDocBlockTemplate',\r
- PARSER_EVENT_END_DOCBLOCK_TEMPLATE => 'handleEndDocBlockTemplate',\r
- PARSER_EVENT_LOGICBLOCK => 'handleLogicBlock',\r
- PARSER_EVENT_METHOD_LOGICBLOCK => 'handleMethodLogicBlock',\r
- PARSER_EVENT_NOEVENTS => 'defaultHandler',\r
- PARSER_EVENT_OUTPHP => 'defaultHandler',\r
- PARSER_EVENT_CLASS_MEMBER => 'handleClassMember',\r
- PARSER_EVENT_DEFINE => 'defaultHandler',\r
- PARSER_EVENT_DEFINE_PARAMS => 'defaultHandler',\r
- PARSER_EVENT_DEFINE_PARAMS_PARENTHESIS => 'defaultHandler',\r
- PARSER_EVENT_INCLUDE_PARAMS_PARENTHESIS => 'defaultHandler',\r
- PARSER_EVENT_DOCBLOCK => 'handleDocBlock',\r
- PARSER_EVENT_TAGS => 'handleTags',\r
- PARSER_EVENT_DESC => 'handleDesc',\r
- PARSER_EVENT_DOCKEYWORD => 'handleTag',\r
- PARSER_EVENT_DOCKEYWORD_EMAIL => 'handleDockeywordEmail',\r
- PARSER_EVENT_EOFQUOTE => 'handleQuote',\r
- PARSER_EVENT_FUNCTION => 'handleFunction',\r
- PARSER_EVENT_METHOD => 'handleMethod',\r
- PARSER_EVENT_FUNCTION_PARAMS => 'handleFunctionParams',\r
- PARSER_EVENT_FUNC_GLOBAL => 'handleFuncGlobal',\r
- PARSER_EVENT_INLINE_DOCKEYWORD => 'handleInlineDockeyword',\r
- PARSER_EVENT_INCLUDE => 'defaultHandler',\r
- PARSER_EVENT_INCLUDE_PARAMS => 'defaultHandler',\r
- PARSER_EVENT_QUOTE => 'handleQuote',\r
- PARSER_EVENT_QUOTE_VAR => 'handleQuoteVar',\r
- PARSER_EVENT_PHPCODE => 'handlePhpCode',\r
- PARSER_EVENT_SINGLEQUOTE => 'handleSingleQuote',\r
- PARSER_EVENT_STATIC_VAR => 'defaultHandler',\r
- PARSER_EVENT_STATIC_VAR_VALUE => 'defaultHandler',\r
- PARSER_EVENT_VAR => 'handleVar',\r
- );\r
-\r
- /**\r
- * event handlers for @tags\r
- * @tutorial tags.pkg\r
- */\r
- var $tagHandlers = array(\r
- '*' => 'defaultTagHandler',\r
- 'abstract' => 'coreTagHandler',\r
- 'access' => 'coreTagHandler',\r
- 'author' => 'coreTagHandler',\r
- 'category' => 'coreTagHandler',\r
- 'copyright' => 'coreTagHandler',\r
- 'deprecated' => 'coreTagHandler',\r
- 'example' => 'coreTagHandler',\r
- 'filesource' => 'coreTagHandler',\r
- 'final' => 'coreTagHandler',\r
- 'global' => 'globalTagHandler',\r
- 'ignore' => 'coreTagHandler',\r
- 'license' => 'coreTagHandler',\r
- 'link' => 'coreTagHandler',\r
- 'name' => 'coreTagHandler',\r
- 'package' => 'coreTagHandler',\r
- 'param' => 'paramTagHandler',\r
- 'parameter' => 'paramTagHandler',\r
- 'see' => 'coreTagHandler',\r
- 'since' => 'coreTagHandler',\r
- 'subpackage' => 'coreTagHandler',\r
- 'internal' => 'coreTagHandler',\r
- 'return' => 'returnTagHandler',\r
- 'static' => 'coreTagHandler',\r
- 'staticvar' => 'staticvarTagHandler',\r
- 'throws' => 'coreTagHandler',\r
- 'todo' => 'coreTagHandler',\r
- 'tutorial' => 'coreTagHandler',\r
- 'uses' => 'coreTagHandler',\r
- 'var' => 'varTagHandler',\r
- 'version' => 'coreTagHandler',\r
- 'property' => 'propertyTagHandler',\r
- 'property-read' => 'propertyTagHandler',\r
- 'property-write' => 'propertyTagHandler',\r
- 'method' => 'propertyTagHandler'\r
- );\r
- /**#@-*/\r
- \r
- /**\r
- * wraps the current line (via the converter) and resets it to empty\r
- *\r
- * @return void\r
- * @uses Converter::SourceLine() encloses {@link $_line} in a\r
- * converter-specific format\r
- */\r
- function newLineNum()\r
- {\r
- if ($this->_pf_no_output_yet) {\r
- return;\r
- }\r
- $this->_flush_save();\r
- $this->_line .= $this->_converter->flushHighlightCache();\r
- $this->_output .= $this->_converter->SourceLine($this->_wp->linenum,\r
- $this->_line, $this->_path);\r
- $this->_line = '';\r
- }\r
- \r
- /**\r
- * Start the parsing at a certain line number\r
- *\r
- * @param int $num line number\r
- *\r
- * @return void\r
- */\r
- function setLineNum($num)\r
- {\r
- $this->_wp->linenum = $num;\r
- }\r
- \r
- /**\r
- * Parse a new file\r
- *\r
- * The parse() method is a do...while() loop that retrieves tokens one by\r
- * one from the {@link $_event_stack}, and uses the token event array set up\r
- * by the class constructor to call event handlers.\r
- *\r
- * The event handlers each process the tokens passed to them, and use the\r
- * {@link _addoutput()} method to append the processed tokens to the\r
- * {@link $_line} variable. The word parser calls {@link newLineNum()}\r
- * every time a line is reached.\r
- *\r
- * In addition, the event handlers use special linking functions\r
- * {@link _link()} and its cousins (_classlink(), etc.) to create in-code\r
- * hyperlinks to the documentation for source code elements that are in the\r
- * source code.\r
- *\r
- * @param array &$parse_data the parse data\r
- * @param Converter &$converter the converter object\r
- * @param bool $inlinesourceparse whether this data is from an\r
- * inline {@}source} tag\r
- * @param string|false $class if a string, it is the name of the \r
- * class whose method we are parsing\r
- * containing a {@}source} tag\r
- * @param false|integer $linenum starting line number from\r
- * {@}source linenum}\r
- * @param false|string $filesourcepath full path to file with @filesource\r
- * tag, if this is a @filesource parse\r
- *\r
- * @staticvar int used for recursion limiting if a handler for\r
- * an event is not found\r
- * @return bool\r
- * @uses setupStates() initialize parser state variables\r
- * @uses configWordParser() pass $parse_data to prepare retrieval of tokens\r
- * @todo CS cleanup - rename tokenizer_ext constant to uppercase\r
- */\r
- function parse (&$parse_data, &$converter, $inlinesourceparse = false,\r
- $class = false, $linenum = false, $filesourcepath = false)\r
- {\r
- if (!tokenizer_ext) {\r
- if (is_array($parse_data)) {\r
- $parse_data = join($parse_data, '');\r
- }\r
- $parse_data = explode("\n", $parse_data);\r
- $this->_output = '';\r
- foreach ($parse_data as $linenum => $line) {\r
- if ($linenum > 0) {\r
- $this->_output .= $converter->SourceLine($linenum,\r
- $line, $filesourcepath);\r
- }\r
- }\r
- return $converter->PreserveWhiteSpace($this->_output);\r
- }\r
- static $endrecur = 0;\r
- $this->_converter = &$converter;\r
- $converter->startHighlight();\r
- $this->_path = $filesourcepath;\r
- $this->setupStates($inlinesourceparse, $class);\r
-\r
- $this->configWordParser($parse_data);\r
- if ($linenum !== false) {\r
- $this->setLineNum($linenum);\r
- }\r
- // initialize variables so E_ALL error_reporting doesn't complain\r
- $pevent = 0;\r
- $word = 0;\r
-\r
- do {\r
- $lpevent = $pevent;\r
- $pevent = $this->_event_stack->getEvent();\r
- if ($lpevent != $pevent) {\r
- $this->_last_pevent = $lpevent;\r
- }\r
-\r
- if ($pevent == PARSER_EVENT_CLASS_MEMBER) {\r
- $this->_wp->setWhitespace(true);\r
- } else {\r
- $this->_wp->setWhitespace(false);\r
- }\r
-\r
- if (!is_array($word)) {\r
- $lw = $word;\r
- }\r
- if (is_array($word) && $word[0] != T_WHITESPACE) {\r
- $lw = $word;\r
- }\r
- $dbg_linenum = $this->_wp->linenum;\r
- $dbg_pos = $this->_wp->getPos();\r
- $word = $this->_wp->getWord();\r
- if (is_array($word) && ($word[0] == T_WHITESPACE || \r
- $word[0] == T_COMMENT) && \r
- $pevent != PARSER_EVENT_CLASS_MEMBER\r
- ) {\r
- //debug("added " . $this->_wp->linenum . '-' . $this->_wp->pos);\r
- $this->_addoutput($word);\r
- continue;\r
- } else {\r
- $this->_pv_last_word = $lw;\r
- }\r
- if ($pevent != PARSER_EVENT_DOCBLOCK) {\r
- $this->_pv_last_next_word = $this->_pv_next_word;\r
- $this->_pv_next_word = $this->_wp->nextToken();\r
- }\r
- // in wordparser, have to keep track of lines\r
- //$this->publishEvent(PHPDOCUMENTOR_EVENT_NEWLINENUM, \r
- // $this->_wp->linenum);\r
- if (PHPDOCUMENTOR_DEBUG == true) {\r
- echo "LAST: ";\r
- if (is_array($this->_pv_last_word)) {\r
- echo token_name($this->_pv_last_word[0]) . \r
- ' => |' .\r
- htmlspecialchars($this->_pv_last_word[1]);\r
- } else {\r
- echo "|" . $this->_pv_last_word;\r
- }\r
- echo "|\n";\r
- echo "PEVENT: " . $this->getParserEventName($pevent) . "\n";\r
- echo "LASTPEVENT: " .\r
- $this->getParserEventName($this->_last_pevent) . "\n";\r
- //echo "LINE: " . $this->_line . "\n";\r
- //echo "OUTPUT: " . $this->_output . "\n";\r
- echo $dbg_linenum . '-' . $dbg_pos . ": ";\r
- if (is_array($word)) {\r
- echo token_name($word[0]) . ' => |' . htmlspecialchars($word[1]);\r
- } else {\r
- echo '|'.htmlspecialchars($word);\r
- }\r
- echo "|\n";\r
- $this->_wp->printState();\r
- echo "NEXT TOKEN: ";\r
- $tok1 = $this->_pv_next_word;\r
- $tok = $this->_wp->_all[$tok1[0]][$tok1[1]];\r
- if (is_array($tok)) {\r
- echo token_name($tok[0]) . ' => ' . $tok1[0] . '-' . $tok1[1] .\r
- '|' . htmlspecialchars($tok[1]);\r
- } else {\r
- echo "|" . $tok;\r
- }\r
- echo "|\n";\r
- echo "-------------------\n\n\n";\r
- flush();\r
- }\r
- if ($word !== false && isset($this->eventHandlers[$pevent])) {\r
- $handle = $this->eventHandlers[$pevent];\r
- $this->$handle($word, $pevent);\r
- } elseif ($word !== false) {\r
- debug('WARNING: possible error, no handler for event number '\r
- . $pevent);\r
- if ($endrecur++ == 25) {\r
- die("FATAL ERROR, recursion limit reached");\r
- }\r
- }\r
- } while (!($word === false));\r
- if (strlen($this->_line)) {\r
- $this->newLineNum();\r
- }\r
- return $this->_output;\r
- }\r
-\r
- /**#@+\r
- * Event Handlers\r
- *\r
- * All Event Handlers use {@link checkEventPush()} and\r
- * {@link checkEventPop()} to set up the event stack and parser state.\r
- *\r
- * @param string|array $word token value\r
- * @param int $pevent parser event from {@link Parser.inc}\r
- *\r
- * @return void\r
- * @access private\r
- */\r
- /**\r
- * Most tokens only need highlighting, and this method handles them\r
- */\r
- function defaultHandler($word, $pevent)\r
- {\r
- $this->_addoutput($word);\r
- if ($this->checkEventPush($word, $pevent)) {\r
- return;\r
- }\r
- $this->checkEventPop($word, $pevent);\r
- }\r
- \r
- /**\r
- * Handles global declarations in a function, like:\r
- *\r
- * <code>\r
- * function foobar()\r
- * {\r
- * global $_phpDocumentor_setting;\r
- * }\r
- * </code>\r
- *\r
- * @uses _globallink() instead of _addoutput(), to link to global variables\r
- * if they are used in a function\r
- */\r
- function handleFuncGlobal($word, $pevent)\r
- {\r
- if ($this->checkEventPush($word, $pevent)) {\r
- return;\r
- }\r
- $this->_globallink($word);\r
- $this->checkEventPop($word, $pevent);\r
- }\r
- \r
- /**\r
- * Handles strings in quotation marks and heredoc\r
- *\r
- * Special handling is needed for strings that contain variables like:\r
- *\r
- * <code>$a = "$test string"</code>\r
- *\r
- * The tokenizer parses out tokens '"',array(T_VARIABLE,'$test'),' string',\r
- * and '"'. Since it is possible to have $this->classvar in a string,\r
- * we save a variable name just in case the next token is -> to allow linking\r
- * to class members. Otherwise, the string is simply highlighted.\r
- *\r
- * constant strings (with no $variables in them) are passed as a single\r
- * entity, and so will be saved in the last token parsed. This means the\r
- * event handler must tell the word parser to re-retrieve the current token\r
- * so that the correct event handler can process it.\r
- */\r
- function handleQuote($word, $pevent)\r
- {\r
- if ($this->_pf_inmethod && is_array($word) && $word[0] == T_VARIABLE) {\r
- $this->_pv_lastvar = $word;\r
- }\r
- if ($this->checkEventPush($word, $pevent)) {\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- if ($this->_pf_quote_active &&\r
- (($this->_pv_last_word == '"' && \r
- $this->_last_pevent != PARSER_EVENT_QUOTE) ||\r
- (is_array($this->_pv_last_word) && \r
- $this->_pv_last_word[0] == T_END_HEREDOC &&\r
- $this->_last_pevent != PARSER_EVENT_EOFQUOTE))\r
- ) {\r
- $this->_pf_quote_active = false;\r
- $this->_wp->backupPos($word);\r
- $this->_event_stack->popEvent();\r
- return;\r
- }\r
- if (!$this->_pf_quote_active && \r
- (($this->_pv_last_word == '"' && \r
- $this->_last_pevent != PARSER_EVENT_QUOTE) ||\r
- (is_array($this->_pv_last_word) && \r
- $this->_pv_last_word[0] == T_END_HEREDOC &&\r
- $this->_last_pevent != PARSER_EVENT_EOFQUOTE))\r
- ) {\r
- if (is_array($word) && $word[0] == T_VARIABLE) {\r
- $this->_pv_lastvar = $word;\r
- }\r
- $this->_pf_quote_active = true;\r
- $this->_save_highlight_state = $this->_converter->getHighlightState();\r
- $this->_converter->startHighlight();\r
- $this->_addoutput($word);\r
- $this->checkEventPop($word, $pevent);\r
- return;\r
- } elseif (is_array($this->_pv_last_word) && \r
- $this->_pv_last_word[0] == T_CONSTANT_ENCAPSED_STRING\r
- ) {\r
- //$this->_pv_quote_data = $this->_pv_last_word[1];\r
- $this->_event_stack->popEvent();\r
- $this->_wp->backupPos($word);\r
- return;\r
- }\r
- if ($this->checkEventPop($word, $pevent)) {\r
- $this->_pf_quote_active = false;\r
- }\r
- $this->_addoutput($word);\r
- }\r
- \r
- /**\r
- * Handles {$variable} within a "quote"\r
- *\r
- * This is a simple handler, for a very complex\r
- * array of legal syntax. It is legal to nest control structures\r
- * inside the {}, and other weird stuff.\r
- */\r
- function handleQuoteVar($word, $pevent)\r
- {\r
- if ($this->checkEventPop($word, $pevent)) {\r
- $this->_pf_quote_active = true;\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- if ($this->_pf_inmethod && is_array($word) && $word[0] == T_VARIABLE) {\r
- $this->_pv_lastvar = $word;\r
- }\r
- if ($this->checkEventPush($word, $pevent)) {\r
- $this->_pf_quote_active = false;\r
- if (is_string($word) && ($word == '{' || $word == '"' || $word == "'")\r
- ) {\r
- $this->_pf_quote_active = true;\r
- $this->_pv_lastvar = false;\r
- }\r
- }\r
- $this->_addoutput($word);\r
- }\r
- \r
- /**\r
- * Handles define() statements\r
- *\r
- * The only thing this handler cares about is retrieving the name of the\r
- * define variable, and the end of the define statement, so after the name\r
- * is found, it simply makes sure parentheses are matched as in this case:\r
- *\r
- * <code>\r
- * define("test",array("hello",6 => 4, 5 => array('there')));\r
- * </code>\r
- *\r
- * This handler and the DEFINE_PARAMS_PARENTHESIS handler (which is just\r
- * {@link defaultHandler()} in this version, as nothing fancy is needed)\r
- * work together to ensure proper parenthesis matching.\r
- *\r
- * If the define variable is documented, a link will be created to its\r
- * documentation using the Converter passed.\r
- */\r
- function handleDefine($word, $pevent)\r
- {\r
- static $token_save;\r
- if (!isset($token_save)) {\r
- $token_save = array();\r
- }\r
- $e = $this->checkEventPush($word, $pevent);\r
- if ($e && $e != PARSER_EVENT_DEFINE_PARAMS_PARENTHESIS) {\r
- return;\r
- }\r
- \r
- if (!isset($this->_pv_define_params_data)) {\r
- $this->_pv_define_params_data = '';\r
- }\r
- \r
- if ($this->checkEventPop($word, $pevent)) {\r
- unset($token_save);\r
- $this->_addoutput($word);\r
- }\r
- if ($this->_pf_definename_isset) {\r
- $this->_addoutput($word);\r
- } else {\r
- if ($word != ",") {\r
- $token_save[] = $word;\r
- if (is_array($word)) {\r
- $word = $word[1];\r
- }\r
- $this->_pv_define_params_data .= $word;\r
- } else {\r
- if (substr($this->_pv_define_params_data, 0, 1) ==\r
- substr($this->_pv_define_params_data,\r
- strlen($this->_pv_define_params_data) - 1) &&\r
- in_array(substr($this->_pv_define_params_data, 0, 1), \r
- array('"', "'"))\r
- ) {\r
- // remove leading and ending quotation marks \r
- // if there are only two\r
- $a = substr($this->_pv_define_params_data, 0, 1);\r
- $b = substr($this->_pv_define_params_data, 1, \r
- strlen($this->_pv_define_params_data) - 2);\r
- if (strpos($b, $a) === false) {\r
- $this->_pv_define_params_data = $b;\r
- }\r
- }\r
- $this->_pf_definename_isset = true;\r
-\r
- $link = $this->_converter->getLink($this->_pv_define_params_data);\r
- foreach ($token_save as $token) {\r
- if (is_object($link)) {\r
- if (is_array($token)) {\r
- $token = $token[1];\r
- }\r
- $this->_addoutput($this->_converter->returnSee($link,\r
- $token));\r
- } else {\r
- $this->_addoutput($save, $token);\r
- }\r
- }\r
- $this->_pv_define_params_data = '';\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Handles normal global code. Special consideration is taken for DocBlocks\r
- * as they need to retrieve the whole DocBlock before doing any output, so\r
- * the parser flag {@link $_pf_no_output_yet} is set to tell\r
- * {@link _addoutput()} not to spit anything out yet.\r
- *\r
- * @uses _link() make any global code that is a documentable element link\r
- * to the php manual or its documentation\r
- */\r
- function handlePhpCode($word, $pevent)\r
- {\r
- $test = $this->checkEventPush($word, $pevent);\r
- if ($test == PARSER_EVENT_DOCBLOCK || $test == PARSER_EVENT_COMMENT) {\r
- if (substr($word[1], 0, 2) == '/*' && strpos($word[1], '*/')) {\r
- $this->_pv_last_word = $word;\r
- if ($word[1] == '/**#@-*/') {\r
- $this->_pf_docblock_template = true;\r
- } else {\r
- $this->_pf_docblock = true;\r
- }\r
- return $this->handleDocBlock($word, PARSER_EVENT_DOCBLOCK);\r
- }\r
- $this->_pf_no_output_yet = true;\r
- $this->_pv_saveline = $this->_wp->linenum + 1;\r
- return;\r
- }\r
- if (is_array($word) && $word[0] == T_DOUBLE_COLON) {\r
- $this->_pf_colon_colon = true;\r
- }\r
- if (!$this->_pf_colon_colon && is_array($word) && $word[0] == T_STRING) {\r
- $this->_pv_last_string = $word;\r
- }\r
- $this->_link($word);\r
- $this->checkEventPop($word, $pevent);\r
- }\r
- \r
- /**\r
- * Handle the function declaration header\r
- *\r
- * This handler only sees the "function name" portion of the function\r
- * declaration. Handling of the function parameters is by\r
- * {@link handleFunctionParams()}, and the function body is handled by\r
- * {@link handleLogicBlock()}\r
- */\r
- function handleFunction($word, $pevent)\r
- {\r
- if ($this->checkEventPush($word, $pevent)) {\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- if ($this->checkEventPop($word, $pevent)) {\r
- return;\r
- }\r
- $this->_link($word);\r
- }\r
- \r
- /**\r
- * Handle the method declaration header\r
- *\r
- * This handler only sees the "function name" portion of the method\r
- * declaration. Handling of the method parameters is by\r
- * {@link handleFunctionParams()}, and the method body is handled by\r
- * {@link handleMethodLogicBlock()}\r
- */\r
- function handleMethod($word, $pevent)\r
- {\r
- if ($this->checkEventPush($word, $pevent)) {\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- if ($this->checkEventPop($word, $pevent)) {\r
- if ($word == ';') {\r
- $this->_addoutput($word);\r
- }\r
- return;\r
- }\r
- $this->_methodlink($word);\r
- }\r
- \r
- /**\r
- * Handler for the stuff between ( and ) in a function declaration\r
- *\r
- * <code>\r
- * function handles($only,$these,$parameters){...}\r
- * </code>\r
- */\r
- function handleFunctionParams($word, $pevent)\r
- {\r
- if ($this->checkEventPush($word, $pevent)) {\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- $this->_addoutput($word);\r
- $this->checkEventPop($word, $pevent);\r
- }\r
- \r
- /**\r
- * Handler for function body.\r
- *\r
- * The function body is checked for php functions, documented constants,\r
- * functions, and indirectly for global statements. It hyperlinks to the\r
- * documentation for detected elements is created. Everything else is\r
- * highlighted normally.\r
- */\r
- function handleLogicBlock($word, $pevent)\r
- {\r
- if ($this->checkEventPush($word, $pevent)) {\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- if (is_array($word) && $word[0] == T_DOUBLE_COLON) {\r
- $this->_pf_colon_colon = true;\r
- }\r
- if (!$this->_pf_colon_colon && is_array($word) && $word[0] == T_STRING) {\r
- $this->_pv_last_string = $word;\r
- }\r
- $this->_link($word);\r
- if ($this->checkEventPop($word, $pevent)) {\r
- $e = $this->_event_stack->popEvent();\r
- $this->_event_stack->pushEvent($e);\r
- if ($e == PARSER_EVENT_FUNCTION) {\r
- $this->_wp->backupPos($word); \r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Handler for method body.\r
- *\r
- * Like functions, the method body is checked for php functions, documented\r
- * constants, functions, and indirectly for global statements. It also\r
- * checks for "$this->XXXX" where XXXX is a class variable or method, and\r
- * links to the documentation for detected elements is created. Everything\r
- * else is highlighted normally.\r
- */\r
- function handleMethodLogicBlock($word, $pevent)\r
- {\r
- if (isset($this->_pv_prev_var_type)) {\r
- //debug('prevtype is set');\r
- if (!is_array($word)) {\r
- unset($this->_pv_prev_var_type);\r
- } else {\r
- if ($word[0] != T_WHITESPACE && \r
- $word[0] != T_STRING && $word[0] != T_OBJECT_OPERATOR\r
- ) {\r
- //fancy_debug('unset', $word);\r
- unset($this->_pv_prev_var_type);\r
- }\r
- }\r
- }\r
- $this->_pf_inmethod = true;\r
- if ($e = $this->checkEventPush($word, $pevent)) {\r
- $this->_addoutput($word);\r
- if ($e == PARSER_EVENT_CLASS_MEMBER) {\r
- $this->_pf_no_output_yet = true;\r
- }\r
- return;\r
- }\r
- if (is_array($word) && $word[0] == T_DOUBLE_COLON) {\r
- $this->_pf_colon_colon = true;\r
- }\r
- if (!$this->_pf_colon_colon && is_array($word) && $word[0] == T_STRING) {\r
- $this->_pv_last_string = $word;\r
- }\r
- if (is_array($word) && $word[0] == T_VARIABLE) {\r
- $this->_pv_lastvar = $word;\r
- }\r
- $this->_link($word);\r
- if ($this->checkEventPop($word, $pevent)) {\r
- $this->_pf_inmethod = false;\r
- $e = $this->_event_stack->popEvent();\r
- $this->_event_stack->pushEvent($e);\r
- if ($e == PARSER_EVENT_METHOD) {\r
- $this->_wp->backupPos($word); \r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Handles $obj->classmember in a method body\r
- *\r
- * This handler is responsible for linking to the documentation of a\r
- * class member when it is used directly in a method body.\r
- * \r
- * There are two methods of determining whether to link:\r
- * - $this->member\r
- * - $this->member->submember\r
- *\r
- * The first case is handled by the $_pv_lastvar variable, and the\r
- * second case is handled by the $_pv_prev_var_type variable. $_pv_lastvar\r
- * is always set to the value of the last T_VARIABLE token, if and only if\r
- * no text has occurred between the variable and a T_OBJECT_OPERATOR token\r
- * "->". handleClassMember will only link if the last variable encountered\r
- * was $this.\r
- *\r
- * When $this->variable is encountered, the variable is looked up to see\r
- * if it can be found, and if so, the contents of its @var tag are processed\r
- * to see if the member variable is defined to have 1 and only 1 class.\r
- * If so, the $_pv_prev_var_type variable is set to this classname. When\r
- * submember is processed, the HighlightParser checks to see if \r
- * $_pv_prev_var_type::submember() or $_pv_prev_var_type::$submember exists,\r
- * and if it does, it is linked to.\r
- */\r
- function handleClassMember($word, $pevent)\r
- {\r
- if (!isset($this->_pv_lastvar) && !isset($this->_pv_prev_var_type)) {\r
- //fancy_debug('returned from', $word, $this->_pv_prev_var_type);\r
- $this->_pf_no_output_yet = false;\r
- $this->_event_stack->popEvent();\r
- return $this->defaultHandler($word, $pevent);\r
- }\r
- if (isset($this->_pv_cm_name)) {\r
- $this->_pf_obj_op = false;\r
- $name = $this->_pv_cm_name;\r
- unset($this->_pv_cm_name);\r
- //debug('unset pvcmname');\r
- $this->_event_stack->popEvent();\r
- // control variable for _pv_prev_var_type\r
- $setnow = false;\r
- if ((isset($this->_pv_lastvar) && $this->_pv_lastvar[1] == '$this') ||\r
- isset($this->_pv_prev_var_type)\r
- ) {\r
- if (is_array($word) && $word[0] == T_WHITESPACE) {\r
- // preserve value of _pv_prev_var_type\r
- $setnow = true;\r
- $save = $this->_wp->nextToken();\r
- $temp = $this->_wp->getWord();\r
- $this->_wp->backupPos($save, true);\r
- }\r
- if ((is_string($word) && $word == '(') || (isset($temp) && \r
- is_string($temp) && $temp == '(')\r
- ) {\r
- // it's a function\r
- $this->_pf_no_output_yet = false;\r
- $this->_methodlink($name);\r
- unset($this->_pv_prev_var_type);\r
- } else {\r
- // it's a variable\r
- //fancy_debug('name is ', $name);\r
- $this->_pf_no_output_yet = false;\r
- $this->_varlink($name, true);\r
- $templink = \r
- $this->_converter->getLink('object ' . $this->_pv_class);\r
- $class = false;\r
- if (is_object($templink)) {\r
- $class = $this->_converter->classes\r
- ->getClass($templink->name, $templink->path);\r
- }\r
- if ($class) {\r
- $varname = $name;\r
- if (is_array($varname)) {\r
- $varname = $name[1];\r
- }\r
- if ($varname{0} != '$') {\r
- $varname = '$'.$varname;\r
- }\r
- $var = $class->getVar($this->_converter, $varname);\r
- \r
- if (is_object($var) && $var->docblock->var) {\r
- $type = $var->docblock->var->returnType;\r
- }\r
- if (isset($type)) {\r
- if (strpos($type, 'object') === false) {\r
- $type = 'object '.$type;\r
- }\r
- $type = $this->_converter->getLink($type);\r
- if (phpDocumentor_get_class($type) == 'classlink') {\r
- // the variable's type is a class, \r
- // save it for future ->\r
- //fancy_debug('set prev_var_type!', $type->name);\r
- $setnow = true;\r
- $this->_pv_prev_var_type = $type->name;\r
- } else {\r
- unset($this->_pv_prev_var_type);\r
- }\r
- } else {\r
- unset($this->_pv_prev_var_type);\r
- }\r
- } else {\r
- unset($this->_pv_prev_var_type);\r
- }\r
- }\r
- } else {\r
- $this->_pf_no_output_yet = false;\r
- // this does NewLinenum if necessary\r
- $this->_wp->backupPos($word);\r
- $this->_wp->getWord();\r
- $this->_addoutput($name);\r
- }\r
- if (!$setnow) {\r
- //debug('unset prevtype, no setnow');\r
- unset($this->_pv_prev_var_type);\r
- }\r
- unset($this->_pv_lastvar);\r
- $this->_pf_no_output_yet = false;\r
- // this does NewLinenum if necessary\r
- $this->_wp->backupPos($word);\r
- $this->_wp->getWord();\r
- if ($word[0] == T_OBJECT_OPERATOR) {\r
- $this->_wp->backupPos($word);\r
- } else {\r
- $this->_addoutput($word);\r
- }\r
- return;\r
- }\r
- if (!$this->_pf_obj_op && is_array($this->_pv_last_word) && \r
- $this->_pv_last_word[0] == T_OBJECT_OPERATOR\r
- ) {\r
- if ((isset($this->_pv_lastvar) && $this->_pv_lastvar[1] == '$this') ||\r
- isset($this->_pv_prev_var_type)\r
- ) {\r
- $this->_pf_obj_op = true;\r
- } else {\r
- $this->_pf_no_output_yet = false;\r
- // this does NewLinenum if necessary\r
- $this->_wp->backupPos($word);\r
- $this->_wp->getWord();\r
- $this->_addoutput($word);\r
- $this->_event_stack->popEvent();\r
- }\r
- }\r
- if (is_array($word) && $word == T_WHITESPACE) {\r
- $this->_pf_no_output_yet = false;\r
- // this does NewLinenum if necessary\r
- $this->_wp->backupPos($word);\r
- $this->_wp->getWord();\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- if ($this->_pf_obj_op) {\r
- if (!(is_array($word) && ($word[0] == T_STRING || \r
- $word[0] == T_WHITESPACE))\r
- ) {\r
- unset($this->_pv_lastvar);\r
- //debug('unset lastvar');\r
- $this->_event_stack->popEvent();\r
- $this->_pf_no_output_yet = false;\r
- // this does NewLinenum if necessary\r
- $this->_wp->backupPos($word);\r
- $this->_wp->getWord();\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- if ($word[0] == T_STRING) {\r
- //fancy_debug('set pvcmname to', $word);\r
- $this->_pv_cm_name = $word;\r
- } else {\r
- $this->_pf_no_output_yet = false;\r
- // this does NewLinenum if necessary\r
- $this->_wp->backupPos($word);\r
- $this->_wp->getWord();\r
- $this->_addoutput($word);\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * Handles comments\r
- *\r
- * Comments are almost always single-line tokens, and so will be\r
- * in the last word. This handler checks to see if the current token\r
- * is in fact a comment, and if it isn't, it backs up and returns control\r
- * to the parent event handler with that word.\r
- */\r
- function handleComment($word, $pevent)\r
- {\r
- $w = $this->_pv_last_word;\r
- // don't perform this check if this is a normal comment. Docblocks\r
- // have the _pf_no_output_yet variable set to true\r
- if ($this->_pf_no_output_yet && is_array($w) && \r
- (in_array($w[0], array(T_COMMENT, T_DOC_COMMENT)) && \r
- strpos($w[1], '/**') === 0)\r
- ) {\r
- $this->_event_stack->popEvent();\r
- $this->_event_stack->pushEvent(PARSER_EVENT_DOCBLOCK);\r
- return $this->handleDocBlock($word, PARSER_EVENT_DOCBLOCK);\r
- }\r
- if ($this->_pf_no_output_yet) {\r
- $flag = 1;\r
- $this->_pf_no_output_yet = false;\r
- $this->_addoutput($this->_pv_last_word);\r
- }\r
- if (!is_array($word) || \r
- !in_array($word[0], array(T_COMMENT, T_DOC_COMMENT)) ||\r
- (in_array($word[0], array(T_COMMENT, T_DOC_COMMENT)) && \r
- strpos($word[1], '/**') === 0)\r
- ) {\r
- $this->_event_stack->popEvent();\r
- if (strpos($this->_pv_last_word[1], "\n") !== false) {\r
- //$this->_wp->linenum++;\r
- //$this->newLineNum();\r
- }\r
- $this->_wp->backupPos($this->_pv_last_word);\r
- $this->_wp->getWord();\r
- //var_dump($this->_wp->nextToken());\r
- return;\r
- } elseif (isset($flag)) {\r
- $this->newLineNum();\r
- }\r
- $this->_addoutput($word);\r
- $this->checkEventPop($word, $pevent);\r
- if (strpos($word[1], '*/') === strlen($word[1]) - 2) {\r
- $this->_event_stack->popEvent();\r
- }\r
- }\r
- \r
- /**\r
- * Handle class declarations\r
- *\r
- * Handles the initial declaration line:\r
- *\r
- * <code>class X</code>\r
- * \r
- * or\r
- * \r
- * <code>class X extends Y implements I</code>\r
- *\r
- * @uses _classlink() to link to documentation for X and for Y class in\r
- * "class X extends Y"\r
- */\r
- function handleClass($word, $pevent)\r
- {\r
- $this->_pf_in_class = true;\r
- $a = $this->checkEventPush($word, $pevent);\r
-\r
- if (!isset($this->_pv_class) && is_array($word) && $word[0] == T_STRING) {\r
- $this->_pv_class = $this->_converter->class = $word[1];\r
- $this->_classlink($word);\r
- return;\r
- }\r
- \r
- if (is_array($word) && \r
- in_array($word[0], array(T_PRIVATE, T_PROTECTED, T_PUBLIC))\r
- ) {\r
- $starttok = $this->_wp->nextToken();\r
- $test = array(T_WHITESPACE);\r
- while ($test && $test[0] == T_WHITESPACE) {\r
- $tok = $this->_wp->nextToken();\r
- $test = $this->_wp->getWord();\r
- } // while\r
- \r
- if (is_array($test) && $test[0] == T_VARIABLE) {\r
- $this->_wp->backupPos($tok, true);\r
- return;\r
- }\r
- $this->_wp->backupPos($starttok, true);\r
- }\r
- \r
- if (@in_array($this->_pv_last_word[0], \r
- array(T_PRIVATE, T_PROTECTED, T_PUBLIC))\r
- ) {\r
- if (is_array($word) && $word[0] == T_VARIABLE) {\r
- $this->_wp->backupPos($this->_pv_last_word);\r
- $this->_event_stack->pushEvent(PARSER_EVENT_VAR);\r
- return;\r
- }\r
- }\r
-\r
- if ($this->_pf_extends_found && is_array($word) && $word[0] == T_STRING) {\r
- $this->_classlink($word);\r
- return;\r
- }\r
- if (is_array($word) && $word[0] == T_EXTENDS) {\r
- $this->_pf_extends_found = true;\r
- }\r
- if ($a == PARSER_EVENT_DOCBLOCK) {\r
- $this->_pf_no_output_yet = true;\r
- $this->_pv_saveline = $this->_wp->linenum + 1;\r
- return;\r
- }\r
- $this->_addoutput($word);\r
- if ($this->checkEventPop($word, $pevent)) {\r
- $this->_pf_in_class = false;\r
- unset($this->_pv_class);\r
- }\r
- }\r
- \r
- /**\r
- * Handles class variable declaration\r
- *\r
- * <code>\r
- * class X\r
- * {\r
- * var $Y;\r
- * }\r
- * </code>\r
- *\r
- * @uses _varlink() make a link to $Y documentation in class variable\r
- * declaration "var $Y;"\r
- */\r
- function handleVar($word, $pevent)\r
- {\r
- if ($this->checkEventPush($word, $pevent)) {\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- if (is_array($word) && $word[0] == T_VARIABLE) {\r
- return $this->_varlink($word);\r
- }\r
- $this->_addoutput($word);\r
- $this->checkEventPop($word, $pevent);\r
- }\r
- \r
- /**\r
- * This handler is responsible for highlighting DocBlocks\r
- *\r
- * handleDocBlock determines whether the docblock is normal or a template,\r
- * and gathers all the lines of the docblock together before doing any\r
- * processing\r
- *\r
- * As it is not possible to distinguish any comment token from a docblock\r
- * token, this handler is also called for comments, and will pass control\r
- * to {@link handleComment()} if the comment is not a DocBlock\r
- *\r
- * @uses commonDocBlock() once all lines of the DocBlock have been retrieved\r
- */\r
- function handleDocBlock($word, $pevent)\r
- {\r
- if (!($this->_pf_docblock || $this->_pf_docblock_template)) {\r
- if (strpos($this->_pv_last_word[1], '/**') !== 0) {\r
- // not a docblock\r
- $this->_wp->backupPos($this->_pv_last_word);\r
- $this->_event_stack->popEvent();\r
- $this->_event_stack->pushEvent(PARSER_EVENT_COMMENT);\r
- $this->_pf_no_output_yet = false;\r
- return;\r
- } else {\r
- $this->_pf_no_output_yet = true;\r
- $this->_pv_db_lines = array();\r
- }\r
- }\r
- $last_word = $this->_pv_last_word[1];\r
- $dtype = '_pv_docblock';\r
- if ($last_word == '/**#@-*/') {\r
- // stop using docblock template\r
- $this->_pf_no_output_yet = false;\r
- $this->_addDocBlockoutput('closetemplate', $last_word);\r
- if ($this->_pv_next_word !== false) {\r
- $this->_wp->backupPos($this->_pv_next_word, true);\r
- }\r
- $this->_event_stack->popEvent();\r
- return;\r
- }\r
- if (!($this->_pf_docblock || $this->_pf_docblock_template)) {\r
- $this->_pv_db_lines = array();\r
- if (strpos($last_word, '/**#@+') === 0) {\r
- // docblock template definition\r
- $this->_pf_docblock_template = true;\r
- } else {\r
- $this->_pf_docblock = true;\r
- }\r
- $this->_pv_db_lines[] = $last_word;\r
- if (strpos($last_word, '*/') !== false) {\r
- $this->commonDocBlock();\r
- return;\r
- }\r
- $this->_pv_db_lines[] = $word[1];\r
- if (strpos($word[1], '*/') !== false) {\r
- $this->commonDocBlock();\r
- }\r
- } else {\r
- $this->_pv_db_lines[] = $word[1];\r
- }\r
- if (($this->_pf_docblock || $this->_pf_docblock_template) && \r
- (strpos($word[1], '*/') !== false)\r
- ) {\r
- $this->commonDocBlock();\r
- }\r
- }\r
- /**#@-*/\r
-\r
- /**\r
- * This continuation of handleDocBlock splits DocBlock comments up into\r
- * phpDocumentor tokens. It highlights DocBlock templates in a different\r
- * manner from regular DocBlocks, recognizes inline tags, regular tags,\r
- * and distinguishes between standard core tags and other tags, and\r
- * recognizes parameters to tags like @var.\r
- *\r
- * the type in "@var type description" will be highlighted as a php type,\r
- * and the var in "@param type $var description" will be highlighted as a\r
- * php variable.\r
- *\r
- * @return void\r
- * @uses handleDesc() highlight inline tags in the description\r
- * @uses handleTags() highlight all tags\r
- * @access private\r
- */\r
- function commonDocBlock()\r
- {\r
- $this->_event_stack->popEvent();\r
- $lines = $this->_pv_db_lines;\r
- $go = count($this->_pv_db_lines);\r
- for ($i=0; $i < $go; $i++) {\r
- if (substr(trim($lines[$i]), 0, 2) == '*/' || \r
- substr(trim($lines[$i]), 0, 1) != '*' && \r
- substr(trim($lines[$i]), 0, 3) != '/**'\r
- ) {\r
- $lines[$i] = array($lines[$i], false);\r
- } elseif (substr(trim($lines[$i]), 0, 3) == '/**') {\r
- $linesi = array();\r
- // remove leading "/**"\r
- $linesi[1] = substr(trim($lines[$i]), 3);\r
- if (empty($linesi[1])) {\r
- $linesi[0] = $lines[$i];\r
- } else {\r
- $linesi[0] = \r
- substr($lines[$i], 0, strpos($lines[$i], $linesi[1]));\r
- }\r
- $lines[$i] = $linesi;\r
- } else {\r
- $linesi = array();\r
- // remove leading "* "\r
- $linesi[1] = substr(trim($lines[$i]), 1);\r
- if (empty($linesi[1])) {\r
- $linesi[0] = $lines[$i];\r
- } else {\r
- $linesi[0] = \r
- substr($lines[$i], 0, strpos($lines[$i], $linesi[1]));\r
- }\r
- $lines[$i] = $linesi;\r
- }\r
- }\r
- for ($i = 0; $i < count($lines); $i++) {\r
- if ($lines[$i][1] === false) {\r
- continue;\r
- }\r
- if (substr(trim($lines[$i][1]), 0, 1) == '@' && \r
- substr(trim($lines[$i][1]), 0, 2) != '@ '\r
- ) {\r
- $tagindex = $i;\r
- $i = count($lines);\r
- }\r
- }\r
- if (isset($tagindex)) {\r
- $tags = array_slice($lines, $tagindex);\r
- $desc = array_slice($lines, 0, $tagindex);\r
- } else {\r
- $tags = array();\r
- $desc = $lines;\r
- }\r
- //var_dump($desc, $tags);\r
- $this->_pf_no_output_yet = false;\r
- $save = $this->_wp->linenum;\r
- $this->_wp->linenum = $this->_pv_saveline;\r
- $this->handleDesc($desc);\r
- $this->handleTags($tags);\r
- $this->_pv_db_lines = array();\r
- $this->_wp->linenum = $save;\r
- if (strpos($this->_pv_last_word[1], '*/') !== false) {\r
- $this->_wp->backupPos($this->_pv_next_word, true);\r
- }\r
- $this->_pf_docblock = $this->_pf_docblock_template = false;\r
- }\r
- \r
- /**\r
- * Handle the description area of a DocBlock\r
- *\r
- * This method simply finds inline tags and highlights them\r
- * separately from the rest of the description.\r
- *\r
- * @param mixed $desc the description piece(s)\r
- *\r
- * @return void\r
- * @uses getInlineTags()\r
- * @access private\r
- */\r
- function handleDesc($desc)\r
- {\r
- $dbtype = 'docblock';\r
- $dbtype .= ($this->_pf_docblock ? '' : 'template');\r
- foreach ($desc as $line) {\r
- $this->getInlineTags($line[0] . $line[1]);\r
- if (strpos($line[0], '*/') === false &&\r
- !(substr($line[0], 0, 2) == '/*' && \r
- strpos($line[1], '*/') !== false)\r
- ) {\r
- $this->newLineNum();\r
- $this->_wp->linenum++;\r
- }\r
- }\r
- if ($this->_pf_internal) {\r
- $this->_pf_internal = false;\r
- }\r
- }\r
- \r
- /**\r
- * Handle phpDocumentor tags in a DocBlock\r
- *\r
- * This method uses the {@link $tagHandlers} array to determine which\r
- * method will handle tags found in the docblock, and passes the data to\r
- * the individual handlers one by one\r
- *\r
- * @param array $tags array of tags to handle\r
- *\r
- * @return void\r
- * @access private\r
- */\r
- function handleTags($tags)\r
- {\r
- $newtags = array();\r
- $curtag = array();\r
- for ($i=0; $i < count($tags); $i++) {\r
- $tagsi = trim($tags[$i][1]);\r
- if (substr($tagsi, 0, 1) == '@' && substr($tagsi, 0, 2) != '@ ') {\r
- // start a new tag\r
- $tags[$i][1] = array(substr($tags[$i][1], 0, \r
- strpos($tags[$i][1], $tagsi)), $tagsi);\r
- if (!empty($curtag)) {\r
- $newtags[] = $curtag;\r
- $curtag = array();\r
- }\r
- $curtag[] = $tags[$i];\r
- } else {\r
- $curtag[] = $tags[$i];\r
- }\r
- }\r
- if (!empty($curtag)) {\r
- $newtags[] = $curtag;\r
- }\r
- foreach ($newtags as $tag) {\r
- foreach ($tag as $i => $t) {\r
- if ($t[1] === false) {\r
- continue;\r
- }\r
- if (is_array($t[1])) {\r
- $tag[$i][1][1]\r
- = explode(" ", str_replace("\t", ' ', $t[1][1]));\r
- $x = $tag[$i][1][1];\r
- }\r
- }\r
- $tagname = substr(array_shift($x), 1);\r
- $restoftag = $tag;\r
- if (isset($this->tagHandlers[$tagname])) {\r
- $handle = $this->tagHandlers[$tagname];\r
- } else {\r
- $handle = $this->tagHandlers['*'];\r
- }\r
- $this->$handle($tagname, $restoftag);\r
- }\r
- }\r
- \r
- /**\r
- * This handler recognizes all {@}inline} tags\r
- *\r
- * Normal inline tags are simply highlighted. the {@}internal}} inline\r
- * tag {@tutorial tags.inlineinternal.pkg} is highlighted differently\r
- * to distinguish it from other inline tags.\r
- *\r
- * @param mixed $value the tag value\r
- * @param bool $endinternal indicates the end of an @internal tag\r
- *\r
- * @return void\r
- * @access private\r
- */\r
- function getInlineTags($value, $endinternal = false)\r
- {\r
- if (!$value) {\r
- return;\r
- }\r
- if ($this->_pf_internal && !$endinternal) {\r
- if (strpos($value, '}}') !== false) {\r
- $x = strrpos($value, '}}');\r
- // add the rest of internal\r
- $this->getInlineTags(substr($value, 0, $x + 3), true);\r
- // strip internal from value\r
- $value = substr($value, strrpos($value, '}}') + 1);\r
- // turn off internal\r
- $this->_pf_internal = false;\r
- }\r
- }\r
- if (!$value) {\r
- return;\r
- }\r
- $dbtype = 'docblock';\r
- $dbtype .= ($this->_pf_docblock ? '' : 'template');\r
- $save = $value;\r
- $value = explode('{@', $value);\r
- $newval = array();\r
- // everything before the first {@ is normal text\r
- $this->_addDocBlockoutput($dbtype, $value[0]);\r
- for ($i=1; $i < count($value); $i++) {\r
- if (substr($value[$i], 0, 1) == '}') {\r
- $this->_addDocBlockoutput($dbtype, '{@}' . substr($value[$i], 1));\r
- } else {\r
- $save = $value[$i];\r
- $value[$i] = str_replace("\t", " ", $value[$i]);\r
- $value[$i] = explode(" ", $value[$i]);\r
- $word = array_shift($value[$i]);\r
- $val = join(' ', $value[$i]);\r
- if ($word == 'internal') {\r
- $this->_pf_internal = true;\r
- $this->_addDocBlockoutput($dbtype, '{@internal ');\r
- $value[$i] = substr($save, strlen('internal') + 1);\r
- // strip internal and cycle as if it were normal text.\r
- $this->_addDocBlockoutput($dbtype, $value[$i]);\r
- continue;\r
- }\r
- if (in_array(str_replace('}', '', $word), $this->allowableInlineTags)\r
- ) {\r
- if (strpos($word, '}')) {\r
- $word = str_replace('}', '', $word);\r
- $val = '} ' . $val;\r
- }\r
- $val = explode('}', $val);\r
- if (count($val) == 1) {\r
- //addError(PDERROR_UNTERMINATED_INLINE_TAG,\r
- // $word, '', $save);\r
- }\r
- $rest = $val;\r
- $val = array_shift($rest);\r
- if ($endinternal) {\r
- $rest = join('}', $rest);\r
- } else {\r
- $rest = join(' ', $rest);\r
- }\r
- if (isset($this->inlineTagHandlers[$word])) {\r
- $handle = $this->inlineTagHandlers[$word];\r
- } else {\r
- $handle = $this->inlineTagHandlers['*'];\r
- }\r
- $this->$handle($word, $val);\r
- $this->_addDocBlockoutput($dbtype, $rest);\r
- } else {\r
- $val = $word . ' ' . $val;\r
- $this->_addDocBlockoutput($dbtype, '{@' . $val);\r
- }\r
- }\r
- }\r
- }\r
-\r
- \r
- /**\r
- * Handles all inline tags\r
- *\r
- * @param string $name the tag name\r
- * @param mixed $value the tag value\r
- *\r
- * @return void\r
- * @access private\r
- */\r
- function handleDefaultInlineTag($name, $value)\r
- {\r
- $this->_addDocBlockoutput('inlinetag', '{@' . $name . ' ' . $value . '}');\r
- }\r
-\r
- /**#@+\r
- * phpDocumentor DocBlock tag handlers\r
- *\r
- * @param string $name tag name\r
- * @param array $value array of lines contained in the tag description\r
- *\r
- * @return void\r
- * @access private\r
- */\r
- /**\r
- * Handle normal tags\r
- *\r
- * This handler adds to outpu all comment information before the tag begins\r
- * as in " * " before "@todo" in " * @todo"\r
- *\r
- * Then, it highlights the tag as a regular or coretag based on $coretag.\r
- * Finally, it uses getInlineTags to highlight the description\r
- *\r
- * @param bool $coretag whether this tag is a core tag or not\r
- *\r
- * @uses getInlineTags() highlight a tag description\r
- */\r
- function defaultTagHandler($name, $value, $coretag = false)\r
- {\r
- $dbtype = 'docblock';\r
- $dbtype .= ($this->_pf_docblock ? '' : 'template');\r
- foreach ($value as $line) {\r
- $this->_addDocBlockoutput($dbtype, $line[0]);\r
- if ($line[1] === false) {\r
- if (trim($line[0]) != '*/') {\r
- $this->newLineNum();\r
- $this->_wp->linenum++;\r
- }\r
- continue;\r
- }\r
- $this->_addDocBlockoutput($dbtype, $line[1][0]);\r
- $stored = '';\r
- if (is_array($line[1][1])) {\r
- foreach ($line[1][1] as $i => $tpart) {\r
- if ($tpart == '@' . $name && $i == 0) {\r
- $tagname = 'tag';\r
- if ($coretag) {\r
- $tagname = 'coretag';\r
- }\r
- $this->_addDocBlockoutput($tagname, '@' . $name);\r
- continue;\r
- }\r
- $stored .= ' ' . $tpart;\r
- }\r
- } else {\r
- $stored = $line[1];\r
- }\r
- $this->getInlineTags($stored);\r
- if (strpos($stored, '*/') === false) {\r
- $this->newLineNum();\r
- $this->_wp->linenum++;\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * main handler for "core" tags\r
- *\r
- * @see defaultTagHandler()\r
- */\r
- function coreTagHandler($name, $value)\r
- {\r
- return $this->defaultTagHandler($name, $value, true);\r
- }\r
- \r
- /**\r
- * Handles @global\r
- *\r
- * This handler works like {@link defaultTagHandler()} except it highlights\r
- * the type and variable (if present) in "@global type $variable" or\r
- * "@global type description"\r
- */\r
- function globalTagHandler($name, $value)\r
- {\r
- $this->paramTagHandler($name, $value);\r
- }\r
- \r
- /**\r
- * Handles @param\r
- *\r
- * This handler works like {@link defaultTagHandler()} except it highlights\r
- * the type and variable (if present) in "@param type $variable description"\r
- * or "@param type description"\r
- *\r
- * @param bool $checkforvar private parameter, checks for $var or not\r
- */\r
- function paramTagHandler($name, $value, $checkforvar = true)\r
- {\r
- $dbtype = 'docblock';\r
- $dbtype .= ($this->_pf_docblock ? '' : 'template');\r
- $ret = $this->retrieveType($value, 0, $checkforvar);\r
- foreach ($value as $num => $line) {\r
- $this->_addDocBlockoutput($dbtype, $line[0]);\r
- if ($line[1] === false) {\r
- if (trim($line[0]) != '*/') {\r
- $this->newLineNum();\r
- $this->_wp->linenum++;\r
- }\r
- continue;\r
- }\r
- $this->_addDocBlockoutput($dbtype, $line[1][0]);\r
- $stored = '';\r
- $typeloc = 1;\r
- $varloc = 2;\r
- if (is_array($line[1][1])) {\r
- $this->_addDocBlockoutput('coretag', '@' . $name . ' ');\r
- foreach ($ret[0] as $text) {\r
- if (is_string($text)) {\r
- $this->_addDocBlockoutput($dbtype, $text);\r
- }\r
- if (is_array($text)) {\r
- if ($text[0] != 'desc') {\r
- $this->_addDocBlockoutput($text[0], $text[1]);\r
- } else {\r
- $stored .= $text[1];\r
- }\r
- }\r
- }\r
- } else {\r
- if (isset($ret[$num])) {\r
- foreach ($ret[$num] as $text) {\r
- if (is_string($text)) {\r
- $this->_addDocBlockoutput($dbtype, $text);\r
- }\r
- if (is_array($text)) {\r
- if ($text[0] != 'desc') {\r
- $this->_addDocBlockoutput($text[0], $text[1]);\r
- } else {\r
- $stored .= $text[1];\r
- }\r
- }\r
- }\r
- } else {\r
- $stored = $line[1];\r
- }\r
- }\r
- $this->getInlineTags($stored);\r
- if (strpos($stored, '*/') === false) {\r
- $this->newLineNum();\r
- $this->_wp->linenum++;\r
- }\r
- }\r
- }\r
- \r
- /**\r
- * handles the @staticvar tag\r
- *\r
- * @see paramTagHandler()\r
- */\r
- function staticvarTagHandler($name, $value)\r
- {\r
- return $this->paramTagHandler($name, $value);\r
- }\r
- \r
- /**\r
- * handles the @var tag\r
- *\r
- * @see paramTagHandler()\r
- */\r
- function varTagHandler($name, $value)\r
- {\r
- return $this->paramTagHandler($name, $value);\r
- }\r
- \r
- /**\r
- * Handles @return\r
- *\r
- * This handler works like {@link defaultTagHandler()} except it highlights\r
- * the type in "@return type description"\r
- */\r
- function returnTagHandler($name, $value)\r
- {\r
- $this->paramTagHandler($name, $value, false);\r
- }\r
-\r
- /**\r
- * Handles @property(-read or -write) and @method magic tags\r
- */\r
- function propertyTagHandler($name, $value)\r
- {\r
- return $this->paramTagHandler($name, $value, true);\r
- }\r
-\r
- /**#@-*/\r
- \r
- /**\r
- * Retrieve the type portion of a @tag type description\r
- *\r
- * Tags like @param, @return and @var all have a PHP type portion in their\r
- * description. Since the type may contain the expression "object blah"\r
- * where blah is a classname, it makes parsing out the type field complex.\r
- *\r
- * Even more complicated is the case where a tag variable can contain\r
- * multiple types, such as object blah|object blah2|false, and so this\r
- * method handles these cases.\r
- *\r
- * @param array $value array of words that were separated by spaces\r
- * @param 0|1 $state 0 = find the type, 1 = find the var, if present\r
- * @param bool $checkforvar flag to determine whether to check for the end of a\r
- * type is defined by a $varname\r
- *\r
- * @return array Format: array(state (0 [find type], 1 [var], 2 [done]),\r
- * @access private\r
- */\r
- function retrieveType($value, $state = 0, $checkforvar = false)\r
- {\r
- $index = 0;\r
- $result = array();\r
- do {\r
- if (!isset($value[$index][1])) {\r
- return $result;\r
- }\r
- $val = $value[$index][1];\r
- if (empty($val)) {\r
- return $result;\r
- }\r
- if ($index == 0) {\r
- $val = $val[1];\r
- array_shift($val);\r
- } else {\r
- $val = explode(' ', $val);\r
- }\r
- $ret = $this->_retrieveType($val, $state, $checkforvar);\r
- $state = $ret[0];\r
- $result[$index++] = $ret[1];\r
- } while ((!$checkforvar && $state < 1) || ($state < 2 && $checkforvar));\r
- return $result;\r
- }\r
-\r
- /**\r
- * used by {@link retrieveType()} in its work\r
- *\r
- * @param array $value array of words that were separated by spaces\r
- * @param 0|1 $state 0 = find the type, 1 = find the var, if present\r
- * @param bool $checkforvar flag to determine whether to check for the end of a\r
- * type is defined by a $varname\r
- *\r
- * @return array \r
- * @access private\r
- */ \r
- function _retrieveType($value, $state, $checkforvar)\r
- {\r
- $result = array();\r
- $result[] = $this->_removeWhiteSpace($value, 0);\r
- if ($state == 0) {\r
- if (!count($value)) {\r
- return array(2, $result);\r
- }\r
- $types = '';\r
- $index = 0;\r
- if (trim($value[0]) == 'object') {\r
- $result[] = array('tagphptype', $value[0] . ' ');\r
- $types .= array_shift($value).' ';\r
- $result[] = $this->_removeWhiteSpace($value, 0);\r
- if (!count($value)) {\r
- // was just passed "object"\r
- return array(2, $result);\r
- }\r
- if ($value[0]{0} == '$' || substr($value[0], 0, 2) == '&$') {\r
- // was just passed "object"\r
- // and the next thing is a variable name\r
- if ($checkforvar) {\r
- $result[] = array('tagvarname' , $value[0] . ' ');\r
- array_shift($value);\r
- }\r
- $result[] = array('desc', join(' ', $value));\r
- return array(2, $result);\r
- }\r
- }\r
- $done = false;\r
- $loop = -1;\r
- do {\r
- // this loop checks for type|type|type and for\r
- // type|object classname|type|object classname2\r
- if (strpos($value[0], '|')) {\r
- $temptypes = explode('|', $value[0]);\r
- while (count($temptypes)) {\r
- $type = array_shift($temptypes);\r
- $result[] = array('tagphptype', $type);\r
- if (count($temptypes)) {\r
- $result[] = '|';\r
- }\r
- }\r
- if (trim($type) == 'object') {\r
- $result[] = array('tagphptype', $types . ' ');\r
- $result[] = $this->_removeWhiteSpace($value, 0);\r
- } else {\r
- $done = true;\r
- }\r
- array_shift($value);\r
- if (count($value) && strlen($value[0]) && isset ($value[0]) && \r
- ($value[0]{0} == '$' || substr($value[0], 0, 2) == '&$')\r
- ) {\r
- // was just passed "object"\r
- // and the next thing is a variable name\r
- $result[] = array('tagvarname' , $value[0] . ' ');\r
- array_shift($value);\r
- $result[] = array('desc', join(' ', $value));\r
- return array(2, $result);\r
- }\r
- } else {\r
- $result[] = array('tagphptype', $value[0] . ' ');\r
- array_shift($value);\r
- $done = true;\r
- }\r
- $loop++;\r
- } while (!$done && count($value));\r
- if ($loop) {\r
- $result[] = ' ';\r
- }\r
- // still searching for type\r
- if (!$done && !count($value)) {\r
- return array(0, $result);\r
- }\r
- // still searching for var\r
- if ($done && !count($value)) {\r
- return array(1, $result);\r
- }\r
- }\r
- $result[] = $this->_removeWhiteSpace($value, 0);\r
- $state = 1;\r
- if ($checkforvar) {\r
- if (count($value)) {\r
- $state = 2;\r
- if (substr($value[0], 0, 1) == '$' || \r
- substr($value[0], 0, 2) == '&$'\r
- ) {\r
- $result[] = array('tagvarname' , $value[0] . ' ');\r
- array_shift($value);\r
- }\r
- } else {\r
- $state = 1;\r
- }\r
- }\r
- $result[] = array('desc', join(' ', $value));\r
- return array($state, $result);\r
- }\r
- \r
- /**\r
- * captures trailing whitespace\r
- *\r
- * @param array &$value array of string\r
- * @param int $index index to seek non-whitespace to\r
- *\r
- * @return string whitespace\r
- * @access private\r
- */\r
- function _removeWhiteSpace(&$value, $index)\r
- {\r
- $result = '';\r
- if (count($value) > $index && empty($value[$index])) {\r
- $found = false;\r
- for ($i = $index; $i < count($value) && !strlen($value[$i]); $i++) {\r
- $result .= ' ';\r
- }\r
- array_splice($value, $index, $i - $index);\r
- }\r
- return $result;\r
- }\r
-\r
- /**#@+\r
- * Link generation methods\r
- *\r
- * @param string|array $word token to try to link\r
- *\r
- * @access private\r
- */\r
- /**\r
- * Generate a link to documentation for an element\r
- *\r
- * This method tries to link to documentation for functions, methods,\r
- * PHP functions, class names, and if found, adds the links to output\r
- * instead of plain text\r
- */\r
- function _link($word)\r
- {\r
- if (is_array($word) && $word[0] == T_STRING) {\r
- if ($this->_pf_colon_colon) {\r
- $this->_pf_colon_colon = false;\r
-\r
- $combo = $this->_pv_last_string[1] . '::' . $word[1] . '()';\r
- //debug('testing ' . $combo);\r
- $link = $this->_converter->getLink($combo);\r
- if (is_object($link)) {\r
- $this->_addoutput($this->_converter->returnSee($link,\r
- $word[1]), true);\r
- return;\r
- }\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- $link = $this->_converter->getLink($word[1] . '()');\r
- if (is_object($link)) {\r
- $this->_addoutput($this->_converter->returnSee($link,\r
- $word[1]), true);\r
- return;\r
- } elseif (is_string($link) && strpos($link, 'ttp://')) {\r
- $this->_addoutput($this->_converter->returnLink($link,\r
- $word[1]), true);\r
- return;\r
- } else {\r
- $link = $this->_converter->getLink($word[1]);\r
- if (is_object($link)) {\r
- $word[1] = $this->_converter->returnSee($link, $word[1]);\r
- }\r
- $this->_addoutput($word, true);\r
- return;\r
- }\r
- }\r
- $this->_addoutput($word);\r
- }\r
- \r
- /**\r
- * Works like {@link _link()} except it only links to global variables\r
- */\r
- function _globallink($word)\r
- {\r
- if (!is_array($word)) {\r
- return $this->_addoutput($word);\r
- }\r
- if ($word[0] != T_VARIABLE) {\r
- return $this->_addoutput($word);\r
- }\r
- if (is_array($word) && $word[0] == T_VARIABLE) {\r
- $link = $this->_converter->getLink('global ' . $word[1]);\r
- if (is_object($link)) {\r
- $this->_addoutput($this->_converter->returnSee($link,\r
- $word[1]), true);\r
- return;\r
- }\r
- }\r
- $this->_addoutput($word);\r
- }\r
- \r
- /**\r
- * Works like {@link _link()} except it only links to classes\r
- */\r
- function _classlink($word)\r
- {\r
- //debug("checking class " . $word[1]);\r
- if (is_array($word) && $word[0] == T_STRING) {\r
- $link = $this->_converter->getLink($word[1]);\r
- if (is_object($link)) {\r
- $this->_addoutput($this->_converter->returnSee($link,\r
- $word[1]), true);\r
- return;\r
- }\r
- }\r
- $this->_addoutput($word);\r
- }\r
- \r
- /**\r
- * Works like {@link _link()} except it only links to methods\r
- */\r
- function _methodlink($word)\r
- {\r
- if (is_array($word) && $word[0] == T_STRING) {\r
- //debug("checking method " . $this->_pv_class . '::' . $word[1] . '()');\r
- if (isset($this->_pv_prev_var_type)) {\r
- $link = $this->_converter->getLink($this->_pv_prev_var_type . '::' .\r
- $word[1] . '()');\r
- } else {\r
- $link = $this->_converter->getLink($this->_pv_class . '::' . \r
- $word[1] . '()');\r
- }\r
- if (is_object($link)) {\r
- $this->_addoutput($this->_converter->returnSee($link,\r
- $word[1]), true);\r
- return;\r
- }\r
- if (isset($this->_pv_prev_var_type)) {\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- //debug("checking method " . $word[1] . '()');\r
- $link = $this->_converter->getLink($word[1] . '()');\r
- if (is_object($link)) {\r
- $this->_addoutput($this->_converter->returnSee($link,\r
- $word[1]), true);\r
- return;\r
- }\r
- }\r
- $this->_addoutput($word);\r
- }\r
- \r
- /**\r
- * Works like {@link _link()} except it only links to class variables\r
- *\r
- * @param bool $justastring true if the $word is only a string\r
- */\r
- function _varlink($word, $justastring=false)\r
- {\r
- if ($justastring) {\r
- $word[0] = T_VARIABLE;\r
- }\r
- if (is_array($word) && $word[0] == T_VARIABLE) {\r
- $x = ($justastring ? '$' : '');\r
- //debug("checking var " . $this->_pv_class . '::' . $x . $word[1]);\r
- if (isset($this->_pv_prev_var_type)) {\r
- //debug("checking var " . $this->_pv_prev_var_type . '::' .\r
- // $x . $word[1]);\r
- $link = $this->_converter->getLink($this->_pv_prev_var_type . '::' .\r
- $x . $word[1]);\r
- } else {\r
- $link = $this->_converter->getLink($this->_pv_class . '::' . \r
- $x . $word[1]);\r
- }\r
- if (is_object($link)) {\r
- $this->_addoutput($this->_converter->returnSee($link,\r
- $word[1]), true);\r
- return;\r
- }\r
- //debug("checking var " . $x . $word[1]);\r
- if (isset($this->_pv_prev_var_type)) {\r
- $this->_addoutput($word);\r
- return;\r
- }\r
- $link = $this->_converter->getLink($x . $word[1]);\r
- if (is_object($link)) {\r
- $this->_addoutput($this->_converter->returnSee($link,\r
- $word[1]), true);\r
- return;\r
- }\r
- }\r
- $this->_addoutput($word);\r
- }\r
- /**#@-*/\r
- \r
- /**#@+\r
- * Output Methods\r
- * @access private\r
- */\r
- /**\r
- * This method adds output to {@link $_line}\r
- *\r
- * If a string with variables like "$test this" is present, then special\r
- * handling is used to allow processing of the variable in context.\r
- *\r
- * @param mixed $word the string|array tag token and value\r
- * @param bool $preformatted whether or not the $word is already formatted\r
- *\r
- * @return void\r
- * @see _flush_save()\r
- */\r
- function _addoutput($word, $preformatted = false)\r
- {\r
- if ($this->_pf_no_output_yet) {\r
- return;\r
- }\r
- if ($this->_pf_quote_active) {\r
- if (is_array($word)) {\r
- $this->_save .= $this->_converter->highlightSource($word[0],\r
- $word[1]);\r
- } else {\r
- $this->_save .= $this->_converter->highlightSource(false,\r
- $word, true);\r
- }\r
- } else {\r
- $this->_flush_save();\r
- if (is_string($word) && trim($word) == '') {\r
- $this->_line .= $this->_converter->postProcess($word);\r
- return;\r
- }\r
- if (is_array($word) && trim($word[1]) == '') {\r
- $this->_line .= $this->_converter->postProcess($word[1]);\r
- return;\r
- }\r
- if (is_array($word)) {\r
- $this->_line .= $this->_converter->highlightSource($word[0],\r
- $word[1], $preformatted);\r
- } else {\r
- $this->_line .= $this->_converter->highlightSource(false,\r
- $word, $preformatted);\r
- }\r
- }\r
- }\r
- \r
- /** \r
- * Like {@link _output()}, but for DocBlock highlighting\r
- *\r
- * @param mixed $dbtype the docblock type\r
- * @param mixed $word the string|array tag token and value\r
- * @param bool $preformatted whether or not the $word is already formatted\r
- *\r
- * @return void\r
- */\r
- function _addDocBlockoutput($dbtype, $word, $preformatted = false)\r
- {\r
- if ($this->_pf_internal) {\r
- $this->_line .= $this->_converter->highlightDocBlockSource('internal',\r
- $word, $preformatted);\r
- } else {\r
- $this->_line .= $this->_converter->highlightDocBlockSource($dbtype,\r
- $word, $preformatted);\r
- }\r
- }\r
- \r
- /**\r
- * Flush a saved string variable highlighting\r
- *\r
- * {@source}\r
- *\r
- * @return void\r
- * @todo CS cleanup - rename to _flushSave() for camelCase rule\r
- */\r
- function _flush_save()\r
- {\r
- if (!empty($this->_save)) {\r
- $this->_save .= $this->_converter->flushHighlightCache();\r
- // clear the existing cache, reset it to the old value\r
- if (isset($this->_save_highlight_state)) {\r
- $this->_converter->\r
- _setHighlightCache($this->_save_highlight_state[0],\r
- $this->_save_highlight_state[1]);\r
- }\r
- $this->_line .= $this->_converter->\r
- highlightSource(T_CONSTANT_ENCAPSED_STRING, $this->_save, true);\r
- $this->_save = '';\r
- }\r
- }\r
- /**#@-*/\r
- \r
- /**\r
- * Give the word parser necessary data to begin a new parse\r
- *\r
- * @param array &$data all tokens separated by line number\r
- *\r
- * @return void\r
- */\r
- function configWordParser(&$data)\r
- {\r
- $this->_wp->setup($data, $this);\r
- $this->_wp->setWhitespace(true);\r
- }\r
-\r
- /**\r
- * Initialize all parser state variables\r
- *\r
- * @param bool $inlinesourceparse true if we are highlighting an inline \r
- * {@}source} tag's output\r
- * @param false|string $class name of class we are going \r
- * to start from\r
- *\r
- * @return void\r
- * @uses $_wp sets to a new {@link phpDocumentor_HighlightWordParser}\r
- */\r
- function setupStates($inlinesourceparse, $class)\r
- {\r
- $this->_output = '';\r
- $this->_line = '';\r
- unset($this->_wp);\r
- $this->_wp = new phpDocumentor_HighlightWordParser;\r
- $this->_event_stack = new EventStack;\r
- if ($inlinesourceparse) {\r
- $this->_event_stack->pushEvent(PARSER_EVENT_PHPCODE);\r
- if ($class) {\r
- $this->_event_stack->pushEvent(PARSER_EVENT_CLASS);\r
- $this->_pv_class = $class;\r
- }\r
- } else {\r
- $this->_pv_class = null;\r
- }\r
-\r
- $this->_pv_define = null;\r
- $this->_pv_define_name = null;\r
- $this->_pv_define_value = null;\r
- $this->_pv_define_params_data = null;\r
- $this->_pv_dtype = null;\r
- $this->_pv_docblock = null;\r
- $this->_pv_dtemplate = null;\r
- $this->_pv_func = null;\r
- $this->_pv_global_name = null;\r
- $this->_pv_global_val = null;\r
- $this->_pv_globals = null;\r
- $this->_pv_global_count = null;\r
- $this->_pv_include_params_data = null;\r
- $this->_pv_include_name = null;\r
- $this->_pv_include_value = null;\r
- $this->_pv_linenum = null;\r
- $this->_pv_periodline = null;\r
- $this->_pv_paren_count = 0;\r
- $this->_pv_statics = null;\r
- $this->_pv_static_count = null;\r
- $this->_pv_static_val = null;\r
- $this->_pv_quote_data = null;\r
- $this->_pv_function_data = null;\r
- $this->_pv_var = null;\r
- $this->_pv_varname = null;\r
- $this->_pf_definename_isset = false;\r
- $this->_pf_extends_found = false;\r
- $this->_pf_includename_isset = false;\r
- $this->_pf_get_source = false;\r
- $this->_pf_getting_source = false;\r
- $this->_pf_in_class = false;\r
- $this->_pf_in_define = false;\r
- $this->_pf_in_global = false;\r
- $this->_pf_in_include = false;\r
- $this->_pf_in_var = false;\r
- $this->_pf_funcparam_val = false;\r
- $this->_pf_quote_active = false;\r
- $this->_pf_reset_quote_data = true;\r
- $this->_pf_useperiod = false;\r
- $this->_pf_var_equals = false;\r
- $this->_pf_obj_op = false;\r
- $this->_pf_docblock = false;\r
- $this->_pf_docblock_template = false;\r
- $this->_pf_colon_colon = false;\r
- $this->_pv_last_string = false;\r
- $this->_pf_inmethod = false;\r
- $this->_pf_no_output_yet = false;\r
- $this->_pv_saveline = 0;\r
- $this->_pv_next_word = false;\r
- $this->_save = '';\r
- }\r
-\r
- /**\r
- * Initialize the {@link $tokenpushEvent, $wordpushEvent} arrays\r
- *\r
- * @return void\r
- */\r
- function phpDocumentor_HighlightParser()\r
- {\r
- if (!defined('T_INTERFACE')) {\r
- define('T_INTERFACE', -1);\r
- }\r
- $this->allowableTags\r
- = $GLOBALS['_phpDocumentor_tags_allowed'];\r
- $this->allowableInlineTags\r
- = $GLOBALS['_phpDocumentor_inline_doc_tags_allowed'];\r
- $this->inlineTagHandlers\r
- = array('*' => 'handleDefaultInlineTag');\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_NOEVENTS] = \r
- array(\r
- T_OPEN_TAG => PARSER_EVENT_PHPCODE,\r
- );\r
-\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_PHPCODE] = \r
- array(\r
- T_FUNCTION => PARSER_EVENT_FUNCTION,\r
- T_CLASS => PARSER_EVENT_CLASS,\r
- T_INTERFACE => PARSER_EVENT_CLASS,\r
- T_INCLUDE_ONCE => PARSER_EVENT_INCLUDE,\r
- T_INCLUDE => PARSER_EVENT_INCLUDE,\r
- T_START_HEREDOC => PARSER_EVENT_EOFQUOTE,\r
- T_REQUIRE => PARSER_EVENT_INCLUDE,\r
- T_REQUIRE_ONCE => PARSER_EVENT_INCLUDE,\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpushEvent[PARSER_EVENT_PHPCODE] =\r
- array(\r
- "define" => PARSER_EVENT_DEFINE,\r
- '"' => PARSER_EVENT_QUOTE,\r
- '\'' => PARSER_EVENT_QUOTE,\r
- );\r
- /**************************************************************/\r
-\r
- $this->wordpushEvent[PARSER_EVENT_FUNCTION] =\r
- array(\r
- '{' => PARSER_EVENT_LOGICBLOCK,\r
- '(' => PARSER_EVENT_FUNCTION_PARAMS,\r
- );\r
- $this->tokenpushEvent[PARSER_EVENT_FUNCTION] =\r
- array(\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_FUNCTION] = array("}");\r
- /**************************************************************/\r
-\r
- $this->tokenpopEvent[PARSER_EVENT_EOFQUOTE] = array(T_END_HEREDOC);\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_FUNCTION_PARAMS] =\r
- array(\r
- T_CONSTANT_ENCAPSED_STRING => PARSER_EVENT_QUOTE,\r
- T_ARRAY => PARSER_EVENT_ARRAY,\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpushEvent[PARSER_EVENT_FUNCTION_PARAMS] =\r
- array(\r
- '"' => PARSER_EVENT_QUOTE,\r
- "'" => PARSER_EVENT_QUOTE,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_FUNCTION_PARAMS] = array(")");\r
- /**************************************************************/\r
-\r
- $this->wordpushEvent[PARSER_EVENT_LOGICBLOCK] = \r
- array(\r
- "{" => PARSER_EVENT_LOGICBLOCK,\r
- '"' => PARSER_EVENT_QUOTE,\r
- );\r
- $this->tokenpushEvent[PARSER_EVENT_LOGICBLOCK] =\r
- array(\r
- T_GLOBAL => PARSER_EVENT_FUNC_GLOBAL,\r
- T_STATIC => PARSER_EVENT_STATIC_VAR,\r
- T_START_HEREDOC => PARSER_EVENT_EOFQUOTE,\r
- T_CURLY_OPEN => PARSER_EVENT_LOGICBLOCK,\r
- T_DOLLAR_OPEN_CURLY_BRACES => PARSER_EVENT_LOGICBLOCK,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_LOGICBLOCK] = array("}");\r
- $this->tokenpopEvent[PARSER_EVENT_LOGICBLOCK] = array(T_CURLY_OPEN);\r
-\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_ARRAY] = \r
- array(\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_ARRAY] = array(")");\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_FUNC_GLOBAL] =\r
- array(\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_FUNC_GLOBAL] = array(";");\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_STATIC_VAR] =\r
- array(\r
- T_CONSTANT_ENCAPSED_STRING => PARSER_EVENT_QUOTE,\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpushEvent[PARSER_EVENT_STATIC_VAR] =\r
- array(\r
- "=" => PARSER_EVENT_STATIC_VAR_VALUE,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_STATIC_VAR] = array(";");\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_STATIC_VAR_VALUE] = \r
- array(\r
- T_CONSTANT_ENCAPSED_STRING => PARSER_EVENT_QUOTE,\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- T_ARRAY => PARSER_EVENT_ARRAY,\r
- );\r
- $this->wordpushEvent[PARSER_EVENT_STATIC_VAR_VALUE] =\r
- array(\r
- '"' => PARSER_EVENT_QUOTE,\r
- "'" => PARSER_EVENT_QUOTE,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_STATIC_VAR_VALUE] = array(";", ",");\r
- /**************************************************************/\r
- $this->tokenpushEvent[PARSER_EVENT_QUOTE] = \r
- array(\r
- T_OBJECT_OPERATOR => PARSER_EVENT_CLASS_MEMBER,\r
- T_CURLY_OPEN => PARSER_EVENT_QUOTE_VAR,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_QUOTE] = array('"');\r
- /**************************************************************/\r
- $this->tokenpushEvent[PARSER_EVENT_QUOTE_VAR] = \r
- array(\r
- T_OBJECT_OPERATOR => PARSER_EVENT_CLASS_MEMBER,\r
- T_CURLY_OPEN => PARSER_EVENT_QUOTE_VAR,\r
- );\r
- $this->wordpushEvent[PARSER_EVENT_QUOTE_VAR] =\r
- array(\r
- "{" => PARSER_EVENT_QUOTE_VAR,\r
- '"' => PARSER_EVENT_QUOTE_VAR,\r
- "'" => PARSER_EVENT_QUOTE_VAR,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_QUOTE_VAR] = array('}');\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_DEFINE] = \r
- array(\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- T_CONSTANT_ENCAPSED_STRING => PARSER_EVENT_QUOTE,\r
- );\r
- $this->wordpushEvent[PARSER_EVENT_DEFINE] = \r
- array(\r
- "(" => PARSER_EVENT_DEFINE_PARAMS,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_DEFINE] = array(";");\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_DEFINE_PARAMS] = \r
- array(\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpushEvent[PARSER_EVENT_DEFINE_PARAMS] = \r
- array(\r
- "(" => PARSER_EVENT_DEFINE_PARAMS_PARENTHESIS,\r
- '"' => PARSER_EVENT_QUOTE,\r
- "'" => PARSER_EVENT_QUOTE,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_DEFINE_PARAMS] = array(")");\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_DEFINE_PARAMS_PARENTHESIS] =\r
- array(\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpushEvent[PARSER_EVENT_DEFINE_PARAMS_PARENTHESIS] =\r
- array(\r
- "(" => PARSER_EVENT_DEFINE_PARAMS_PARENTHESIS,\r
- '"' => PARSER_EVENT_QUOTE,\r
- "'" => PARSER_EVENT_QUOTE,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_DEFINE_PARAMS_PARENTHESIS] = array(")");\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_VAR] = \r
- array(\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- T_ARRAY => PARSER_EVENT_ARRAY,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_VAR] = array(";");\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_CLASS] = \r
- array(\r
- T_FUNCTION => PARSER_EVENT_METHOD,\r
- T_VAR => PARSER_EVENT_VAR,\r
- T_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- T_CLOSE_TAG => PARSER_EVENT_OUTPHP,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_CLASS] = array("}");\r
- /**************************************************************/\r
-\r
- $this->wordpushEvent[PARSER_EVENT_METHOD] =\r
- array(\r
- '{' => PARSER_EVENT_METHOD_LOGICBLOCK,\r
- '(' => PARSER_EVENT_FUNCTION_PARAMS,\r
- );\r
- $this->tokenpushEvent[PARSER_EVENT_METHOD] =\r
- array(\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_METHOD] = array("}", ";");\r
- /**************************************************************/\r
-\r
- $this->wordpushEvent[PARSER_EVENT_METHOD_LOGICBLOCK] = \r
- array(\r
- "{" => PARSER_EVENT_METHOD_LOGICBLOCK,\r
- '"' => PARSER_EVENT_QUOTE,\r
- );\r
- $this->tokenpushEvent[PARSER_EVENT_METHOD_LOGICBLOCK] =\r
- array(\r
- T_OBJECT_OPERATOR => PARSER_EVENT_CLASS_MEMBER,\r
- T_GLOBAL => PARSER_EVENT_FUNC_GLOBAL,\r
- T_STATIC => PARSER_EVENT_STATIC_VAR,\r
- T_CURLY_OPEN => PARSER_EVENT_LOGICBLOCK,\r
- T_DOLLAR_OPEN_CURLY_BRACES => PARSER_EVENT_LOGICBLOCK,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_METHOD_LOGICBLOCK] = array("}");\r
- $this->tokenpopEvent[PARSER_EVENT_METHOD_LOGICBLOCK] = array(T_CURLY_OPEN);\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_INCLUDE] = \r
- array(\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpushEvent[PARSER_EVENT_INCLUDE] = \r
- array(\r
- "(" => PARSER_EVENT_INCLUDE_PARAMS,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_INCLUDE] = array(";");\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_INCLUDE_PARAMS] = \r
- array(\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpushEvent[PARSER_EVENT_INCLUDE_PARAMS] = \r
- array(\r
- "(" => PARSER_EVENT_INCLUDE_PARAMS_PARENTHESIS,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_INCLUDE_PARAMS] = array(")");\r
- /**************************************************************/\r
-\r
- $this->tokenpushEvent[PARSER_EVENT_INCLUDE_PARAMS_PARENTHESIS] =\r
- array(\r
- T_COMMENT => PARSER_EVENT_COMMENT,\r
- T_DOC_COMMENT => PARSER_EVENT_DOCBLOCK,\r
- );\r
- $this->wordpushEvent[PARSER_EVENT_INCLUDE_PARAMS_PARENTHESIS] =\r
- array(\r
- "(" => PARSER_EVENT_INCLUDE_PARAMS_PARENTHESIS,\r
- );\r
- $this->wordpopEvent[PARSER_EVENT_INCLUDE_PARAMS_PARENTHESIS] = array(")");\r
- }\r
-}\r
-?>\r