PHP Method ratchet\ ConnectionInterface::callError Code Examples

PHP ratchet\ConnectionInterface::callError - 13 examples found. These are the top rated real world PHP examples of method ratchet\ConnectionInterface::callError extracted from open source projects. You can rate examples to help us improve the quality of examples
Frequently Used Methods
Example #1
0
 /**
  * Dispatches an event for the called RPC
  *
  * @param \Ratchet\ConnectionInterface $conn
  * @param string $id
  * @param string|\Ratchet\Wamp\Topic $topic
  * @param array $params
  */
 public function onCall(Conn $conn, $id, $topic, array $params)
 {
     $topicName = self::getTopicName($topic);
     $eventPayload = ['connection' => $conn, 'id' => $id, 'connectionData' => $this->_connections[$conn->WAMP->sessionId]];
     $event = $this->dispatchEvent('Rachet.WampServer.Rpc', $this, array_merge($eventPayload, ['topicName' => $topicName, 'topic' => $topic, 'params' => $params, 'wampServer' => $this]));
     if ($event->isStopped()) {
         $conn->callError($id, $event->result['stop_reason']['error_uri'], $event->result['stop_reason']['desc'], $event->result['stop_reason']['details']);
         $this->outVerbose('Rachet.WampServer.Rpc.' . $topicName . ' call (' . $id . ') was blocked');
         $this->dispatchEvent('Rachet.WampServer.RpcBlocked', $this, array_merge($eventPayload, ['topicName' => $topicName, 'reason' => $event->result['stop_reason']]));
         return false;
     }
     $start = microtime(true);
     $deferred = new \React\Promise\Deferred();
     $deferred->promise()->then(function ($results) use($conn, $id, $topicName, $start, $eventPayload) {
         $end = microtime(true);
         $conn->callResult($id, $results);
         $this->outVerbose('Rachet.WampServer.Rpc.' . $topicName . ' call (' . $id . ') took <info>' . ($end - $start) . 's</info> and succeeded');
         $this->dispatchEvent('Rachet.WampServer.RpcSuccess', $this, array_merge($eventPayload, ['topicName' => $topicName, 'results' => $results]));
     }, function ($errorUri, $desc = '', $details = null) use($conn, $id, $topicName, $start, $eventPayload) {
         $end = microtime(true);
         $conn->callError($id, $errorUri, $desc, $details);
         $this->outVerbose('Rachet.WampServer.Rpc.' . $topicName . ' call (' . $id . ') took <info>' . ($end - $start) . 's</info> and failed');
         $this->dispatchEvent('Rachet.WampServer.RpcFailed', $this, array_merge($eventPayload, ['topicName' => $topicName, 'reason' => [$errorUri, $desc, $details]]));
     });
     $this->dispatchEvent('Rachet.WampServer.Rpc.' . $topicName, $this, array_merge($eventPayload, ['promise' => $deferred, 'topic' => $topic, 'params' => $params, 'wampServer' => $this]));
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 function onCall(ConnectionInterface $conn, $id, $fn, array $params)
 {
     switch ($fn) {
         case 'setName':
             break;
         case 'createRoom':
             $topic = $this->escape($params[0]);
             $created = false;
             if (empty($topic)) {
                 return $conn->callError($id, 'createRoom', 'Room name can not be empty');
             }
             if (array_key_exists($topic, $this->roomLookup)) {
                 $roomId = $this->roomLookup[$topic];
             } else {
                 $created = true;
                 $roomId = uniqid('room-');
                 $this->broadcast(static::CTRL_ROOMS, array($roomId, $topic, 1));
             }
             if ($created) {
                 $this->rooms[$roomId] = new \SplObjectStorage();
                 $this->roomLookup[$topic] = $roomId;
                 return $conn->callResult($id, array('id' => $roomId, 'display' => $topic));
             } else {
                 return $conn->callError($id, 'createRoom', "Room '{$topic}' exists", array('id' => $roomId, 'display' => $topic));
             }
             break;
         default:
             return $conn->callError($id, '', 'Unknown call');
             break;
     }
 }
 /**
  * @param ConnectionInterface $conn
  * @param string              $id
  * @param string              $topic
  * @param WampRequest         $request
  * @param array               $params
  */
 public function dispatch(ConnectionInterface $conn, $id, $topic, WampRequest $request, array $params)
 {
     $callback = $request->getRoute()->getCallback();
     try {
         $procedure = $this->rpcRegistry->getRpc($callback);
     } catch (\Exception $e) {
         $conn->callError($id, $topic, $e->getMessage(), ['rpc' => $topic, 'request' => $request]);
         return;
     }
     $method = $this->toCamelCase($request->getAttributes()->get('method'));
     $result = null;
     try {
         $result = call_user_func([$procedure, $method], $conn, $request, $params);
     } catch (\Exception $e) {
         $conn->callError($id, $topic, $e->getMessage(), ['code' => $e->getCode(), 'rpc' => $topic, 'params' => $params, 'request' => $request]);
         return;
     }
     if ($result === null) {
         $result = false;
     }
     if ($result) {
         if ($result instanceof RpcResponse) {
             $result = $result->getData();
         } elseif (!is_array($result)) {
             $result = [$result];
         }
         $conn->callResult($id, $result);
         return;
     } elseif ($result === false) {
         $conn->callError($id, $topic, 'RPC Error', ['rpc' => $topic, 'params' => $params, 'request' => $request]);
     }
     $conn->callError($id, $topic, 'Unable to find that command', ['rpc' => $topic->getId(), 'params' => $params, 'request' => $request]);
     return;
 }
Example #4
0
 public function dispatch(Conn $conn, $id, $topic, array $params)
 {
     $parts = explode("/", $topic->getId());
     if (count($parts) < 2) {
         $conn->callError($id, $topic, "Incorrectly formatted Topic name", array("topic_name" => $topic->getId()));
         return;
     }
     $handler = $this->getHandler($parts[0]);
     $method = $this->toCamelCase($parts[1]);
     $result = null;
     if ($handler) {
         try {
             $result = call_user_func(array($handler, $method), $conn, $params);
         } catch (\Exception $e) {
             $conn->callError($id, $topic, $e->getMessage(), array("code" => $e->getCode(), "rpc" => $topic->getId(), "params" => $params));
             return;
         }
         if ($result === null) {
             //incase handler doesnt return anything!
             $result = false;
         }
     }
     if ($result) {
         if (!is_array($result)) {
             $result = array($result);
         }
         $conn->callResult($id, $result);
         return;
     } elseif ($result === false) {
         $conn->callError($id, $topic, "RPC Failed", array("rpc" => $topic->getId(), "params" => $params));
     }
     $conn->callError($id, $topic, "Unable to find that command", array("rpc" => $topic->getId(), "params" => $params));
     return;
 }
Example #5
0
 /**
  * @param ConnectionInterface $conn
  * @param string $id
  * @param \Ratchet\Wamp\Topic|string $topic
  * @param array $params
  */
 public function onCall(ConnectionInterface $conn, $id, $topic, array $params)
 {
     if (isset($this->command[$topic->getId()])) {
         /** @var CommandInterface $command */
         $command = $this->command[$topic->getId()];
         $result = $command->run($this->node, $params);
         $conn->callResult($id, $result);
     }
     $conn->callError($id, $topic, ['error' => 'Invalid call']);
 }
 public function onCall(ConnectionInterface $conn, $id, $topic, array $params)
 {
     switch ($topic->getId()) {
         case "synchronize":
             $conn->callResult($id, $this->playerData);
             break;
         default:
             $conn->callError($id, $topic, 'You are not allowed to make calls')->close();
     }
     // In this application if clients send data it's because the user hacked around in console
 }
 public function onCall(Conn $from, $callId, $topic, array $params)
 {
     echo 'Received data from ' . $from->resourceId . "\n";
     if ($topic->getId() == 'api.call') {
         if (!isset($params['id']) || !is_int($params['id'])) {
             var_dump($params);
             $from->callError($callId, $topic, 'Bad request: invalid call id');
             return;
         }
         // Handle HTTP headers
         if (isset($params['http_headers']) && is_array($params['http_headers'])) {
             if (isset($params['http_headers']['Accept-Language'])) {
                 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $params['http_headers']['Accept-Language'];
             }
         }
         try {
             if (isset($params['groupped']) && $params['groupped'] == true) {
                 $resp = $this->_handleRequestGroup($from, $params['data']);
             } else {
                 $resp = $this->_handleRequest($from, $params['data']);
             }
         } catch (Exception $e) {
             $errMsg = $e->getMessage();
             $resp = new ApiResponse();
             $resp->setSuccess(false);
             $resp->setValue($errMsg);
             $resp->setChannel(2, $errMsg);
         }
         $resp->setId($params['id']);
         $respData = $resp->generateArray();
         echo 'Sending data to ' . $from->resourceId . "\n";
         $from->callResult($callId, $respData);
     } else {
         $from->callError($callId, $topic, 'Bad request: unsupported topic "' . $topic->getId() . '"');
     }
 }
 public function onCall(ConnectionInterface $conn, $id, $topic, array $params)
 {
     // In this application if clients send data it's because the user hacked around in console
     $conn->callError($id, $topic, 'Calls not supported')->close();
 }
Example #9
0
 /**
  * @param ConnectionInterface $conn
  * @param string $id
  * @param \Ratchet\Wamp\Topic|string $topic
  * @param array $params
  */
 public function onCall(ConnectionInterface $conn, $id, $topic, array $params)
 {
     $conn->callError($id, $topic, 'You are not allowed to make calls');
 }
 /**
  * An RPC call has been received
  *
  * @param \Ratchet\ConnectionInterface $conn
  * @param string                       $id     The unique ID of the RPC, required to respond to
  * @param string|Topic                 $topic  The topic to execute the call against
  * @param array                        $params Call parameters received from the client
  */
 function onCall(ConnectionInterface $conn, $id, $topic, array $params)
 {
     // In this application if clients send data it's because the user hacked around in console
     $conn->callError($id, $topic, 'You are not allowed to make calls')->close();
 }
Example #11
0
 /**
  * An RPC call has been received.
  *
  * @param \Ratchet\ConnectionInterface $conn
  * @param string                       $id     The unique ID of the RPC, required to respond to
  * @param string|Topic                 $topic  The topic to execute the call against
  * @param array                        $params Call parameters received from the client
  */
 public function onCall(ConnectionInterface $conn, $id, $topic, array $params)
 {
     $this->console->info('onCall');
     $conn->callError($id, $topic, 'You are not allowed to make calls')->close();
 }
Example #12
0
 public function onCall(Conn $conn, $id, $topic, array $params)
 {
     $conn->callError($id, $topic, 'RPC not supported on this demo');
 }
 /**
  * {@inheritdoc}
  */
 public function onCall(Conn $conn, $id, $topic, array $params)
 {
     $this->logger->error(sprintf('Received RPC call on topic %s', $topic->getId()), ['topic' => $topic]);
     $conn->callError($id, $topic, 'RPC not supported on this demo');
 }