- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Implement the handler of serialization to process the proxy of Doctrine ORM #46
Conversation
{ | ||
public function serialize(VisitorInterface $visitor, $data, $type, &$handled) | ||
{ | ||
if ($data instanceof Proxy && get_class($data) === $type) { |
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.
Is the get_class() check necessary? It should always be true, no?
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.
Yep, here need determine already handled the proxy or no.
In the beginning I used the test state of __isInitialized__
property...
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.
Below the accept()
method is invoked, passing the type of parent class, so this handler called twice. We need to determine whether the entity is already initialized or no.
There is one issue. When accept()
method is called from this handler (the $type
argument is not null) not handled the callbacks of serialization, because the $isSerialization
is false.
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.
If we pass the type of parent class instead of null
to accept()
method, then skip loading of metadata for the proxy class.
I reviewed implementation of this handler and guess that not good... Invoke accept() method in this handler looks like a hack. What do you think about the refactoring of the graph navigator, to extract logic of handling object from I've done base implementation of refactoring in this commit 03aec39. Added a two new methods, This solution allows us to make a second pass of the object through the graph navigator in the custom handlers. |
Yes, I agree with your assessment. What I'd like to do instead is to pass to the GraphNavigator whether it is serializing, or deserializing upon instantiation (i.e. in Serializer::serialize() and Serializer::deserialize()). Then, we do not need to split the GraphNavigator, and consequentially also do not need to duplicate code. |
I've pushed the change: This should make the implementation easier. |
Added an implementation of detachObject() method. |
Thanks, merged it. |
I tried to implement a processing the proxy classes through the custom handler.
Note that not processing serialization callbacks if they defined on level of parents class of the proxy class. Since the handler invokes to
accept()
method of the navigator and passes type of parent class to second argument instead ofnull
.