当前位置: 首页 > 后端技术 > PHP

一个解析php源码找出类名和所有方法名的函数

时间:2023-03-30 02:06:36 PHP

函数getClassAndMethodFromCode($code=''){$list=token_get_all($code);$count=count($列表);$数据=[];$类='';$方法=[];foreach($listas$k=>$v){if(is_array($v)){$v['name']=token_name($v[0]);$v['内容']=$v[1];$v['线']=$v[2];if(in_array($v['name'],['T_CLASS','T_FUNCTION'])){$data[]=['name'=>$v['name'],'index'=>$k];}}$列表[$k]=$v;}foreach($dataas$v){for($i=$v['index'];$i<$count;$i++){$item=$list[$i];if($item['name']=='T_STRING'){if($v['name']=='T_CLASS'){$class=$item['content'];}elseif($v['name']=='T_FUNCTION'){$method[]=$item['content'];}休息;}}}返回['class'=>$class,'method'=>$method];}我用这个自动扫描源码,分配用户组权限时自动生成权限