/** {@inheritdoc} */ public function addCall($methodName, array $params = [], callable $onSuccess = null, callable $onError = null) { if (!is_string($methodName)) { throw InvalidArgumentException::expectedParameter(1, 'string', $methodName); } $this->calls[$this->index] = compact('methodName', 'params'); $this->handlers[$this->index] = compact('onSuccess', 'onError'); ++$this->index; return $this; }
/** * @param callable $onError * @throws InvalidArgumentException * @return self */ public function onError($onError) { if (!is_callable($onError)) { throw InvalidArgumentException::expectedParameter(1, 'callable', $onError); } $this->onError = $onError; return $this; }
/** {@inheritdoc} */ public function call($methodName, array $params = []) { if (!is_string($methodName)) { throw InvalidArgumentException::expectedParameter(0, 'string', $methodName); } $params = array_merge($this->prependParams, $params, $this->appendParams); $payload = $this->serializer->serialize($methodName, $params); $response = $this->transport->send($this->uri, $payload); $result = $this->parser->parse($response, $isFault); if ($isFault) { throw ResponseException::fault($result); } return $result; }