8000 [Messenger] Add RedeliveryStamp (de)normalizer to avoid deprecations by Jean85 · Pull Request #45701 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Add RedeliveryStamp (de)normalizer to avoid deprecations #45701

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

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add normalization step too
  • Loading branch information
Jean85 committed Mar 11, 2022
commit 07723c93a64f1aa4cb20d6b6ed7f7994ad2fff87
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@
namespace Symfony\Component\Messenger\Transport\Serialization\Normalizer;

use Symfony\Component\Messenger\Stamp\RedeliveryStamp;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class RedeliveryStampNormalizer implements DenormalizerInterface
{
public function denormalize($data, string $type, string $format = null, array $context = [])
{
$redeliveredAt = $data['redeliveredAt'] ?? null;

return new RedeliveryStamp(
$data['retryCount'] ?? 0,
$data['redeliveredAt'] ?? null
$redeliveredAt ? new \DateTimeImmutable($redeliveredAt) : null
);
}

Expand All @@ -31,4 +36,25 @@ public function supportsDenormalization($data, string $type, string $format = nu
&& null === ($data['flattenException'] ?? null)
;
}

public function normalize($object, string $format = null, array $context = [])
{
if (! $object instanceof RedeliveryStamp) {
throw new InvalidArgumentException();
}

$dateTimeFormat = $context[DateTimeNormalizer::FORMAT_KEY] ?? \DateTimeInterface::RFC3339;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct approach? Or is there some solution to delegate this normalization to the default serialization (and to DateTimeNormalizer)?


return [
'retryCount' => $object->getRetryCount(),
'redeliveredAt' => $object->getRedeliveredAt()->format($dateTimeFormat),
];
}

public function supportsNormalization($data, string $format = null): bool
{
return Kernel::VERSION_ID >= 50200
&& $data instanceof RedeliveryStamp
;
}
}
0