public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
public function onMessage(ConnectionInterface $from, $msg) { $msgObject = json_decode($msg); $logparams = ''; $to = $this->getRecipientConnection($msgObject->recipient); switch ($msgObject->type) { case 'init': $this->map[$msgObject->myEmail] = $from->resourceId; $this->setGlobalVar('emailToCon', $this->map); break; case 'invite': $restId = $msgObject->restId; echo "in invite to rest {$restId}\n"; if (isset($to)) { $to->send(json_encode($msgObject)); } break; case 'response': echo "in response\nanswer is {$msgObject->answer}\n"; $logparams = $msgObject->answer; $froms = $this->getRecipientConnection($msgObject->recipient); if ($msgObject->answer == 1) { echo 'the user has accepted the invite'; $message = array('message ' => $msgObject->myEmail . ' has accepted', 'type' => 'accepted', 'recipient' => $msgObject->myEmail, 'myEmail' => $msgObject->recipient); // sends message to himself, to add a button $addButtonMessage = $this->createAddButtonMessage($msgObject); $to = $this->getRecipientConnection($msgObject->myEmail); $to->send(json_encode($addButtonMessage)); } else { echo 'the user has rejected the invite'; $message = array('message ' => $msgObject->myEmail . ' has rejected', 'type' => 'rejected', 'recipient' => $msgObject->myEmail, 'myEmail' => $msgObject->recipient); } $froms->send(json_encode($message)); break; case 'sendOrder': $newMessage = $this->switchMyWithRecipient($msgObject); $newMessage->dish = $msgObject->dish; echo "sendOrder\n"; $to->send(json_encode($newMessage)); break; case 'a': $newMessage = $this->switchMyWithRecipient($msgObject); $newMessage->dish = $msgObject->dish; $newMessage->type = 'a'; $to->send(json_encode($newMessage)); break; default: echo "in default\n"; break; } //TODO: verify it's always the same $logger = WixBisLogger::getInstance(); // $sender, $recipient, $restId, $action, $extensionVersion, $params $restId = ''; $recipient = ''; if (isset($msgObject->recipient)) { $recipient = $msgObject->recipient; } if (isset($msgObject->restId)) { $restId = $msgObject->restId; } $logger->log($msgObject->myEmail, $recipient, $restId, $msgObject->type, '', $logparams); }