php-platform / search-query-parser
a library to parse search query parameters from a rest request
Requires
- php: >=5.4
- php-platform/errors: ~0.1
- php-platform/persist: ~0.1
- php-platform/restful: ~0.1
Requires (Dev)
- php-platform/mock-config: ~0.1
- phpunit/phpunit: ~4.8
This package is not auto-updated.
Last update: 2025-01-02 17:09:20 UTC
README
When a Model from php-platform/persist is exposed as REST Resource (php-platform/restful), It is required that the REST End point to list all resources must support filter , sort and pagination
Models extending php-platform/persist supports filter , sort and pagination through arguments to PhpPlatform\Persist\Model::find($filters,$sort,$pagination,$where) method
So this library parses query parameters from rest endpoint to method arguments required by PhpPlatform\Persist\Model::find($filters,$sort,$pagination,$where)
How to use
$searchParams = PhpPlatform\SearchQueryParser\Parser::parse(PhpPlatform\RESTFul\HTTPRequest $request,string $modelClassName, array $excludeFromFullTextSearch);
where
- $request is the HTTPRequest object received in the rest service
- $modelClassName is the full name of the Model which is served as REST Resource
- $excludeFromFullTextSearch is the array of fields which needs to be excluded from performing full text search
returns
An instance of PhpPlatform\SearchQueryParser\FindParams
Parse rules
Note 1 : This API throws
PhpPlatform\Errors\Exceptions\Http\_4XX\BadRequest
Exception if the query parameters are invalid Note 2 : All of the above query parameters are optional