daniel-ac-martin/apidoc
Composer 安装命令:
composer create-project daniel-ac-martin/apidoc
包简介
A system for creating API reference documentation.
README 文档
README
A system for generating API reference documentation from a collection of XML files.
Rationale
API documentation matters. The quality of a software library's documentation has a great effect on the speed at which a prospective programmer can start using it, and that speed greatly affects whether the library will be used at all.
At present there are two main approaches to producing API documentation. The first is to simply write it manually as you would the rest of your project's documentation. The other is to insert specially formatted comments directly into your project's source and to generate documentation from this. (Examples include Doxygen, javadoc and PHPDocumentor.) In my opinion, both of these approaches are quite flawed.
In the first approach it is very easy for mistakes in the API specification to not be picked up. This is because general documentation formats are not designed to deal with programming APIs, which must be very strictly defined. Also, it is very easy for programmers to change the API in the source code whilst forgetting to update the documentation.
In the case of in-line documentation, there is the ugly situation of having two separate syntaxes mixed in a single file. The rationale is that the programmer should update the documentation at the same time he changes the source code but again, there is no guarantee of this. The benefit this offers over the first approach is that the API is at least strictly defined, though it may still become outdated.
Intermingling API documentation with source code generally causes at least one of the following problems:
- The source code becomes much harder to read as considerable screen space is given over to the documentation comments.
- The API is insufficiently documented as the programmer attempts minimise the pollution of his source code. i.e. In-line documentation is an excuse for hardly documenting at all.
Additionally, in-line documentation can encourage a lack of proper traditional commenting of source code. - Comments that are useful to the programmer working on the library itself are very different in nature from API documentation.
Instead, I propose an alternative. Rather than loosely defining APIs in the main documentation or strictly defining them in a second syntax in our source code, we can maintain a set of API documentation files adjacent to our source code files and strictly define our API in those. e.g.
project/src/some_file.php # Some source code file
project/src/some_file.xml # The strict specification of the API along with
# documentation
Alternatively, one could provide a separate directory for the purpose in the same way many people separate off their unit tests from their main source code. e.g.
project/src/some_file.php # Some source code file
project/src-doc/some_file.xml # The strict specification of the API along
# with documentation
This approach has the following advantages:
- The API documentation can use its own strictly defined syntax ensuring that the specification is valid.
- Source code syntax and documentation syntax are no longer mixed in the same files. Source code can be beautiful and concise again with comments that are actually helpful.
- Conformance with the documentation can be tested for in the unit tests. (Most general purpose programming languages have libraries for reading XML files.) This makes it far easier to ensure that the documentation is correct.
The initial implementation
This project is the initial implementation of the idea. I am using it to document a library I have written in PHP. (Though the system should work just as well for many other languages.) It works well for my purposes but I should stress that it has been hacked together using mainly XSLT and GNU Bash. i.e. It is not the most elegant implementation imaginable. I suspect it will only run on GNU/Linux systems, though it might be possible to use it on other *nix systems and Cygwin environments.
The main requirements are:
- GNU Bash
- xmllint (libxml)
- xsltproc (libxml)
It compiles the source documentation to another documentation format so that it can be incorporated into the project's main documentation. At the time of writing the only format supported is the Docbook format used by PhD (which is what is used to generate php.net).
Installation
Besides checking out the code through git. It is possible to install it through composer by running the following commands from your project's main directory:
php ./path/to/composer.phar require daniel-ac-martin/apidoc php ./path/to/composer.phar install
apidoc can then be run by typing:
vendor/bin/apidoc
Usage
The main script file, apidoc, is a bash script. Full usage information is available by executing "apidoc -h".
Generally one creates an XML file called "apidoc.xml" in the root directory of your project from which apidoc takes it's information. (Alternatively the program can be called with the information provided through the programs arguments.) Here is an example of the configuration file:
<?xml version="1.0" encoding="UTF-8"?> <apidoc-config> <source> <directory filter="*.xml">src-doc</directory> </source> <transformations> <transform template="phpnet">build/doc</transform> </transformations> </apidoc-config>
This will look for source files in the src-doc/ directory that end with ".xml". It will then collate them and then transform them using the template called "phpnet" (the only valid template at the time of writing). The transformed files (including any intermediate steps) will then be placed in the build/doc/ directory. The user can then insert the resulting API documentation into their project's main documentation.
License
Copyright (C) 2015 Daniel A.C. Martin
Distributed under the GNU General Public License v3 or any later version.
daniel-ac-martin/apidoc 适用场景与选型建议
daniel-ac-martin/apidoc 是一款 基于 XSLT 开发的 Composer 扩展包,目前已累计 70 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「documentation」 「api」 「doc」 「docs」 「apidoc」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 daniel-ac-martin/apidoc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 daniel-ac-martin/apidoc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 daniel-ac-martin/apidoc 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting
Laravel package that generates RESTful API documentation in Markdown based on PHPDoc.
A PSR-7 compatible library for making CRUD API endpoints
Laravel API documentation generating tool
RESTful API server for structured and self-documenting resources over JSON, XML, ...
统计信息
- 总下载量: 70
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GNU
- 更新时间: 2015-01-20