# PHP basic function
**Repository Path**: kusting/php-basic-function
## Basic Information
- **Project Name**: PHP basic function
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Artistic-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-11-01
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
#php basic function
packing funciton is used itself
install php-swagger
1 git clone https://github.com/swagger-api/swagger-ui.git
2 composer require zircote/swagger-php
3 dist/index.html
add
4
/**
* @OA\Info(
* version="1.0.0",
* title="接口demo",
* description="Version: 1.0.0",
* @OA\Contact(name = "panpan", email = "734245514@qq.com")
* ),
* @OA\Get(path="/api/article",
* tags={"文章管理"},
* summary="文章列表",
* @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string", default="123456")),
* @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="int", default="1")),
* @OA\Parameter(name="limit", in="query", description="行数", @OA\Schema(type="int", default="10")),
* @OA\Response(response="200", description="The User")
* )
*/
/**
* @OA\Post(path="/api/article",
* tags={"文章管理"},
* summary="新增文章",
* @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* @OA\Property(description="文章名称", property="title", type="string", default="dd"),
* @OA\Property(description="文章内容", property="content", type="string"),
* required={"title", "content"})
* )
* ),
* @OA\Response(response="200", description="successful operation")
* )
*/
5 add controller function
public function api(){
$path ='../app/controller'; //你想要哪个文件夹下面的注释生成对应的API文档
$swagger = \OpenApi\scan($path);
header('Content-Type: application/x-yaml');
$swagger_json_path ='./swagger.json';
$res = file_put_contents($swagger_json_path,$swagger->toYaml());
//跳转链接
if ($res == true) {
return redirect('http://localhost/dist/index.html');
}
}
6 change dist/index.html URL
const ui = SwaggerUIBundle({
//change URL
url: "http://localhost/tp/public/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
})