futuretek/yii2-api 问题修复 & 功能扩展

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

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

futuretek/yii2-api

最新稳定版本:2.1.1

Composer 安装命令:

composer require futuretek/yii2-api

包简介

API used in FTS.

README 文档

README

Yii2 JSON API.

Requirements

  • Yii2
  • ext-shared-components

Installation

Use composer and add the following line to your composer.json file:

"futuretek/yii2-api": "*"

Changelog

v1.0.0

  • Initial release

Usage

Setup the API in the init method of your controller:

	public function init()
	{
		$this->setIdentity(UserModel);
		parent::init();
	}

Define the custom actions:

public function actions()
{
    return [
        ...,
        'myAction' => [
            'class' => 'futuretek\api\ApiAction',
        ],
        ...,
    ];
}

Add phpDoc tags (see below) to the properly documented actions you want:

/**
* Returns hello and the name that you gave
*
* @param string $name Your name
* @return string
* @api
*/
public function getHello($name)
{
    return ['hello' => 'Hello ' . $name];
}

Optionaly use IpFilter to limit access to API. Declare it in the behaviors() method of your controller class.

public function behaviors()
{
    return [
        'ips' => [
            'class' => \futuretek\api\IpFilter::className(),
            'policy' => IpFilter::POLICY_ALLOW_ALL,
            'list' => [
                '192.168.1.2',
                '192.168.11.1-192.168.11.27',
                '10.*.*.*',
                '172.16.1.0/24',
            ],
        ],
    ];
}

Built-in methods

ping

Ping action intended mainly to test the API interface availability

generate-definition

Generate API methods definition list

This is the default action if API method is not specified

generate-confluence-documentation

Generate API documentation in Confluence markup

Allowed phpDoc tags

@param

Usage: @param type $variable description {additional parameters}

Indicate input variable. If the input variable is an array, you can define it by using [], eg. String[]

Additional parameters

Optionally, extra attributes can be defined for each @param tag by enclosing definitions into curly brackets and separated by comma like so:

{[attribute1 = value1][, attribute2 = value2], ...}

where the attribute can be one of following:

validate - Specifies validator function to check parameter value against

Validator must be static method name from the Validate class.

  • isInt
  • isString

element - Array element definition. If @param is of type Array, you can describe array elements with this attribute

Usage: {element=name|type|description, element=name|type, ...}

@return

Usage: @return type description

Indicate method return value. If the return value is an array, you can define it by using [], eg. String[]

Remember: API function should always (and I mean ALWAYS!) return associative array. If another type is returned, it will be treated like the function has no output. Additionally if the function returns boolean false (or another data type that can be typed to false), the API call will result in general error message.

If you want to express processing fail inside the method, you should throw an exception.

@return-param

Usage: @return-param type name description

All API methods must return Array, bool or void(null). In case of Array you can specify each array element with this tag. This is mainly to describe the method. No additional logic is bind to this tag.

@api

Usage: @api

Indicates that this method should be accessible via API interface. Methods without this tag are ignored.

@no-auth

Usage: @no-auth

Indicates that this method will be publicly accessible without user identification

@permission

Usage: @permission permissionName

Require specified RBAC permission to run action. If @no-auth is used, this tag will be ignored

@transaction

Usage: @transaction

Run method in database transaction

统计信息

  • 总下载量: 196
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2022-01-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固