Skip to content
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

Open
wants to merge 94 commits into
base: main
Choose a base branch
from
Open

Conversation

barw4
Copy link
Contributor

@barw4 barw4 commented Aug 12, 2024

🎫 Issue IBX-8190

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 and Generator have to be created and passed as arguments to ValueObjectVisitor instance.

        $valueObjectVisitor->visit($visitor, $generator, $object);

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

@barw4 barw4 self-assigned this Aug 12, 2024
@barw4 barw4 changed the title [POC] [Work in progress] Add Symfony's Serializer support [POC] Add Symfony's Serializer support Aug 26, 2024
@barw4 barw4 requested a review from a team August 26, 2024 12:59
@Steveb-p
Copy link
Contributor

Since I consulted this approach I'll give some explanations too.

Whole concept relies on using Serializer as primary entry point for data normalization.

While analyzing how Visitors worked with Generator, it became apparent that Generator basically serves as a Data Container that changes it's internal "pointer" as instructed by Visitor. This is "shared" between XML and JSON Generators, with the difference being that XML outputs it's state during this process.

So, since the primary difference between Symfony normalization and our Visitor's processing is that Symfony returns data and Visitors pass around Generator (as data storage), we can give Visitors a "fake" Generator - which whole purpose is to store data - and use it's state at the end as normalization result. This results in both processes behaving in a similar way.

@barw4 barw4 changed the title [POC] Add Symfony's Serializer support [POC] IBX-8190: Add Symfony's Serializer support Aug 29, 2024
{
use NormalizerAwareTrait;

private const string CALLED_CONTEXT = __CLASS__ . '_CALLED';
Copy link
Contributor

Choose a reason for hiding this comment

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

@alongosz we might want to standardize naming for encoder key, when it should be skipped in the next normalization pass, just like in your PR.

@barw4 barw4 changed the title [POC] IBX-8190: Add Symfony's Serializer support IBX-8190: Add Symfony's Serializer support Oct 18, 2024
Copy link

sonarcloud bot commented Oct 24, 2024

@barw4 barw4 added Feature New feature request Ready for review and removed Work in progress labels Oct 24, 2024
phpunit.integration.xml Show resolved Hide resolved
phpunit.integration.xml Show resolved Hide resolved
src/contracts/Output/Generator.php Show resolved Hide resolved
src/contracts/Output/Generator.php Show resolved Hide resolved
Comment on lines +149 to +152
throw new \LogicException(sprintf(
'Parent element at %s cannot be `null`.',
__METHOD__,
));
Copy link
Contributor

Choose a reason for hiding this comment

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

If you make getParent() part of the interface, you can declare that trying to getParent() without one would give this exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature request Ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants