/** * @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)); }
/** * @covers \Gamma\Pushpin\PushpinBundle\Services\Events\Json\EventParser::getEventName */ public function testGetEventName() { static::assertEquals('testAction', self::$instance->getEventName(self::$event)); }
/** * {@inheritdoc} */ public function __construct($type, $content) { parent::__construct($type, $content); $this->name = EventParser::getEventName($this); $this->json = EventParser::getEventJson($this); }