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

MenuItem (tree) is not serializable #309

Open
cjprinse opened this issue Aug 29, 2019 · 3 comments

Comments

@cjprinse
Copy link

commented Aug 29, 2019

I want the menu to be serializable, because we use a large menu (200+ items) and we want to cache the result.

When serializing the menuItem (including children) an exception will thrown:
Serialization of 'Closure' is not allowed

This is due to the injected ItemFactory.

solution will be to implement Serializable interface on the menuItem and reinject the factory on deserialization

@stof

This comment has been minimized.

Copy link
Collaborator

commented Aug 29, 2019

We cannot reinject the factory when using the PHP serialization API, as there is no way to hook in it externally (and we don't want to make the factory available in a global variable to be able to retrieve it from inside the unserialized MenuItem). So we cannot implement Serializable in a usable way.

My suggestion would be to use a more powerful serializer for that (one that allows hooking from the outside), like symfony/serializer or jms/serializer (and both of them would allow you to use the library without modifying it btw).

@cjprinse

This comment has been minimized.

Copy link
Author

commented Aug 29, 2019

Ok, I understand. But why would you like the the have the factory injected in the menuItem anyway? menuItem should be a popo right?

@stof

This comment has been minimized.

Copy link
Collaborator

commented Sep 6, 2019

well, currently, we have methods to build childs on the MenuItem itself, to build the tree. This is why we need the factory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.