$source = new DocTestSource(""); * * getDocComments 메소드는 해당 코드에 포함된 주석을 추출하여 DocTestComment 객체로 돌려줍니다. * php> $comments = $source->getDocComments(); * php> $comments[0]->text * "\nsome comment " * php> $comments[0]->lineNumber * 2 */ class DocTestSource { function DocTestSource($source) { $this->source = $source; } function getDocComments() { $comments = array(); $lineno = 1; foreach (token_get_all($this->source) as $token) if (!is_string($token)) { if ($token[0] == T_DOC_COMMENT && substr($token[1], 0, 2) == '/*') { $comments[] = new DocTestComment(substr($token[1], 2, -2), $lineno); } $lineno += substr_count($token[1], "\n"); } return $comments; } }