简体   繁体   English

通过阅读功能注释(PHP)自动创建文档

[英]Automatically create documentation by reading function comments (PHP)

Let's say I have: 假设我有:

class myclass {

    /*
     * This function, bla bla bla
     */
    function myclass()
    {
        return(true);
    }

    /*
     * This function, bla bla bla
     */
    function myfunc1()
    {
        return(true);
    }

    /*
     * This function, bla bla bla
     */
    function myfunc2()
    {
        return(true);
    }
}

By using get_class_methods(new myclass()); 通过使用get_class_methods(new myclass()); I can get the classes. 我可以上课。

Now my question is this: can I read the comments from the class function into a string? 现在我的问题是:我可以将类函数中的注释读入字符串吗? So I can create auto generated documentation. 因此,我可以创建自动生成的文档。

You can't get access to comments from PHP it the target file is included with include, include_once, require or require_once because of php-parser strips all comments out of code. 您无法从PHP访问注释,因为目标文件包含在include,include_once,require或require_once中,因为php-parser会将所有注释从代码中删除。

If you need to do it and don't want to use PHPDocumentor or Doxygen, but want to do it yourself, you need to reed the target file using file_get_contents or any other reading method and parse this code yourself using reguar expressions of other method of your choise(for example using this library - https://github.com/nikic/PHP-Parser ). 如果您需要执行此操作并且不想使用PHPDocumentor或Doxygen,但想要自己执行操作,则需要使用file_get_contents或任何其他读取方法来读取目标文件,并使用其他方法的常规表达式自己解析此代码。您的选择(例如,使用此库-https: //github.com/nikic/PHP-Parser )。 And parsing the code yourself you can get all information you need from comments. 并自己解析代码,您可以从注释中获取所需的所有信息。

But it is not so easy task so my advice is to use PHPDocumentor :P 但这不是一件容易的事,所以我的建议是使用PHPDocumentor:P

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM