Skip to content

Commit

Permalink
Remove RawEncoder (#52)
Browse files Browse the repository at this point in the history
* Remove RawEncoder

* Serialize relations into json and then decode them into associative array instead of using raw serialization
  • Loading branch information
Andriichello authored May 19, 2023
1 parent d797844 commit 97ff3e0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 66 deletions.
1 change: 0 additions & 1 deletion php/src/Snagshout/Promote/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ protected function buildResource(string $resourceClass): AbstractResource
new Serializer(
NormalizerFactory::create(),
[
new RawEncoder(),
new JsonEncoder(new JsonEncode(), new JsonDecode()),
]
)
Expand Down
60 changes: 0 additions & 60 deletions php/src/Snagshout/Promote/Encoder/RawEncoder.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function normalize($object, $format = null, array $context = [])
if (null !== $object->getImpressions()) {
$values = [];
foreach ($object->getImpressions() as $value) {
$values[] = $this->serializer->serialize($value, 'raw', $context);
$json = $this->serializer->serialize($value, 'json', $context);
$values[] = json_decode($json, true);
}
$data['impressions'] = $values;
}
Expand Down
6 changes: 4 additions & 2 deletions php/src/Snagshout/Promote/Normalizer/DealNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,16 @@ public function normalize($object, $format = null, array $context = [])
if (null !== $object->getCategories()) {
$values = [];
foreach ($object->getCategories() as $value) {
$values[] = $this->serializer->serialize($value, 'raw', $context);
$json = $this->serializer->serialize($value, 'json', $context);
$values[] = json_decode($json, true);
}
$data['categories'] = $values;
}
if (null !== $object->getMedia()) {
$values_1 = [];
foreach ($object->getMedia() as $value_1) {
$values_1[] = $this->serializer->serialize($value_1, 'raw', $context);
$json = $this->serializer->serialize($value_1, 'json', $context);
$values_1[] = json_decode($json, true);
}
$data['media'] = $values_1;
}
Expand Down
2 changes: 0 additions & 2 deletions php/tests/Snagshout/Promote/Normalizer/DealNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Tests\Snagshout\Promote\Normalizer;

use PHPUnit\Framework\TestCase as BaseTestCase;
use Snagshout\Promote\Encoder\RawEncoder;
use Snagshout\Promote\Model\Category;
use Snagshout\Promote\Model\Deal;
use Snagshout\Promote\Model\Medium;
Expand All @@ -38,7 +37,6 @@ protected function getSerializer()
return new Serializer(
NormalizerFactory::create(),
[
new RawEncoder(),
new JsonEncoder(
new JsonEncode(),
new JsonDecode()
Expand Down

0 comments on commit 97ff3e0

Please sign in to comment.