コード例 #1
0
 /**
  * @covers \Gamma\Pushpin\PushpinBundle\Services\Events\Json\EventParser::getEventJson
  */
 public function testGetEventJson()
 {
     static::assertEquals('{
             "string":"test string",
             "bool":true,
             "int":150,
             "float":150.9999,
             "array": {
                 "key":"value"
             }
         }', self::$instance->getEventJson(self::$event));
 }
コード例 #2
0
 /**
  * @param WebSocketEvent $webSocketEvent
  *
  * @return AbstractJsonEvent
  *
  * @throws \RuntimeException
  */
 private function resolveJsonEvent(WebSocketEvent $webSocketEvent)
 {
     if ($webSocketEvent->type !== TextEventInterface::EVENT_TYPE) {
         throw new \RuntimeException(sprintf('Cannot parse event with type "%s". Expected type is "%s"', $webSocketEvent->type, TextEventInterface::EVENT_TYPE));
     }
     $eventName = $this->parser->getEventName($webSocketEvent);
     $className = sprintf('%s\\%s', $this->baseNamespace, $this->getClassByEventName($eventName));
     if (class_exists($className)) {
         $event = new $className($webSocketEvent->type, $webSocketEvent->content);
         $deSerialized = $this->serializer->deserialize($event);
         return $deSerialized;
     }
     throw new \RuntimeException(sprintf('Class "%s" not exists', $className));
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function __construct($type, $content)
 {
     parent::__construct($type, $content);
     $this->name = EventParser::getEventName($this);
     $this->json = EventParser::getEventJson($this);
 }