Skip to content

Stop using listeners for data extraction #43

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

Merged
merged 4 commits into from
Oct 26, 2020

Conversation

lcobucci
Copy link
Member

Fix #15

This simplifies the deserialisation engine by moving away from events and allowing users to append data via object decoration.

We should remove the deprecated components on the next release.

@dsantang @rdohms can you please help me ensure that we don't break all your apps?

@lcobucci lcobucci added the Improvement Improvement of existing feature label Oct 26, 2020
@lcobucci lcobucci added this to the 0.4.0 milestone Oct 26, 2020
@lcobucci lcobucci self-assigned this Oct 26, 2020
Copy link

@dsantang dsantang left a comment

Choose a reason for hiding this comment

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

Hey @lcobucci, thanks for looking into this, the change you made does indeed fix the issue.

I also think this solution is really nice in terms of extendibility.

The change you introduced shouldn't affect our existing Clients since it's done in a BC way.

If I'm not mistaken, as an upgrade path, the existing Clients should start removing the:

@Serializer\SerializedName(IdGenerator::GENERATED_ID)

From the id property to be compatible with the next major release.

@lcobucci
Copy link
Member Author

Hey @lcobucci, thanks for looking into this, the change you made does indeed fix the issue.

I also think this solution is really nice in terms of extensibility.

🎉

The change you introduced shouldn't affect our existing Clients since it's done in a BC way.

If I'm not mistaken, as an upgrade path, the existing Clients should start removing the:

Correct! There's also the possibility of decorating the decorator (if needed):

$extractor = new AppendGeneratedIdentifier(
    new AppendGeneratedIdentifier(
        new UseInputData()
    ),
    '_input.id'
);

That would send both id and _input.id down to the serialiser - which can be kept until annotations are removed from everywhere.

It's important to remember that, if I'm not mistaken, you had some other event listeners which will need to be migrated to the new way of extracting data - they shouldn't be affected until the removal of the deprecated components, though.

@lcobucci
Copy link
Member Author

I'm just thinking about moving the interface and these extractors to chimera/foundation since they can be reused by another serialiser if we want.

This simplifies the deserialisation engine by moving away from events
and allowing users to append data via object decoration.
Since we don't use events any more these are just useless.
@lcobucci lcobucci force-pushed the stop-using-listeners-for-data-extraction branch from 17a45b1 to 4580144 Compare October 26, 2020 21:37
@lcobucci lcobucci merged commit 2263e04 into master Oct 26, 2020
@lcobucci lcobucci deleted the stop-using-listeners-for-data-extraction branch October 26, 2020 21:38
@rdohms
Copy link

rdohms commented Oct 27, 2020

@lcobucci do you have an example of replacing an injector with this decorator? Just to help migration path, maybe add this to an Upgrade.md?

Use case: a injector that uses $context->getInput()->getAttribute('some-req-data'); and injects it into $event->setData

Or is this not affected?

@lcobucci
Copy link
Member Author

lcobucci commented Oct 27, 2020

That injector doesn't need to be changed immediately after this release, only when we remove the deprecated components.

IMHO this is a good example:

https://github.com/chimeraphp/foundation/blob/master/src/MessageCreator/InputExtractor/AppendGeneratedIdentifier.php#L24-L34

I'll be documenting stuff soon but I'm terrible at that so any help is appreciated.

@rdohms
Copy link

rdohms commented Oct 27, 2020

We can help with the docs, also this PR then becomes a bit more self-documenting.

How do we hook up a InputExtractor? is there a new tag?

@lcobucci
Copy link
Member Author

lcobucci commented Oct 27, 2020

The idea is to rely on the SF DI decorator feature (using the interface as decorated service).

Something like:

<service id="MyCustomExtractor" decorates="Chimera\MessageCreator\InputExtractor">
    <argument type="service" id=".inner"/>
</service>

@rdohms
Copy link

rdohms commented Oct 27, 2020

Aaah, interesting, did not know that. Nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Improvement of existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question: how to correctly use the createAndFetch method in combination with an ArrayTransformer MessageCreator
3 participants