承接 tomi20v/phalswag 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tomi20v/phalswag

最新稳定版本:0.1.0

Composer 安装命令:

composer require tomi20v/phalswag

包简介

phalswag is a swagger toolkit for php using cphalcon framework

README 文档

README

phalswag is a component for the Phalcon framework, to validate incoming HTTP request against a swagger.json schema and also build the corresponding response the goal is to automate writing REST APIs as much as possible based on swagger definitions

simplest example using the supplied Phalcon Mvc Controller extension:

class UsersController extends Controller
{
	// by defining these,
	protected static $_swaggerPath = '../app/config/swagger';
	protected static $_swaggerFname = 'users.json';

	public function getAction() {

		try {

			$Response = $this->_process(
				// swagger operation ID
				'usersGet',
				// callback which receives input and shall return result data
				function($RequestModel) {
					$User = UserModel::findById($RequestModel->id);
					return $User;
				}
			);

		}
		catch (\Exception $e) {

			$Response = $this->ResponseBuilder->buildError(500);

		}

		return $Response;

	}
}

a more complete example would include:

// get the operation object
$Operation = $this->SwaggerService->getOperationById(
	$operationId,
	$this->_Swagger
);

// bind to request model
$this->SwaggerService->bindRequest(
	$RequestModel,
	$Operation,
	$this->dispatcher->getParams(),
	$this->request
);

// get response schema and build from data object
$ResponseSchema = $this->SwaggerService->getResponseSchema(
	200,
	$Operation,
	$this->_Swagger
);
$Result = $this->SwaggerService->buildBySchema(
	$Object,
	$ResponseSchema
);

current status: traversable models for most of swagger definition elements can populate a request model (class of your choice) with data from the HTTP input. can do basic validation of this data but eg cannot validate structures in body. it can build responses from models containing result data. it cannot resolve $ref 's.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: wtfpl
  • 更新时间: 2015-03-29