public static function getAnnotationParams($controller, $action)
{
$result = [];
$reflection = new \ReflectionClass($controller);
$res = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($res as $method) {
if ($method->name == $action) {
$annotation = $method->getDocComment();
if (strpos($annotation, '@doc') !== false) {
//$result[$version][$model]['all'] = $annotation;
//描述
preg_match('/@desc([^\\n]+)/', $annotation, $desc);
$result['desc'] = isset($desc[1]) ? $desc[1] : '';
//参数
preg_match_all('/@param([^\\n]+)/', $annotation, $params);
foreach ($params[1] as $key => $val) {
$tmp = explode(' ', preg_replace('/\\s(\\s+)/', ' ', trim($val)));
isset($tmp[3]) || ($tmp[3] = 'N');
substr($tmp[1], 0, 1) == '$' && ($tmp[1] = substr($tmp[1], 1));
$result['params'][] = $tmp;
}
//请求示例
preg_match('/@req(.+?)(\\*\\s*?@|\\*\\/)/s', $annotation, $reqEg);
$result['req'] = isset($reqEg[1]) ? $reqEg[1] : '';
//请求成功示例
preg_match('/@success(.+?)(\\*\\s*?@|\\*\\/)/s', $annotation, $success);
$result['success'] = isset($success[1]) ? $success[1] : '';
//请求失败示例
preg_match('/@error(.+?)(\\*\\s*?@|\\*\\/)/s', $annotation, $error);
$result['error'] = isset($error[1]) ? $error[1] : '';
}
}
}
return $result;
}