-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
DateTime - Deserialize from more formats (default) #1559
Conversation
Does this addition need to be documented? |
I can put it somewhere but please tell me where. |
Who can take it further? |
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.
@iKsSs In general - great work! It looks like we do not have a documentation for the Handlers - So creating docs in bundle sounds ok for me.
I left 2 small comments - can you take a look at them please? :)
Best, Marcin
src/Handler/DateHandler.php
Outdated
bool $xmlCData = true, | ||
array $defaultDeserializationFormats = [\DateTime::ATOM] | ||
) { | ||
$this->defaultFormat = $defaultFormat; | ||
$this->defaultDeserializationFormats = $defaultDeserializationFormats; |
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.
If I understand correctly in the past $defaultFormat
was working for both - serialisation & deserialisation. With the changes that you proposed I can see small BC break - when somebody was using $defaultFormat with different format after updating the package, they will get DateTime::ATOM
as a deserialisation format what might be small BC. I guess something like might help to keep it consistent with old behaviour when no defaultDeserializationFormats
are passed.
bool $xmlCData = true, | |
array $defaultDeserializationFormats = [\DateTime::ATOM] | |
) { | |
$this->defaultFormat = $defaultFormat; | |
$this->defaultDeserializationFormats = $defaultDeserializationFormats; | |
bool $xmlCData = true, | |
array $defaultDeserializationFormats = [] | |
) { | |
$this->defaultFormat = $defaultFormat; | |
$this->defaultDeserializationFormats = $defaultDeserializationFormats === [] ? [$defaultFormat] : $defaultDeserializationFormats; |
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.
Ou, you are very right. In my case, it would be BC. Thanks for providing me with a solution to this problem.
I was thinking about renaming defaultFormat
private property to defaultSerializationFormat
, what do you think?
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.
Renaming sounds like a good solution 👍
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.
OK, done
src/Handler/DateHandler.php
Outdated
@@ -285,10 +298,14 @@ private function getDeserializationFormats(array $type): array | |||
return is_array($type['params'][2]) ? $type['params'][2] : [$type['params'][2]]; | |||
} | |||
|
|||
return [$this->getFormat($type)]; | |||
if (isset($type['params'][0])) { | |||
return is_array($type['params'][0]) ? $type['params'][0] : [$type['params'][0]]; |
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.
Looking at the old code:
private function getFormat(array $type): string
{
return $type['params'][0] ?? $this->defaultFormat;
}
$type['params'][0]
will be always string
.
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.
Yeah, that's true => I removed redundant code, thanks
I will release it on Monday! Thanks for the contribution! |
OK, you are welcome, thanks for your cooperation |
@scyzoryck What Monday? 😄 |
@iKsSs Sorry, I got some urgent stuff last week. Released today! 🎉 |
This change allows the setting of multiple default deserialization formats of Date.