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

PHP安装和使用PHPDocumentor生成API文档

时间:2023-03-29 15:39:24 PHP

使用composer安装。因为不支持composer的框架,所以暂时放弃这个方法。使用梨安装。在安装pear的时候,phpgo-pear.phar总是无限循环,在安装步骤中,即使设置了php-cli路径,也是失败。从官方网站下载phpDocumentor.phar。https://www.phpdoc.org/把下载好的文件放在php.exe所在目录下,然后就可以通过命令去生成文件了`phpphpDocumentor.phar-d"生成的路径document"-t"生成文件的存放路径"phpphpDocumentor.phar-dPro/-tdocs/api-d后跟文件夹路径,如果是单个文件,可以用-f。-t表示targettarget,后面是生成API文档的文件夹。如果需要指定模板,可以在代码后加上--template。phpphpDocumentor.phar-dPro/-tdocs/api--template="clean"可以查看支持的内置模板phpphpDocumentor.phartemplate:list通过template:list可以直接连接自定义模板phpphpDocumentor之后模板。phar-dPro/-tdocs/api--template="data/template/my_template"使用phpphpDocumentor.phar-f"D:\Visual-NMP-x64\www\xinhu0905\webmain\task\api\test.php"-t"D:\document"会报错。因为cli方式使用的是PHP7.2。于是,改了phar包。$phar=newPhar('PharFile.phar');$phar->extractTo('PharFile');可以运行,但是修改后会压缩报错,无法解决,所以放弃:$phar=newPhar('test.phar');//$phar->extractTo('fmt');//指定压缩目录,第二个参数为指定压缩文件类型Regular$phar->buildFromDirectory(__DIR__.'/phars/','/.php$/');//压缩方式Phar::GZPHAR::BZ2$phar->compressFiles(Phar::GZ);//设置默认启动文件,即入口文件$phar->setStub($phar->createDefaultStub('index.php'));打包前将php.ini中的配置项phar.readonly设置为Off注意事项打包成phar后,如果脚本中使用常量dir,必须替换phar://,否则有些函数如file_get_contentmkdir会报错并且找不到路径,但是require_onceinclude等可以使用define('ROOT_PATH',str_replace('phar://','',dirname(__dir__)));或者使用以下获取当前目录define('ROOT_PATH',realpath('.'));最后只能妥协,使用5.6版本的PHP运行文件:D:/Visual-NMP-x64/Bin/PHP/php-5.6.36-nts-x64/php.exephpDocumentor.phar-f"D:\Visual-NMP-x64\www\xinhu0905\webmain\task\api\test.php"-t"D:\document"生成页面:参考文档:phpDocumentorPHPDocumentor的代码注释规范解释PHP代码打包---pharphppacksphar文件phpDocumentor使用教程【安装PHPDocumentor】后续尝试使用apidoc也是一个更好的选择。