Add*_*ons 3 php architecture class-design object outline
我正在寻找一个可以有效勾画一个类的函数或类:
class MyClass{
/*
* Perhaps include the function comments
* in the function.
*/
function mainFunction(){
//Does Something
}
function functionWithArgs($arg1,$arg2=false){
//Does Something
//The function I want will give e the arguments w/default values
}
}
Run Code Online (Sandbox Code Playgroud)
是否有一个函数或库可以让我对这个类甚至文件的信息进行某种访问.
恩.
get_file_outline('fileWithAboveClass.php');
要么
get_class_outline('MyClass');
有没有人知道,或知道一种轻松写这个的方法?
看一下PHP Reflection API
//use the ReflectionClass to find out about MyClass
$classInfo = new ReflectionClass('MyClass');
//then you can find out pretty much anything you want to know...
$methods = $classInfo->getMethods();
var_dump($methods);
//you can even extract your comments, e.g.
$comment=$classInfo->getMethod('mainFunction')->getDocComment();
Run Code Online (Sandbox Code Playgroud)
请注意,要使注释提取起作用,它们必须格式化为PHPDoc/Doxygen注释,并以开头开头 /**