-
Notifications
You must be signed in to change notification settings - Fork 3
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
IBX-8190: Add Symfony's Serializer support #121
base: main
Are you sure you want to change the base?
Conversation
Since I consulted this approach I'll give some explanations too. Whole concept relies on using While analyzing how So, since the primary difference between Symfony normalization and our Visitor's processing is that Symfony returns data and Visitors pass around |
b39b477
to
0ddbb6d
Compare
src/bundle/DependencyInjection/Compiler/ValueObjectVisitorResolverPass.php
Outdated
Show resolved
Hide resolved
src/contracts/Input/Parser/Query/Criterion/BaseCriterionProcessor.php
Outdated
Show resolved
Hide resolved
e71209e
to
ab72638
Compare
0d3387d
to
cc840b3
Compare
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.
A lot of solid work 💪
Some remarks & questions:
src/contracts/Output/Generator.php
Outdated
$this->json->$name = $object; | ||
$this->json = $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.
The first line doesn't make sense here, as it's immediately overridden by the next line.
use NormalizerAwareTrait; | ||
|
||
/** | ||
* @return array<string, mixed> |
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.
* @return array<string, mixed> | |
* @return array<string, mixed> | |
* | |
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface |
if ($isXml) { | ||
$expectedXml = new \DOMDocument(); | ||
$expectedXml->preserveWhiteSpace = false; | ||
$expectedXml->formatOutput = true; | ||
$expectedXml->load($fixtureFile); | ||
|
||
$actualXml = new \DOMDocument(); | ||
$actualXml->preserveWhiteSpace = false; | ||
$actualXml->formatOutput = true; | ||
$actualXml->loadXML($actualResult); | ||
|
||
self::assertSame($expectedXml->saveXML(), $actualXml->saveXML()); |
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.
Have you tried to use assertXmlStringEqualsXmlFile
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.
Yes and I think this method expects clean xml, without:
<?xml version="1.0" encoding="UTF-8"?>
because I'm getting:
Could not read
<?xml version="1.0" encoding="UTF-8"?>
with it.
@@ -1,5 +1,5 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<elements> | |||
<element attribute="attribute value 1">element value 1</element> | |||
<element attribute="attribute value 2">element value 2</element> | |||
<element2 attribute="attribute value 2">element value 2</element2> |
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.
What's the source of/reason for that change?
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.
The reason for this is that startHashElement
does not support multiple elements of the same name, just like Json Generator. The proper way to handle this would be to use the startHashElement
with conjunction of the startList
like it's done for example in the ContentFieldValidationException
visitor:
$generator->startHashElement('errorDetails');
$generator->startList('fields');
We are imo safe here with this change because our visitors are both handling Json and Xml and if we had something like this in some visitor:
$generator->startHashElement('elements');
$generator->startValueElement('element', 'element value 1', ['attribute' => 'attribute value 1']);
$generator->endValueElement('element');
$generator->startValueElement('element', 'element value 2', ['attribute' => 'attribute value 2']);
$generator->endValueElement('element');
$generator->endHashElement('elements');
JSON output would be also broken which was never the case.
Quality Gate passedIssues Measures |
Related PRs:
https://github.com/ibexa/scheduler/pull/111
Description:
AdapterNormalizer
A new normalizer with low priority is implemented called
AdapterNormalizer
that handles data normalization or visiting data using the existing visitors. Currently, the visitors are prioritized over incoming (new) normalizers.Unfortunately, the problem is that in order to visit value objects the
Visitor
andGenerator
have to be created and passed as arguments toValueObjectVisitor
instance.Ibexa\Contracts\Rest\Output\ValueObjectVisitorDispatcher
It is deleted now and the responsibility for finding a proper visitor is moved to the newly introduced
ValueObjectVisitorResolverInterface
.Ibexa\Contracts\Rest\OutputVisitor
The
visitValueObject
method has to behave exactly the same as before as it's used throughout the app so we should keep BC here. I don't think we can change it to use normalizer as it uses the original Visitor's generator.Concept made by Paweł.
For QA:
TBD
Documentation:
TBD