Skip to content

[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

Closed
wants to merge 8 commits into from
Closed

[Serializer][FrameworkBundle] Add a DateInterval normalizer #23747

wants to merge 8 commits into from

Conversation

Lctrs
Copy link
Contributor

@Lctrs Lctrs commented Aug 1, 2017

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.

@@ -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
Copy link
Contributor

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?

Copy link
Contributor Author

@Lctrs Lctrs Aug 2, 2017

Choose a reason for hiding this comment

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

👍

Done in #23765.

@ogizanagi ogizanagi added this to the 3.4 milestone Aug 2, 2017
}

if (!$this->isISO8601($data)) {
throw new UnexpectedValueException('Non ISO 8601 interval strings are not supported yet.');
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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));
Copy link
Contributor Author

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 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me :)

@Lctrs
Copy link
Contributor Author

Lctrs commented Aug 13, 2017

PR updated to fix comment made by @ogizanagi and @chalasr.

@Lctrs
Copy link
Contributor Author

Lctrs commented Aug 18, 2017

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.');
Copy link
Contributor

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.

@ogizanagi ogizanagi requested a review from dunglas August 18, 2017 06:10
@ogizanagi
Copy link
Contributor

Could you add an entry in component's CHANGELOG.md file?

@Lctrs
Copy link
Contributor Author

Lctrs commented Aug 31, 2017

@ogizanagi Done.

@Lctrs
Copy link
Contributor Author

Lctrs commented Sep 14, 2017

@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) {
Copy link
Contributor

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) {
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

@ogizanagi
Copy link
Contributor

ogizanagi commented Sep 14, 2017

@Lctrs : Nothing to me (appart from the comments I've just added, since the PR was tweaked since my last review). We just miss another approval (not mandatory here, but always good to take).

ping @symfony/deciders , @dunglas :)

@ogizanagi
Copy link
Contributor

Thank you @Lctrs.

ogizanagi added a commit that referenced this pull request Sep 15, 2017
…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
@ogizanagi ogizanagi closed this Sep 15, 2017
@Lctrs Lctrs deleted the feature/dateinterval-normalizer branch September 15, 2017 16:11
xabbuh added a commit to symfony/symfony-docs that referenced this pull request Sep 22, 2017
…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
This was referenced Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants