function getClassAndMethodFromCode($code = '')
{
$list = token_get_all($code);
$count = count($list);
$data = [];
$class = '';
$method = [];
foreach($list as $k => $v){
if(is_array($v)){
$v['name'] = token_name($v[0]);
$v['content'] = $v[1];
$v['line'] = $v[2];
if(in_array($v['name'], ['T_CLASS', 'T_FUNCTION'])){
$data[] = ['name' => $v['name'], 'index' => $k];
}
}
$list[$k] = $v;
}
foreach($data as $v){
for($i = $v['index'];$i < $count;$i++){
$item = $list[$i];
if($item['name'] == 'T_STRING'){
if($v['name'] == 'T_CLASS'){
$class = $item['content'];
}
else if($v['name'] == 'T_FUNCTION'){
$method[] = $item['content'];
}
break;
}
}
}
return ['class' => $class, 'method' => $method];
}
我用这个来自动扫描源码,在用户组权限分配时自动生成权限
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。