コード例 #1
0
 public function onStompEvent(StompEvent $event)
 {
     $d = EventDispatcher::get();
     // If the object does not have exactly one property then
     // it's invalid.
     if (!is_object($event->getData()) || count($event->getData()) !== 1) {
         // @todo Log this...
         return false;
     }
     // The event that will be dispatched
     $ordEvent = null;
     // We foreach over the single property object, because we don't
     // know the name of the property...
     foreach ($event->getData() as $k => $v) {
         switch ($k) {
             case "CA_MSG":
             case "CB_MSG":
             case "CC_MSG":
             case "CT_MSG":
                 $ordEvent = new CClassEvent($v);
                 break;
             case "SF_MSG":
             case "SG_MSG":
             case "SH_MSG":
                 $ordEvent = new SClassEvent($v);
                 break;
             default:
                 // Unknown message type.
                 // @todo Log this error.
                 break;
         }
     }
     $d->dispatch(TopicEventNames::TRAIN_DESCRIBER, $ordEvent);
 }
コード例 #2
0
 public function onStompEvent(StompEvent $event)
 {
     $d = EventDispatcher::get();
     // If there is no header property, then this Stomp message is
     // not valid, we can't process it.
     if (!is_object($event->getData()) || !property_exists($event->getData(), "header")) {
         // @todo Log this...
         return false;
     }
     // The event that will be returned.
     $ordEvent = new TrainMovementsEvent($event->getData());
     $d->dispatch(TopicEventNames::TRAIN_MOVEMENTS, $ordEvent);
 }
コード例 #3
0
 public function loop()
 {
     $d = EventDispatcher::get();
     if (!$this->stomp) {
         $this->connect();
     }
     while (true) {
         if ($this->stomp->hasFrame()) {
             $msg = $this->stomp->readFrame();
             $destination = $msg->headers['destination'];
             /** @var Topics\AbstractTopic $topic */
             $topic = $this->eventTopics[$destination];
             //$factory = "\\OpenRailData\\NetworkRail\\Services\\Stomp\\Events\\" . $topic->getFactory() . "\\Factory";
             // Save events locally so we can ack the message.
             $events = [];
             foreach (json_decode($msg->body) as $raw) {
                 $events[] = $raw;
             }
             $this->stomp->ack($msg);
             foreach ($events as $event) {
                 $d->dispatch("raw" . $topic->getEventName(), new StompEvent($event));
             }
         }
     }
 }
コード例 #4
0
 public function onStompEvent(StompEvent $event)
 {
     $d = EventDispatcher::get();
     $ordEvent = new VstpEvent($event->getData());
     $d->dispatch(TopicEventNames::VSTP, $ordEvent);
 }
コード例 #5
0
 public function listen()
 {
     EventDispatcher::get()->addListener("raw" . $this->getEventName(), [$this, 'onStompEvent']);
 }
コード例 #6
0
 public function onStompEvent(StompEvent $event)
 {
     $d = EventDispatcher::get();
     $event = new RtppmEvent($event->getData());
     $d->dispatch(TopicEventNames::RTPPM, $event);
 }