Download the PHP package mrcnpdlk/url-search-parser without Composer
On this page you can find all versions of the php package mrcnpdlk/url-search-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package url-search-parser
mrcnpdlk/url-search-parser
Contents
This boundle has been created for parsing advanced queries to easy-to-use objects.
Based on https://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#advanced-queries
- Installation
- Supported parameters
- Sort
- Filter
- Limit
- Page
- Phrase
- Others
- Usage
Installation
Install the latest version with composer
Supported parameters
Sort
Generic parameter sort
can be used to describe sorting rules. Accommodate complex sorting requirements by letting the sort parameter take in list of comma separated fields, each with a possible unary negative to imply descending sort order. Let's look at some examples:
GET /messages?sort=-createDate
- Retrieves a list of messages in descending order of createDate;GET /messages?sort=-type,createDate
- Retrieves a list of messages in descending order of type. Within a specific type, older messages are ordered first;
Filter
Filtering is more complex then sorting. Array notation is used. Let's look at some examples:
GET /messages?filter[created][lt]=2018-06-01
- Retrieves a list of messages where createDate is lower than 2018-06-01;GET /messages?filter[type][in]=urgent,warning,error
- Retrieves a list of messages where type is urgent, warning or error;GET /messages?filter[type][null]
- Retrieves a list of messages where type is NULL;
Allowed operators: eq
,lt
,lte
,gt
,gte
,like
,llike
,rlike
,in
,notin
,null
,notnull
,regexp
In case using not allowed operator mrcnpdlk\Lib\UrlQueryParser\Exception\InvalidParamException
is thrown.
Limit
Example:
GET /messages?limit=20
- limitation;
Page
Example:
GET /messages?page=1
- pagination. Should be used withlimit
parameter;
Phrase
Example:
GET /messages?phrase=foo
- for easier filtering;
Other params
Use getQueryParam()
method.
Example:
GET /messages?foo=bar&baz=5
- additional params;
Usage
Example
Result
Running the tests
Authors
- Marcin Pudełek - Initial work - mrcnpdlk
See also the list of contributors who participated in this project.
License
Copyright (c) 2018 Marcin Pudełek / mrcnpdlk
This project is licensed under the MIT License - see the LICENSE file for details
All versions of url-search-parser with dependencies
ext-json Version *