function it_restores_an_identical_version_of_a_serialized_object() { $emitter = new Product(\Rhumsaa\Uuid\Uuid::uuid4(), 'shoe'); $event = new Event\Generic('yes it did', ['reason' => 'because!']); $event->setEmitter($emitter); if ($this->serializer->unserialize($this->serializer->serialize($event)) != $event) { throw new \Exception(); } }
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; }