>개발 도구 >composer >Composer가 인터페이스 문서를 자동으로 생성하는 방법에 대하여

Composer가 인터페이스 문서를 자동으로 생성하는 방법에 대하여

藏色散人
藏色散人앞으로
2020-07-03 11:50:273022검색

下面由composer教程栏目给大家介绍关于composer自动生成接口文档,希望对需要的朋友有所帮助!

Composer가 인터페이스 문서를 자동으로 생성하는 방법에 대하여

安装composer

1.先下载Composer-Setup.exe,下载地址:下载Composer 。会自动搜索PHP.exe的安装路径,如果没有,就手动找到php路径下的php.exe。

2.在PHP目录下,打开php.ini文件,开启openssl扩展。去掉extension=php_openssl.dll前面的分号(;)

3.把php目录添加到环境变量(和php.exe同级目录的路径)例如:D:\apache_php\php添加到环境变量path里。

4.下载composer.phar,下载地址:Composer.phar  将composer.phar文件放入php目录下,在php目录下新建一个文件composer.cmd,内容写成:
@php "%~dp0composer.phar" %*保存。运行这个文件,然后打开cmd运行:composer会出现
可以运行composer --version 查看composer的版本。

5.在命令行中执行:composer config -g repo.packagist composer https://packagist.phpcomposer.com

改写Packagist 镜像至国内镜像可以加快下载速度。

最后提一下,看云上有composer的中文手册http://www.kancloud.cn/thinkphp/composer

通过composer安装软件,实现自动生成接口文档(https://packagist.org/packages/weiwei/api-doc)

cmd 进入项目目录,输入composer require weiwei/api-doc。

(TP5)/application/extra/view/doc.php:

<?php
return [
    &#39;title&#39; => "海泉智腾APi接口文档(ios)",  //文档title
    &#39;version&#39;=>&#39;1.0.0&#39;, //文档版本
    &#39;copyright&#39;=>&#39;Powered By kraus&#39;, //版权信息
    &#39;controller&#39; => [
        //需要生成文档的类
      &#39;app\\ios\\controller\\Index&#39;,
      &#39;app\\ios\\controller\\Member&#39;,
      &#39;app\\ios\\controller\\Sms&#39;,
      &#39;app\\ios\\controller\\Address&#39;,
      &#39;app\\ios\\controller\\Goods&#39;,
      &#39;app\\ios\\controller\\Cart&#39;,
      &#39;app\\ios\\controller\\Order&#39;,
      &#39;app\\ios\\controller\\Comment&#39;,
      &#39;app\\admin\\controller\\GoodsNum&#39;,
    ],
    &#39;filter_method&#39; => [
        //过滤 不解析的方法名称
        &#39;_empty&#39;
    ],
    &#39;return_format&#39; => [
        //数据格式
        &#39;code&#39; => "200/205/301/307",
        &#39;msg&#39; => "状态码说明",
    ],
    &#39;public_header&#39; => [
        //全局公共头部参数
        //[&#39;name&#39;=>&#39;&#39;, &#39;require&#39;=>1, &#39;default&#39;=>&#39;&#39;, &#39;desc&#39;=>&#39;&#39;],
        //[&#39;name&#39;=>&#39;&#39;, &#39;require&#39;=>1, &#39;default&#39;=>&#39;&#39;, &#39;desc&#39;=>&#39;&#39;],
    ],
    &#39;public_param&#39; => [
        //全局公共请求参数,设置了所有的接口会自动增加次参数
        //[&#39;name&#39;=>&#39;token&#39;,&#39;type&#39;=>&#39;字符串&#39;, &#39;require&#39;=>1, &#39;default&#39;=>&#39;&#39;,&#39;other&#39;=>&#39;用户唯一身份标识码&#39;, &#39;desc&#39;=>&#39;token&#39;],
        [&#39;name&#39;=>&#39;sign&#39;,&#39;type&#39;=>&#39;字符串&#39;, &#39;require&#39;=>1, &#39;default&#39;=>&#39;&#39;,&#39;other&#39;=>&#39;接口参数加密&#39;, &#39;desc&#39;=>&#39;签名&#39;],
    ],
];

route.php:

<?php
use think/Route;
Route::pattern(&#39;id&#39;,&#39;\d+&#39;);
Route::pattern(&#39;name&#39;,&#39;\w+&#39;);
Route::rule(&#39;createSign&#39;,&#39;ios/member/createSign&#39;);//生成token接口
Route::rule(&#39;iToken&#39;,&#39;ios/member/createToken&#39;);//生成token接口
Route::rule(&#39;iSendSms&#39;,&#39;ios/sms/send&#39;);//短信验证码发送
Route::rule(&#39;imemsg&#39;,&#39;ios/member/memsg&#39;);//获取用户信息

address.php:

<?php
...
    /**
     * @title 首页分类商品
     * @description 首页分类商品
     * @author tiny
     * @url /itypeGoods
     * @method POST
     *
     * @param name:tid type:int require:1 default: other: desc:商品类型id
     *
     * @return type:类型@
     * @type id:类型id  cat_name:类型名
     *
     * @return recommend:推荐@
     * @recommend id:商品id image:商品图片 goods_name:商品名 goods_price:价格
     *
     * @return new:新品上市@
     * @new id:商品id image:商品图片 goods_name:商品名 goods_price:价格
     *
     * @return image:图片@
     * @image
     */

URL输入:ip/doc

위 내용은 Composer가 인터페이스 문서를 자동으로 생성하는 방법에 대하여의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 csdn.net에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제