Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| { | ||
| if (class_exists('Symfony\Component\Serializer\Normalizer\DataUriNormalizer')) { | ||
| // Runafter serializer.normalizer.object | ||
| // Runbefore 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)) { | ||
| thrownewUnexpectedValueException('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 classDateIntervalToStringTransformer 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 :)
Lctrs commentedAug 13, 2017
PR updated to fix comment made by@ogizanagi and@chalasr. |
Lctrs commentedAug 18, 2017
Unless there are more comments that need to be addressed, it should be ready to merge then :) |
| publicfunctiondenormalize($data,$class,$format =null,array$context =array()) | ||
| { | ||
| if (!is_string($data)) { | ||
| thrownewInvalidArgumentException('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 usesprintf for exception messages.
ogizanagi commentedAug 31, 2017
Could you add an entry in component's CHANGELOG.md file? |
Lctrs commentedAug 31, 2017
@ogizanagi Done. |
Lctrs commentedSep 14, 2017
@ogizanagi Is there anything else that prevent it from being merged ? |
| $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.
| if ('workflow' ===$type) { | ||
| $transitions[] =newDefinition(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
| 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
ogizanagi commentedSep 14, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
ogizanagi commentedSep 15, 2017
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#8267Could 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 normalizerWaiting forsymfony/symfony#23747 to be merged.Commits-------9784714 [Serializer] Document the new DateIntervalNormalizer normalizer
Uh oh!
There was an error while loading.Please reload this page.
Could be useful for API needing to submit a duration.
Most code have been adapted from@MisatoTremor's DateInterval form type. Credits to him.