/** * @param string $entity * @param string $action * @param array $params * @throws GarbledMessageException * @throws InvalidMessageException * @return mixed */ public function call($entity, $action, $params) { $this->log->debug("Send API call: {entity}.{action} over {cxnId}", array('entity' => $entity, 'action' => $action, 'cxnId' => $this->cxnId)); $cxn = $this->cxnStore->getByCxnId($this->cxnId); $req = new StdMessage($cxn['cxnId'], $cxn['secret'], array($entity, $action, $params, $this->appMeta['appCert'])); list($respHeaders, $respCiphertext, $respCode) = $this->http->send('POST', $cxn['siteUrl'], $req->encode(), array('Content-type' => Constants::MIME_TYPE)); $respMessage = $this->decode(array(StdMessage::NAME, GarbledMessage::NAME), $respCiphertext); if ($respMessage instanceof GarbledMessage) { throw new GarbledMessageException($respMessage); } elseif ($respMessage instanceof StdMessage) { if ($respMessage->getCxnId() != $cxn['cxnId']) { // Tsk, tsk, Mallory! throw new InvalidMessageException('Received response from incorrect connection.'); } return $respMessage->getData(); } else { throw new InvalidMessageException('Unrecognized message type.'); } }