Skip to content

Commit

Permalink
Reverting collection filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Sep 11, 2015
1 parent 95afde2 commit 6c94024
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 294 deletions.
9 changes: 0 additions & 9 deletions examples/User/JsonApi/Document/UsersDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,4 @@ public function getLinks()
->setPagination("http://example.com/api/users", $this->domainObject)
;
}

/**
* @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
*/
protected function filterContent(RequestInterface $request)
{
$this->filterCollection($request);
$this->sortCollection($request, "id");
}
}
20 changes: 13 additions & 7 deletions src/JsonApi/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,39 @@ class Request implements RequestInterface
/**
* @var \Psr\Http\Message\ServerRequestInterface
*/
private $serverRequest;
protected $serverRequest;

/**
* @var array|null
*/
private $includedFields;
protected $includedFields;

/**
* @var array|null
*/
private $includedRelationships;
protected $includedRelationships;

/**
* @var array|null
*/
private $sorting;
protected $sorting;

/**
* @var array|null
*/
private $pagination;
protected $pagination;

/**
* @var array|null
*/
private $filtering;
protected $filtering;

/**
* @param \Psr\Http\Message\ServerRequestInterface $request
*/
public function __construct(ServerRequestInterface $request)
{
$this->serverRequest = $request->withParsedBody(json_decode($request->getBody(), true));
$this->serverRequest = $request;
}

/**
Expand Down Expand Up @@ -754,6 +754,12 @@ public function withUploadedFiles(array $uploadedFiles)
*/
public function getParsedBody()
{
if ($this->serverRequest->getBody()->getSize() && $this->serverRequest->getParsedBody() === null) {
$this->serverRequest = $this->serverRequest->withParsedBody(
json_decode($this->serverRequest->getBody(), true)
);
}

return $this->serverRequest->getParsedBody();
}

Expand Down
29 changes: 0 additions & 29 deletions src/JsonApi/Transformer/AbstractCollectionDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

abstract class AbstractCollectionDocument extends AbstractCompoundDocument
{
use CollectionFilterTrait;

/**
* @var \Traversable|array
*/
Expand All @@ -25,31 +23,6 @@ public function __construct(AbstractResourceTransformer $transformer)
$this->transformer = $transformer;
}

/**
* @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
*/
abstract protected function filterContent(RequestInterface $request);

/**
* @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
* @param string $defaultSorting
*/
protected function sortCollection(RequestInterface $request, $defaultSorting = "")
{
if (empty($request->getQueryParam("sort"))) {
$request = $request->withQueryParam("sort", $defaultSorting);
}
$this->sortByFields($this->data, $this->included, $request->getSortingByFields());
}

/**
* @param \WoohooLabs\Yin\JsonApi\Request\RequestInterface $request
*/
protected function filterCollection(RequestInterface $request)
{
$this->filterByFields($this->data, $this->included, $request->getFilteringByFields());
}

/**
* Sets the value of the "data" and "included" properties based on the "resource" property.
*
Expand All @@ -62,8 +35,6 @@ protected function setContent(RequestInterface $request)
foreach ($this->domainObject as $item) {
$this->data[] = $this->transformer->transformToResource($item, $request, $this->included);
}

$this->filterContent($request);
}

/**
Expand Down
249 changes: 0 additions & 249 deletions src/JsonApi/Transformer/CollectionFilterTrait.php

This file was deleted.

0 comments on commit 6c94024

Please sign in to comment.