public function serialize(Visitor\ArraySerialize $visitor, Event\Generic $event, array $type, Context $context) { $data = ['name' => $event->getName(), 'emitter_class' => $event->getEmitterClass(), 'emitter_id' => $visitor->getNavigator()->accept($event->getEmitterId(), null, $context), 'attributes' => array_map($closure = function ($attribute) use(&$closure, $visitor, $context) { if (is_array($attribute)) { return ['__type__' => 'array', '__value__' => array_map($closure, $attribute)]; } return ['__type__' => is_object($attribute) ? get_class($attribute) : gettype($attribute), '__value__' => $visitor->getNavigator()->accept($attribute, null, $context)]; }, $event->getAttributes())]; $visitor->setRoot($data); return $data; }