-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Serializer] Add NormalizedValueInterface
that can be returned by NormalizerInterface::normalize
to enable receiving a value object for normalized values.
#43498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 6.0
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
NormalizedValueInterface
that can be returned by `…
…NormalizerInterface::normalize` to enable receiving a value object for normalized values.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\Serializer\Normalizer; | ||
|
||
interface NormalizedValueInterface { | ||
|
||
public function getNormalization(): array|string|int|float|bool|\ArrayObject|null; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizedValueInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
|
@@ -161,6 +162,10 @@ public function normalize(mixed $data, string $format = null, array $context = [ | |
return $normalizer->normalize($data, $format, $context); | ||
} | ||
|
||
if ($data instanceof NormalizedValueInterface) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion the serializer class should return the wrapper object too. We have a use case in API Platform: we'll be able to return an object containing the serialized data and some additional metadata. We need to be able to access the metadata from the outside. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome to hear there is an reason to have this in api platform. I will have a look later today too see how that might work. I didn't initially since i thought that would be a bigger bc break and if you want to access the data you could just have your own serializer. I do see your point though |
||
$data = $data->getNormalization(); | ||
} | ||
|
||
if (null === $data || is_scalar($data)) { | ||
return $data; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.