zobaken / apd

简单的PHP API文档生成器

0.3 2019-01-06 14:32 UTC

This package is not auto-updated.

Last update: 2024-09-23 18:48:05 UTC


README

这是什么?

这是一个简单的库,它可以帮助您直接在PHP代码注释块中创建API文档。

安装

您需要使用composer

composer require zobaken/apd ~0.3

用法

获取解析的结构

use Apd\Parser;
...
$parser = new Parser();
$parser->path('path to your php files');
$endpoints = $parser->parse();

结果中,$endpoints将包含一个\Apd\Structure\Endpoint的数组。

命令行

此解析器可以用于生成简单的Markdown或HTML输出

php vendor/bin/apd-markdown.php path-to-files > output.md
php vendor/bin/apd-html.php path-to-files > output.html

语法

可选描述可以放置在任何标签之后。

项目

@project <shortname> <version> <Title> 

部分

@section <Section-name> <Section title> 

调用入口

@call <Method> <Path> <Title> 

请求参数

@request <Type> <Name> <Title> 

如果参数是可选的,则将其类型后附加|null,例如string|null

如果类型是object,则可以包括嵌套字段的列表

@request object data Request object
int id User id
string email User email

响应字段

@response <Type> <Name> <Title> 

注册对象

您可以定义一个对象,然后稍后使用它。请参阅下面的示例。

示例

这是一个简单的示例。

/**
 * @project test 1.0 Test project
 *
 * Project description.
 *
 * @section profile Register and login section
 *
 * Section description.
 *
 * @register Profile User profile object
 * int id User id
 * string email User email
 * string|null about About user
 * string|null profile_image Profile image
 * object|null address { User address
 *   string city City
 *   string street Street
 *   string number House number
 * }
 *
 * Registered class description.
 *
 */

/**
 * @call PUT /profile/register Register a new user
 *
 * Call entry description
 *
 * @request string token Security token
 * @request object profile Profile fields
 * string email User email
 * string password User password
 * string about="To be filled" About user
 * string profile_image=http://someserver/default.png About user

 * @response Profile data User profile
 */