-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer][FrameworkBundle] Add a DateInterval normalizer #23747
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
Conversation
@@ -1336,12 +1337,19 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild | |||
private function registerSerializerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) | |||
{ | |||
if (class_exists('Symfony\Component\Serializer\Normalizer\DataUriNormalizer')) { | |||
// Run after serializer.normalizer.object | |||
// Run before serializer.normalizer.object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you submit another PR to fix this in 3.3 instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Done in #23765.
} | ||
|
||
if (!$this->isISO8601($data)) { | ||
throw new UnexpectedValueException('Non ISO 8601 interval strings are not supported yet.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why "yet"? Do you plan to add support for this and how?
On the contrary, I'd change the message for "Expected a valid ISO 8601 interval string." and remove related tests/dataprovider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, as I said, most code have been adapted from the DateInterval form type, and especially from the class DateIntervalToStringTransformer which have the same exception message.
I thought that if non ISO 8601 interval string support was added to this class, maybe we could port it to the DateIntervalNormalizer. But I'm not sure it's worth it or a valid use case for the Serializer part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @ogizanagi, let's not promise something that we're not sure to want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
I'll try to make the requested changes before I go on holidays.
// Run before serializer.normalizer.object | ||
$definition = $container->register('serializer.normalizer.dateinterval', DateIntervalNormalizer::class); | ||
$definition->setPublic(false); | ||
$definition->addTag('serializer.normalizer', array('priority' => -915)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ogizanagi are you okay with this priority ? Or should I change it to -930 to be more consistent with other normalizers ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me :)
PR updated to fix comment made by @ogizanagi and @chalasr. |
Unless there are more comments that need to be addressed, it should be ready to merge then :) |
public function denormalize($data, $class, $format = null, array $context = array()) | ||
{ | ||
if (!is_string($data)) { | ||
throw new InvalidArgumentException('Data expected to be a string, '.gettype($data).' given.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use sprintf
for exception messages.
Could you add an entry in component's CHANGELOG.md file? |
@ogizanagi Done. |
@ogizanagi Is there anything else that prevent it from being merged ? |
@@ -631,9 +632,9 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $ | |||
|
|||
$transitions = array(); | |||
foreach ($workflow['transitions'] as $transition) { | |||
if ($type === 'workflow') { | |||
if ('workflow' === $type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must be reverted. This change does not belong to this PR.
$transitions[] = new Definition(Workflow\Transition::class, array($transition['name'], $transition['from'], $transition['to'])); | ||
} elseif ($type === 'state_machine') { | ||
} elseif ('state_machine' === $type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
@@ -1088,6 +1104,7 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con | |||
if (ChainAdapter::class === $parentDefinition->getClass()) { | |||
break; | |||
} | |||
// no break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
Thank you @Lctrs. |
…lizer (Lctrs) This PR was squashed before being merged into the 3.4 branch (closes #23747). Discussion ---------- [Serializer][FrameworkBundle] Add a DateInterval normalizer | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | symfony/symfony-docs#8267 Could be useful for API needing to submit a duration. Most code have been adapted from @MisatoTremor's DateInterval form type. Credits to him. Commits ------- 6185cb1 [Serializer][FrameworkBundle] Add a DateInterval normalizer
…alizer (Lctrs) This PR was squashed before being merged into the 3.4 branch (closes #8267). Discussion ---------- [Serializer] Document the new DateIntervalNormalizer normalizer Waiting for symfony/symfony#23747 to be merged. Commits ------- 9784714 [Serializer] Document the new DateIntervalNormalizer normalizer
Could be useful for API needing to submit a duration.
Most code have been adapted from @MisatoTremor's DateInterval form type. Credits to him.