Codeigniter项目使用phpDocumentor生成api文档

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Codeigniter项⽬使⽤phpDocumentor⽣成api⽂档
前⾔
运⾏环境:
vagrant 2.2.4
virtualbox 6.0
box bento/ubuntu-16.04 (Apache 2.4.18 + Mysql 5.7.26 + PHP 5.6.40)
phpDocumentor 2 是⼀个尽可能的通过你的PHP源码来⽣成⽂档的⼯具。

通过 Codeigniter项⽬applicaiton下控制器和模型 2个⽂件夹的源码来⽣成 api⽂档
vagrant@vagrant:~$ phpdoc -V
phpDocumentor version v2.9.0
我是通过⽅式进⾏安装
wget https:///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
我安裝apigen網站的教程,通過 composer的⽅式安裝 apigen 庫,然後⽣成基於Codeigniter 3.1.10項⽬的Api ⽂檔
composer require apigen/apigen --dev
composer.json 中require-dev顯⽰的 "apigen/apigen": "^4.1"
單個源⽂件夾src,輸出⽬錄docs
vendor/bin/apigen generate -s application/controllers --destination docs2
將應⽤的
vendor/bin/apigen generate -s application/controllers,application/models,application/core,application/helpers --destination apigendoc
apigen generate help
vagrant@vagrant:/var/www/html/codeigniter310$ vendor/bin/apigen generate --help
Usage:
generate [options]
Options:
-s, --source=SOURCE Dirs or files documentation is generated for. (multiple values allowed)
-d, --destination=DESTINATION Target dir for documentation.
--access-levels=ACCESS-LEVELS Access levels of included method and properties. [default: ["public","protected"]] (multiple values allowed)
--annotation-groups=ANNOTATION-GROUPS Generate page with elements with specific annotation.
--base-url=BASE-URL Base url used for sitemap (useful for public doc).
--config=CONFIG Custom path to apigen.neon config file. [default: "/var/www/html/mainpowers3/apigen.neon"]
--google-cse-id=GOOGLE-CSE-ID Custom google search engine id (for search box).
--google-analytics=GOOGLE-ANALYTICS Google Analytics tracking code.
--debug Turn on debug mode.
--deprecated Generate documentation for elements marked as @deprecated
--download Add link to ZIP archive of documentation.
--extensions=EXTENSIONS Scanned file extensions. [default: ["php"]] (multiple values allowed)
--exclude=EXCLUDE Directories and files matching this mask will not be parsed (e.g. */tests/*). (multiple values allowed)
--groups=GROUPS The way elements are grouped in menu. [default: "auto"]
--charset=CHARSET Charset of scanned files. (multiple values allowed)
--main=MAIN Elements with this name prefix will be first in tree.
--internal Include elements marked as @internal.
--php Generate documentation for PHP internal classes.
--skip-doc-path=SKIP-DOC-PATH Files matching this mask will be included in class tree, but will not create a link to their documentation. (multiple values allowed) --no-source-code Do not generate highlighted source code for elements.
--template-theme=TEMPLATE-THEME ApiGen template theme name. [default: "default"]
--template-config=TEMPLATE-CONFIG Your own template config, has higher priority templateTheme.
--title=TITLE Title of generated documentation.
--todo Generate documentation for elements marked as @todo.
--tree Generate tree view of classes, interfaces, traits and exceptions.
-h, --help Display this help message.
-q, --quiet Do not output any message.
-V, --version Display this application version. Help:
Generate API documentation
References。

相关文档
最新文档