示例#1
0
 public function deserialize(Visitor\ArrayDeserialize $visitor, $data, array $type, Context $context)
 {
     $attributes = array_map($closure = function ($attribute) use(&$closure, $visitor, $context) {
         if (isset($attribute['__type__']) && 'array' === $attribute['__type__']) {
             return array_map($closure, $attribute['__value__']);
         }
         return $visitor->getNavigator()->accept($attribute['__value__'], ['name' => $attribute['__type__'], 'params' => []], $context);
     }, $data['attributes']);
     $event = new Event\Generic($data['name'], $attributes);
     $reflect = new Reflection($event);
     $reflect->setPropertyValue('emitterClass', $data['emitter_class']);
     $reflect->setPropertyValue('emitterId', $visitor->getNavigator()->accept($data['emitter_id'], ['name' => 'Rhumsaa\\Uuid\\Uuid', 'params' => []], $context));
     return $event;
 }
示例#2
0
 public function findBy($class, $id)
 {
     $statement = $this->pdo->prepare('SELECT event_class, name, emitter_class, emitter_id, attributes
         FROM event
         WHERE emitter_class = :class AND emitter_id = :id
     ;');
     $statement->bindValue('class', $class);
     $statement->bindValue('id', $id);
     $statement->execute();
     $hasFetched = false;
     while (false !== ($row = $statement->fetch(PDO::FETCH_ASSOC))) {
         $hasFetched = true;
         $event = $this->serializer->unserialize(json_decode($row['attributes'], true), $row['event_class']);
         $reflect = new Reflection($event);
         $reflect->setPropertyValue('emitterClass', $row['emitter_class']);
         $reflect->setPropertyValue('emitterId', $row['emitter_id']);
         (yield $event);
     }
     if (!$hasFetched) {
         throw new NoResult();
     }
 }