php-platform/search-query-parser

一个用于解析REST请求中搜索查询参数的库

v0.1.1 2018-02-11 07:19 UTC

This package is not auto-updated.

Last update: 2024-09-26 15:52:40 UTC


README

Build Status

当一个来自 php-platform/persist 的模型作为REST资源 (php-platform/restful)公开时,必须支持REST端点列出所有资源的功能,包括 过滤排序分页

扩展 php-platform/persist 的模型通过 PhpPlatform\Persist\Model::find($filters,$sort,$pagination,$where) 方法接受参数来实现 过滤排序分页

因此,这个库将从REST端点解析查询参数到 PhpPlatform\Persist\Model::find($filters,$sort,$pagination,$where) 方法所需的参数

如何使用

$searchParams = PhpPlatform\SearchQueryParser\Parser::parse(PhpPlatform\RESTFul\HTTPRequest $request,string $modelClassName, array $excludeFromFullTextSearch);

where

  • $request 是在REST服务中接收到的HTTPRequest对象
  • $modelClassName 是作为REST资源提供的模型的完整名称
  • $excludeFromFullTextSearch 是需要排除执行全文搜索的字段数组

返回

一个 PhpPlatform\SearchQueryParser\FindParams 实例

解析规则

注意 1:如果查询参数无效,此API将抛出 PhpPlatform\Errors\Exceptions\Http\_4XX\BadRequest 异常 注意 2:上述所有查询参数都是可选的