v2.2.0: help in parsing query parameters and request documents
This release makes it easier to process query parameters and request documents. There's a new RequestParser
class which can be constructed from PSR-7 request objects or $_GET
/$_POST
/$_SERVER
superglobals. See below or check the example code with all options.
Query parameters
On a a request for GET /users?fields[user]=name,location&sort=-name
you can:
$requestParser->hasSparseFieldset('user'); // true
$requestParser->getSparseFieldset('user'); // ['name', 'location']
$requestParser->hasSortFields(); // true
$requestParser->getSortFields(); // [['field' => 'name', 'order' => RequestParser::SORT_DESCENDING]]
Request documents
On a request for POST /users
with this POST data:
{
"data": {
"type": "user",
"attributes": {
"name": "Zaphod"
}
}
}
You can check for contents inside a request document, without a lot of isset
/array_has_key
on nested arrays:
$requestParser->hasAttribute('name'); // true
$requestParser->getAttribute('name'); // 'Zaphod'