-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced normalizers for Generator state
- Loading branch information
Showing
5 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
|
||
namespace Ibexa\Rest\Output\Normalizer; | ||
|
||
use Ibexa\Rest\Output\Generator\Data\ArrayList; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
final class ArrayListNormalizer implements NormalizerInterface | ||
final class ArrayListNormalizer implements NormalizerInterface, NormalizerAwareInterface | ||
{ | ||
use NormalizerAwareTrait; | ||
|
||
/** | ||
* @param \Ibexa\Rest\Output\Generator\Data\ArrayList $object | ||
* @param array<mixed> $context | ||
*/ | ||
public function normalize($object, ?string $format = null, array $context = []) | ||
{ | ||
dump($object); | ||
$data = []; | ||
foreach ($object as $key => $value) { | ||
$data[$key] = $this->normalizer->normalize($value, $format, $context); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
public function supportsNormalization($data, ?string $format = null): bool | ||
{ | ||
return $data instanceof ArrayList; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
|
||
namespace Ibexa\Rest\Output\Normalizer; | ||
|
||
use Ibexa\Rest\Output\Generator\Json\ArrayObject; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
final class ArrayObjectNormalizer implements NormalizerInterface | ||
{ | ||
|
||
/** | ||
* @param array<mixed> $context | ||
* | ||
* @return array<mixed> | ||
*/ | ||
public function normalize($object, ?string $format = null, array $context = []): array | ||
{ | ||
return get_object_vars($object); | ||
$data = get_object_vars($object); | ||
|
||
unset($data['_ref_parent']); | ||
|
||
foreach ($data as $key => $value) { | ||
$data[$key] = $this->normalize($value, $format, $context); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
public function supportsNormalization($data, ?string $format = null): bool | ||
{ | ||
return $data instanceof ArrayObject; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,41 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
|
||
namespace Ibexa\Rest\Output\Normalizer; | ||
|
||
use Ibexa\Rest\Output\Generator\Json\JsonObject; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
final class JsonObjectNormalizer implements NormalizerInterface | ||
final class JsonObjectNormalizer implements NormalizerInterface, NormalizerAwareInterface | ||
{ | ||
use NormalizerAwareTrait; | ||
|
||
/** | ||
* @param array<mixed> $context | ||
* | ||
* @return array<mixed> | ||
*/ | ||
public function normalize($object, ?string $format = null, array $context = []): array | ||
{ | ||
return get_object_vars($object); | ||
$vars = get_object_vars($object); | ||
|
||
unset($vars['_ref_parent']); | ||
|
||
foreach ($vars as $name => $value) { | ||
$vars[$name] = $this->normalizer->normalize($value, $format, $context); | ||
} | ||
|
||
return $vars; | ||
} | ||
|
||
public function supportsNormalization($data, ?string $format = null): bool | ||
{ | ||
return $data instanceof JsonObject; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters