[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zf2 for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license http://framework.zend.com/license/new-bsd New BSD License 8 */ 9 10 namespace Zend\Code\Scanner; 11 12 use Zend\Code\Annotation\AnnotationManager; 13 use Zend\Code\NameInformation; 14 15 class DocBlockScanner implements ScannerInterface 16 { 17 /** 18 * @var bool 19 */ 20 protected $isScanned = false; 21 22 /** 23 * @var string 24 */ 25 protected $docComment = null; 26 27 /** 28 * @var NameInformation 29 */ 30 protected $nameInformation = null; 31 32 /** 33 * @var AnnotationManager 34 */ 35 protected $annotationManager = null; 36 37 /** 38 * @var string 39 */ 40 protected $shortDescription = null; 41 42 /** 43 * @var string 44 */ 45 protected $longDescription = ''; 46 47 /** 48 * @var array 49 */ 50 protected $tags = array(); 51 52 /** 53 * @var array 54 */ 55 protected $annotations = array(); 56 57 /** 58 * @param string $docComment 59 * @param null|NameInformation $nameInformation 60 */ 61 public function __construct($docComment, NameInformation $nameInformation = null) 62 { 63 $this->docComment = $docComment; 64 $this->nameInformation = $nameInformation; 65 } 66 67 /** 68 * @return string 69 */ 70 public function getShortDescription() 71 { 72 $this->scan(); 73 74 return $this->shortDescription; 75 } 76 77 /** 78 * @return string 79 */ 80 public function getLongDescription() 81 { 82 $this->scan(); 83 84 return $this->longDescription; 85 } 86 87 /** 88 * @return array 89 */ 90 public function getTags() 91 { 92 $this->scan(); 93 94 return $this->tags; 95 } 96 97 /** 98 * @return array 99 */ 100 public function getAnnotations() 101 { 102 $this->scan(); 103 104 return $this->annotations; 105 } 106 107 /** 108 * @return void 109 */ 110 protected function scan() 111 { 112 if ($this->isScanned) { 113 return; 114 } 115 116 $mode = 1; 117 118 $tokens = $this->tokenize(); 119 $tagIndex = null; 120 reset($tokens); 121 122 SCANNER_TOP: 123 $token = current($tokens); 124 125 switch ($token[0]) { 126 case 'DOCBLOCK_NEWLINE': 127 if ($this->shortDescription != '' && $tagIndex === null) { 128 $mode = 2; 129 } else { 130 $this->longDescription .= $token[1]; 131 } 132 goto SCANNER_CONTINUE; 133 //goto no break needed 134 135 case 'DOCBLOCK_WHITESPACE': 136 case 'DOCBLOCK_TEXT': 137 if ($tagIndex !== null) { 138 $this->tags[$tagIndex]['value'] .= ($this->tags[$tagIndex]['value'] == '') ? $token[1] : ' ' . $token[1]; 139 goto SCANNER_CONTINUE; 140 } elseif ($mode <= 2) { 141 if ($mode == 1) { 142 $this->shortDescription .= $token[1]; 143 } else { 144 $this->longDescription .= $token[1]; 145 } 146 goto SCANNER_CONTINUE; 147 } 148 //gotos no break needed 149 case 'DOCBLOCK_TAG': 150 array_push($this->tags, array('name' => $token[1], 151 'value' => '')); 152 end($this->tags); 153 $tagIndex = key($this->tags); 154 $mode = 3; 155 goto SCANNER_CONTINUE; 156 //goto no break needed 157 158 case 'DOCBLOCK_COMMENTEND': 159 goto SCANNER_END; 160 161 } 162 163 SCANNER_CONTINUE: 164 if (next($tokens) === false) { 165 goto SCANNER_END; 166 } 167 goto SCANNER_TOP; 168 169 SCANNER_END: 170 171 $this->shortDescription = trim($this->shortDescription); 172 $this->longDescription = trim($this->longDescription); 173 $this->isScanned = true; 174 } 175 176 /** 177 * @return array 178 */ 179 protected function tokenize() 180 { 181 static $CONTEXT_INSIDE_DOCBLOCK = 0x01; 182 static $CONTEXT_INSIDE_ASTERISK = 0x02; 183 184 $context = 0x00; 185 $stream = $this->docComment; 186 $streamIndex = null; 187 $tokens = array(); 188 $tokenIndex = null; 189 $currentChar = null; 190 $currentWord = null; 191 $currentLine = null; 192 193 $MACRO_STREAM_ADVANCE_CHAR = function ($positionsForward = 1) use (&$stream, &$streamIndex, &$currentChar, &$currentWord, &$currentLine) { 194 $positionsForward = ($positionsForward > 0) ? $positionsForward : 1; 195 $streamIndex = ($streamIndex === null) ? 0 : $streamIndex + $positionsForward; 196 if (!isset($stream[$streamIndex])) { 197 $currentChar = false; 198 199 return false; 200 } 201 $currentChar = $stream[$streamIndex]; 202 $matches = array(); 203 $currentLine = (preg_match('#(.*?)\r?\n#', $stream, $matches, null, $streamIndex) === 1) ? $matches[1] : substr($stream, $streamIndex); 204 if ($currentChar === ' ') { 205 $currentWord = (preg_match('#( +)#', $currentLine, $matches) === 1) ? $matches[1] : $currentLine; 206 } else { 207 $currentWord = (($matches = strpos($currentLine, ' ')) !== false) ? substr($currentLine, 0, $matches) : $currentLine; 208 } 209 210 return $currentChar; 211 }; 212 $MACRO_STREAM_ADVANCE_WORD = function () use (&$currentWord, &$MACRO_STREAM_ADVANCE_CHAR) { 213 return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentWord)); 214 }; 215 $MACRO_STREAM_ADVANCE_LINE = function () use (&$currentLine, &$MACRO_STREAM_ADVANCE_CHAR) { 216 return $MACRO_STREAM_ADVANCE_CHAR(strlen($currentLine)); 217 }; 218 $MACRO_TOKEN_ADVANCE = function () use (&$tokenIndex, &$tokens) { 219 $tokenIndex = ($tokenIndex === null) ? 0 : $tokenIndex + 1; 220 $tokens[$tokenIndex] = array('DOCBLOCK_UNKNOWN', ''); 221 }; 222 $MACRO_TOKEN_SET_TYPE = function ($type) use (&$tokenIndex, &$tokens) { 223 $tokens[$tokenIndex][0] = $type; 224 }; 225 $MACRO_TOKEN_APPEND_CHAR = function () use (&$currentChar, &$tokens, &$tokenIndex) { 226 $tokens[$tokenIndex][1] .= $currentChar; 227 }; 228 $MACRO_TOKEN_APPEND_WORD = function () use (&$currentWord, &$tokens, &$tokenIndex) { 229 $tokens[$tokenIndex][1] .= $currentWord; 230 }; 231 $MACRO_TOKEN_APPEND_WORD_PARTIAL = function ($length) use (&$currentWord, &$tokens, &$tokenIndex) { 232 $tokens[$tokenIndex][1] .= substr($currentWord, 0, $length); 233 }; 234 $MACRO_TOKEN_APPEND_LINE = function () use (&$currentLine, &$tokens, &$tokenIndex) { 235 $tokens[$tokenIndex][1] .= $currentLine; 236 }; 237 238 $MACRO_STREAM_ADVANCE_CHAR(); 239 $MACRO_TOKEN_ADVANCE(); 240 241 TOKENIZER_TOP: 242 243 if ($context === 0x00 && $currentChar === '/' && $currentWord === '/**') { 244 $MACRO_TOKEN_SET_TYPE('DOCBLOCK_COMMENTSTART'); 245 $MACRO_TOKEN_APPEND_WORD(); 246 $MACRO_TOKEN_ADVANCE(); 247 $context |= $CONTEXT_INSIDE_DOCBLOCK; 248 $context |= $CONTEXT_INSIDE_ASTERISK; 249 if ($MACRO_STREAM_ADVANCE_WORD() === false) { 250 goto TOKENIZER_END; 251 } 252 goto TOKENIZER_TOP; 253 } 254 255 if ($context & $CONTEXT_INSIDE_DOCBLOCK && $currentWord === '*/') { 256 $MACRO_TOKEN_SET_TYPE('DOCBLOCK_COMMENTEND'); 257 $MACRO_TOKEN_APPEND_WORD(); 258 $MACRO_TOKEN_ADVANCE(); 259 $context &= ~$CONTEXT_INSIDE_DOCBLOCK; 260 if ($MACRO_STREAM_ADVANCE_WORD() === false) { 261 goto TOKENIZER_END; 262 } 263 goto TOKENIZER_TOP; 264 } 265 266 if ($currentChar === ' ' || $currentChar === "\t") { 267 $MACRO_TOKEN_SET_TYPE(($context & $CONTEXT_INSIDE_ASTERISK) ? 'DOCBLOCK_WHITESPACE' : 'DOCBLOCK_WHITESPACE_INDENT'); 268 $MACRO_TOKEN_APPEND_WORD(); 269 $MACRO_TOKEN_ADVANCE(); 270 if ($MACRO_STREAM_ADVANCE_WORD() === false) { 271 goto TOKENIZER_END; 272 } 273 goto TOKENIZER_TOP; 274 } 275 276 if ($currentChar === '*') { 277 if (($context & $CONTEXT_INSIDE_DOCBLOCK) && ($context & $CONTEXT_INSIDE_ASTERISK)) { 278 $MACRO_TOKEN_SET_TYPE('DOCBLOCK_TEXT'); 279 } else { 280 $MACRO_TOKEN_SET_TYPE('DOCBLOCK_ASTERISK'); 281 $context |= $CONTEXT_INSIDE_ASTERISK; 282 } 283 $MACRO_TOKEN_APPEND_CHAR(); 284 $MACRO_TOKEN_ADVANCE(); 285 if ($MACRO_STREAM_ADVANCE_CHAR() === false) { 286 goto TOKENIZER_END; 287 } 288 goto TOKENIZER_TOP; 289 } 290 291 if ($currentChar === '@') { 292 $MACRO_TOKEN_SET_TYPE('DOCBLOCK_TAG'); 293 $MACRO_TOKEN_APPEND_WORD(); 294 $MACRO_TOKEN_ADVANCE(); 295 if ($MACRO_STREAM_ADVANCE_WORD() === false) { 296 goto TOKENIZER_END; 297 } 298 goto TOKENIZER_TOP; 299 } 300 301 if ($currentChar === "\n") { 302 $MACRO_TOKEN_SET_TYPE('DOCBLOCK_NEWLINE'); 303 $MACRO_TOKEN_APPEND_CHAR(); 304 $MACRO_TOKEN_ADVANCE(); 305 $context &= ~$CONTEXT_INSIDE_ASTERISK; 306 if ($MACRO_STREAM_ADVANCE_CHAR() === false) { 307 goto TOKENIZER_END; 308 } 309 goto TOKENIZER_TOP; 310 } 311 312 $MACRO_TOKEN_SET_TYPE('DOCBLOCK_TEXT'); 313 $MACRO_TOKEN_APPEND_LINE(); 314 $MACRO_TOKEN_ADVANCE(); 315 if ($MACRO_STREAM_ADVANCE_LINE() === false) { 316 goto TOKENIZER_END; 317 } 318 goto TOKENIZER_TOP; 319 320 TOKENIZER_END: 321 322 array_pop($tokens); 323 324 return $tokens; 325 } 326 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |