Skip to content

Commit

Permalink
Merge pull request #515 from Simperfit/issue-509-v1
Browse files Browse the repository at this point in the history
[V1] fix #509 - php's parse str does not allow dots
  • Loading branch information
dunglas committed Apr 25, 2016
2 parents 684a621 + e59af5c commit 225501b
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Hydra/Serializer/CollectionNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Dunglas\ApiBundle\JsonLd\ContextBuilder;
use Dunglas\ApiBundle\JsonLd\Serializer\ContextTrait;
use Dunglas\ApiBundle\Model\PaginatorInterface;
use Dunglas\ApiBundle\Util\RequestParser;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\SerializerAwareNormalizer;

Expand Down Expand Up @@ -147,7 +148,7 @@ private function parseRequestUri($requestUri)

$parameters = [];
if (isset($parts['query'])) {
parse_str($parts['query'], $parameters);
$parameters = RequestParser::parseRequestParams($parts['query']);

// Remove existing page parameter
if (isset($parameters[$this->pageParameterName])) {
Expand Down
2 changes: 1 addition & 1 deletion Util/RequestParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function parseAndDuplicateRequest(Request $request)
*
* @return array
*/
private static function parseRequestParams($source)
public static function parseRequestParams($source)
{
$source = urldecode($source);

Expand Down
143 changes: 143 additions & 0 deletions features/doctrine/date-filter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,146 @@ Feature: Order filter on collections
}
}
"""

@dropSchema
@createSchema
Scenario: Get collection filtered by association date
Given there is "2" dummy objects with dummyDate and relatedDummy
When I send a "GET" request to "/dummies?relatedDummy.dummyDate[after]=2015-04-28"
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json"
And the JSON should be equal to:
"""
{
"@context": "/contexts/Dummy",
"@id": "/dummies?relatedDummy.dummyDate[after]=2015-04-28",
"@type": "hydra:PagedCollection",
"hydra:totalItems": 0,
"hydra:itemsPerPage": 3,
"hydra:firstPage": "/dummies?relatedDummy.dummyDate%5Bafter%5D=2015-04-28",
"hydra:lastPage": "/dummies?relatedDummy.dummyDate%5Bafter%5D=2015-04-28",
"hydra:member": [],
"hydra:search": {
"@type": "hydra:IriTemplate",
"hydra:template": "/dummies{?id,name,alias,description,relatedDummy.name,relatedDummies[],dummy,order[id],order[name],order[relatedDummy.symfony],dummyPrice[between],dummyPrice[gt],dummyPrice[gte],dummyPrice[lt],dummyPrice[lte],dummyDate[before],dummyDate[after],relatedDummy.dummyDate[before],relatedDummy.dummyDate[after]}",
"hydra:variableRepresentation": "BasicRepresentation",
"hydra:mapping": [
{
"@type": "IriTemplateMapping",
"variable": "id",
"property": "id",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "name",
"property": "name",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "alias",
"property": "alias",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "description",
"property": "description",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "relatedDummy.name",
"property": "relatedDummy.name",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "relatedDummies[]",
"property": "relatedDummies",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "dummy",
"property": "dummy",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "order[id]",
"property": "id",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "order[name]",
"property": "name",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "order[relatedDummy.symfony]",
"property": "relatedDummy.symfony",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "dummyPrice[between]",
"property": "dummyPrice",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "dummyPrice[gt]",
"property": "dummyPrice",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "dummyPrice[gte]",
"property": "dummyPrice",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "dummyPrice[lt]",
"property": "dummyPrice",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "dummyPrice[lte]",
"property": "dummyPrice",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "dummyDate[before]",
"property": "dummyDate",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "dummyDate[after]",
"property": "dummyDate",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "relatedDummy.dummyDate[before]",
"property": "relatedDummy.dummyDate",
"required": false
},
{
"@type": "IriTemplateMapping",
"variable": "relatedDummy.dummyDate[after]",
"property": "relatedDummy.dummyDate",
"required": false
}
]
}
}
"""

0 comments on commit 225501b

Please sign in to comment.