-
-
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
[WIP] adds an event system #189
Conversation
} | ||
|
||
foreach (call_user_func($subscriberClass, 'getSubscribedEvents') as $eventData) { | ||
if ( ! isset($eventData['name'])) { |
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.
according to the phpoc of the interface, it should be event
, not name
. either the phpdoc need to be fixed or the compiler pass
Is it possible to add additional stuff in the serialized data, which is not in the original object ? |
@@ -110,12 +109,16 @@ public function accept($data, $type, VisitorInterface $visitor) | |||
foreach ($metadata->preSerializeMethods as $method) { | |||
$method->invoke($data); | |||
} | |||
|
|||
if (null !== $this->dispatcher && $this->dispatcher->hasListeners('serializer.pre_serialize', $type)) { | |||
$this->dispatcher->dispatch(new Event($visitor, $data, $metadata)); |
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.
There should be 3 more arguments. The EventDispatcherInterface
interface expects $eventName, $class, $format, $event
.
I like this. I think I could also use that to skip serialization of ToMany relations. +1 |
TODO: Add some docs, and tests
This adds an event system to the serializer. Basically, you can now register dedicated classes where you currently could only use methods on objects, that is on pre-serialization, post-serialization, and post-deserialization.
I've not re-used an existing event dispatcher (I've looked at Symfony, and Doctrine ones) for several reasons:
This should help to implement something like #121 in a cleaner, more re-usable way. I've also thought about allowing listeners to skip serialization for an object, but I'm not sure about this yet.
Feedback welcome.