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

Closed
cjprinse opened this issue Aug 29, 2019 · 5 comments
Closed

MenuItem (tree) is not serializable #309

cjprinse opened this issue Aug 29, 2019 · 5 comments

Comments

@cjprinse
Copy link

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
Copy link
Collaborator

stof 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
Copy link
Author

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
Copy link
Collaborator

stof 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.

@garak
Copy link
Collaborator

garak commented Mar 30, 2020

Can we close this?

@cjprinse
Copy link
Author

Yes, fine to close

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

No branches or pull requests

3 participants