yiisoft/yii2-apidoc 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yiisoft/yii2-apidoc

Composer 安装命令:

composer require yiisoft/yii2-apidoc

包简介

API Documentation generator for the Yii framework 2.0

README 文档

README

API documentation generator


This extension provides an API documentation generator.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status Static status Codecov

Installation

Important

  • The minimum required PHP version is PHP 8.2.

The preferred way to install this extension is through composer.

Either run

composer require --prefer-dist yiisoft/yii2-apidoc:"~4.0.0"

The above command may not work on an existing project due to version conflicts that need to be resolved, so it is preferred to add the package manually to the require section of your composer.json:

"yiisoft/yii2-apidoc": "~4.0.0"

afterwards run composer update. You may also run composer update yiisoft/yii2-apidoc cebe/markdown if you want to avoid updating unrelated packages.

Usage

This extension creates executable at /vendor/bin. Please do change directory to that directory if you do not want to use full path i.e /vendor/bin/apidoc and use just the executable name as with below examples.

This extension offers two commands:

1)api to generate class API documentation. phpDocumentor is used as a base framework so refer to its guide for the syntax.

The output of help api command (i.e apidoc help api):

DESCRIPTION

Renders API documentation files


USAGE

apidoc api <sourceDirs> <targetDir> [...options...]

- sourceDirs (required): array

- targetDir (required): string


OPTIONS

--appconfig: string
  custom application configuration file path.
  If not set, default application configuration is used.

--color: boolean, 0 or 1
  whether to enable ANSI color in the output.
  If not set, ANSI color will only be enabled for terminals that support it.

--exclude: string|array
  files to exclude.

--guide: string
  url to where the guide files are located

--guide-prefix: string (defaults to 'guide-')
  prefix to prepend to all guide file names.

--help, -h: boolean, 0 or 1 (defaults to 0)
  whether to display help information about current command.

--interactive: boolean, 0 or 1 (defaults to 1)
  whether to run the command interactively.

--page-title: string

--repo-url: string
  Repository url (e.g. "https://github.com/yiisoft/yii2"). Optional, used for resolving relative links
  within a repository (e.g. "[docs/guide/README.md](docs/guide/README.md)"). If you don't have such links you can
  skip this. Otherwise, skipping this will cause generation of broken links because they will be not resolved and
  left as is.

--readme-url: string
  URL for the README to use for the index of the guide.

--silent-exit-on-exception: boolean, 0 or 1
  if true - script finish with `ExitCode::OK` in case of exception.
  false - `ExitCode::UNSPECIFIED_ERROR`.
  Default: `YII_ENV_TEST`

--template: string (defaults to 'bootstrap')
  template to use for rendering

2)guide to render nice HTML pages from markdown files such as the yii guide.

The output of help guide command (i.e apidoc help guide):

DESCRIPTION

Renders API documentation files


USAGE

apidoc guide <sourceDirs> <targetDir> [...options...]

- sourceDirs (required): array

- targetDir (required): string


OPTIONS

--api-docs: string
  path or URL to the api docs to allow links to classes and properties/methods.

--appconfig: string
  custom application configuration file path.
  If not set, default application configuration is used.

--color: boolean, 0 or 1
  whether to enable ANSI color in the output.
  If not set, ANSI color will only be enabled for terminals that support it.

--exclude: string|array
  files to exclude.

--guide-prefix: string (defaults to 'guide-')
  prefix to prepend to all output file names generated for the guide.

--help, -h: boolean, 0 or 1 (defaults to 0)
  whether to display help information about current command.

--interactive: boolean, 0 or 1 (defaults to 1)
  whether to run the command interactively.

--page-title: string

--silent-exit-on-exception: boolean, 0 or 1
  if true - script finish with `ExitCode::OK` in case of exception.
  false - `ExitCode::UNSPECIFIED_ERROR`.
  Default: `YII_ENV_TEST`

--template: string (defaults to 'bootstrap')
  template to use for rendering

Simple usage for stand-alone class documentation:

vendor/bin/apidoc api source/directory ./output

Simple usage for stand-alone guide documentation:

vendor/bin/apidoc guide source/docs ./output

Note that in order to generate a proper index file, the README.md file containing links to guide sections must be present. An example of such file can be found in the yii2 repository.

You can combine them to generate class API and guide documentation in one place:

# generate API docs
vendor/bin/apidoc api source/directory ./output
# generate the guide (order is important to allow the guide to link to the apidoc)
vendor/bin/apidoc guide source/docs ./output

By default, the bootstrap template will be used. You can choose a different template with the --template=name parameter. Currently, there is only the bootstrap template available.

You may also add the yii\apidoc\commands\ApiController and GuideController to your console application command map and run them inside your application's console app.

Generating docs from multiple sources

The apidoc generator can use multiple directories, so you can generate docs for your application and include the yii framework docs to enable links between your classes and framework classes. This also allows @inheritdoc to work for your classes that extend from the framework. Use the following command to generate combined api docs:

./vendor/bin/apidoc api ./vendor/yiisoft/yii2,. docs/json --exclude="docs,vendor"

This will read the source files from ./vendor/yiisoft/yii2 directory and . which is the current directory (you may replace this with the location of your code if it is not in the current working directory).

Advanced usage

The following script can be used to generate API documentation and guide in different directories and also multiple guides in different languages (like it is done on yiiframework.com):

#!/bin/sh

# set these paths to match your environment
YII_PATH=~/dev/yiisoft/yii2
APIDOC_PATH=~/dev/yiisoft/yii2/extensions/apidoc
OUTPUT=yii2docs

cd $APIDOC_PATH
./apidoc api $YII_PATH/framework/,$YII_PATH/extensions $OUTPUT/api --guide=../guide-en --guide-prefix= --interactive=0
./apidoc guide $YII_PATH/docs/guide $OUTPUT/guide-en --apiDocs=../api --guide-prefix= --interactive=0
./apidoc guide $YII_PATH/docs/guide-ru $OUTPUT/guide-ru --apiDocs=../api --guide-prefix= --interactive=0
# repeat the last line for more languages

Creating a PDF of the guide

Prerequisites:

Generation:

vendor/bin/apidoc guide source/docs ./output --template=pdf
cd ./output
make pdf

If all runs without errors the PDF will be guide.pdf in the output dir.

Special Markdown Syntax

We have a special Syntax for linking to a class in the API documentation. See the code style guide for details.

Generating documentation for your own project

To generate API documentation for your own project, use the "project" template and specify the README.md of your repository using the "readmeUrl" parameter:

apidoc api YOUR_REPO_PATH OUTPUT_PATH --exclude="vendor" --template="project" --readme-url="file://YOUR_REPO_PATH/README.md" --page-title="TITLE_OF_YOUR_DOCS"

To also include links to the Yii2 documentation, you can do:

apidoc api "YOUR_REPO_PATH,vendor/yiisoft/yii2" OUTPUT_PATH --exclude="vendor" --template="project" --readme-url="file://YOUR_REPO_PATH/README.md" --page-title="TITLE_OF_YOUR_DOCS"

Creating your own templates

TBD

Using the model layer

TBD

yiisoft/yii2-apidoc 适用场景与选型建议

yiisoft/yii2-apidoc 是一款 基于 HTML 开发的 Composer 扩展包,目前已累计 711.33k 次下载、GitHub Stars 达 259, 最近一次更新时间为 2014 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「documentation」 「phpdoc」 「api」 「yii2」 「apidoc」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 yiisoft/yii2-apidoc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 yiisoft/yii2-apidoc 我们能提供哪些服务?
定制开发 / 二次开发

基于 yiisoft/yii2-apidoc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 711.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 269
  • 点击次数: 30
  • 依赖项目数: 45
  • 推荐数: 0

GitHub 信息

  • Stars: 259
  • Watchers: 27
  • Forks: 120
  • 开发语言: HTML

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-01-06