Implemented minimize response processor and updated the ProcessorsInterface.

This commit is contained in:
Alex Tselegidis 2016-07-09 22:27:24 +02:00
parent bfc96409bc
commit 4189bcb459
6 changed files with 27 additions and 7 deletions

View file

@ -15,7 +15,7 @@ namespace EA\Engine\Api\V1\Processors;
class Filter implements ProcessorsInterface { class Filter implements ProcessorsInterface {
{ {
public static function process(array $response) { public static function process(array &$response) {
} }
} }

View file

@ -14,7 +14,27 @@
namespace EA\Engine\Api\V1\Processors; namespace EA\Engine\Api\V1\Processors;
class Minimize implements ProcessorsInterface { class Minimize implements ProcessorsInterface {
public static function process(array $response) { public static function process(array &$response) {
if (!isset($_GET['fields'])) {
return;
}
$fields = explode(',', $_GET['fields']);
$temporaryResponse = [];
foreach ($response as &$entry) {
$temporaryEntry = [];
foreach ($fields as $field) {
if (isset($entry[$field])) {
$temporaryEntry[$field] = $entry[$field];
}
}
$temporaryResponse[] = $temporaryEntry;
}
$response = $temporaryResponse;
} }
} }

View file

@ -14,7 +14,7 @@
namespace EA\Engine\Api\V1\Processors; namespace EA\Engine\Api\V1\Processors;
class Paginate implements ProcessorsInterface { class Paginate implements ProcessorsInterface {
public static function process(array $response) { public static function process(array &$response) {
} }
} }

View file

@ -14,5 +14,5 @@
namespace EA\Engine\Api\V1\Processors; namespace EA\Engine\Api\V1\Processors;
interface ProcessorsInterface { interface ProcessorsInterface {
public static function process(array $response); public static function process(array &$response);
} }

View file

@ -14,7 +14,7 @@
namespace EA\Engine\Api\V1\Processors; namespace EA\Engine\Api\V1\Processors;
class Search implements ProcessorsInterface { class Search implements ProcessorsInterface {
public static function process(array $response) { public static function process(array &$response) {
} }
} }

View file

@ -14,7 +14,7 @@
namespace EA\Engine\Api\V1\Processors; namespace EA\Engine\Api\V1\Processors;
class Sort implements ProcessorsInterface { class Sort implements ProcessorsInterface {
public static function process(array $response) { public static function process(array &$response) {
} }
} }