From efc9ac83659630bd55517f474210aad642569734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IT=E5=B0=8F=E5=BC=BAxqitw=2Ecn?= <360237521@qq.com> Date: Tue, 5 Jun 2018 11:14:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/ParseComment.php | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/lib/ParseComment.php diff --git a/src/lib/ParseComment.php b/src/lib/ParseComment.php new file mode 100644 index 0000000..92e44c7 --- /dev/null +++ b/src/lib/ParseComment.php @@ -0,0 +1,87 @@ + $v) { + $comments[$k] = $v = trim($v); + if (strpos($v, '@') !== 0) { + continue; + } + $_parse = $this->_parseCommentLine($v); + if (!$_parse) { + continue; + } + $_type = $_parse['type']; + $_content = isset($_parse['content']) ? $_parse['content'] : ''; + if ($_type === 'param') { + if (!isset($this->commentParams[$_type])) { + $this->commentParams[$_type] = []; + } + unset($_parse['type']); + $this->commentParams[$_type][] = $_parse; + } else { + $this->commentParams[$_type] = $_content; + } + } + return $this->commentParams; + } + + /** + * 解析注释中的参数 + * @param $line - 注释行 + * @return bool|array - 解析后的数组(解析失败返回false) + */ + private function _parseCommentLine($line) { + $line = explode(' ', $line); + $line[0] = substr($line[0], 1); + $class = new ParseLine(); + $action = 'parseLine' . $class->underlineToHump($line[0]); + if (!method_exists($class, $action)) { + $action = 'parseLineTitle'; + } + return $class->$action($line); + } +} \ No newline at end of file