Codeigniter項目使用phpDocumentor生成api文檔

前言

運行環境:

  1. vagrant 2.2.4

  2. virtualbox 6.0
  3. box bento/ubuntu-16.04 (Apache 2.4.18 + Mysql 5.7.26 + PHP 5.6.40)
  4. phpDocumentor

phpDocumentor 2 是一個儘可能的通過你的PHP源碼來生成文檔的工具。

通過 Codeigniter項目applicaiton下控制器和模型 2個文件夾的源碼來生成 api文檔

vagrant@vagrant:~$ phpdoc -V
phpDocumentor version v2.9.0

我是通過 phar 方式進行安裝

wget https://www.phpdoc.org/phpDocumentor.phar # 下載phpDocumentor.phar文件
# php phpDocumentor.phar -V
sudo mv phpDocumentor.phar /usr/local/bin/phpdoc #將文件移入到/usr/local/bin下,並重命名爲phpdoc,在所有目錄下,都可以運行 phpdoc命令了,即全局命令
phpdoc -h # 輸出幫助信息
phpdoc -V # 輸出版本信息
phpdoc template:list # 列出使用的模板

使用

簡單的使用 phpDocumentor 是使用命令行參數(-d 一個目錄,-f 一個文件)來提供一個輸入點和告訴它你喜歡放的文件夾(-t)來輸出你的文檔。

例如:

$ phpdoc -d ./src -t ./docs/api

上面的案列會掃描 在src 和它子文件夾下的所有文件,執行分析和生成一個包含文檔的網站在docs/api下。如果你沒有指定-t選項,文檔的輸出將會寫入到一個子文件夾爲output文件夾中。

命令:

codeignniter$: phpdoc -d "application/controllers,application/models" -t ./docs/api

docs/api可以看到生成的文檔

通過配置文件進行配置

phpdoc.dist.xml 配置文件內容

<?xml version="1.0" encoding="UTF-8" ?>
<phpdoc>
    <title>Codeigniter</title>
    <parser>
        <target>docs/api</target>
    </parser>
    <files>
        <directory>application/controllers</directory>
        <directory>application/models</directory>
    </files>
    <transformations>
        <template name="responsive-twig" />
        <target>docs/api</target>
    </transformations>
</phpdoc>

命令:

codeigniter$: phpdoc -c phpdoc.dist.xml
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章