Example #1
0
 public function onMessage(ConnectionInterface $from, $msg)
 {
     $result = null;
     foreach ($this->clients as $client) {
         if ($from == $client) {
             $type = strtolower(substr($msg, 0, strpos($msg, '|')));
             $data = substr($msg, strpos($msg, '|') + 1);
             switch ($type) {
                 case 'cart':
                     $result = Cart::getCartData($data);
                     break;
                 case 'prod':
                     $result = Product::getProductData($data);
                     break;
                 case 'comb':
                     $result = Combination::getCombinationData($data);
                     break;
                 default:
                     break;
             }
             if (!empty($result)) {
                 $client->send(json_encode($result));
             }
         }
     }
 }