public function pushToTransaction($transactionId, array $statementsStack)
{
$statements = [];
foreach ($statementsStack as $statement) {
$st = ['statement' => $statement->text(), 'resultDataContents' => ['REST', 'GRAPH'], 'includeStats' => true];
if (!empty($statement->parameters())) {
$st['parameters'] = $this->formatParams($statement->parameters());
}
$statements[] = $st;
}
$headers = [['X-Stream' => true, 'Content-Type' => 'application/json']];
$body = json_encode(['statements' => $statements]);
$request = new Request('POST', sprintf('%s/db/data/transaction/%d', $this->uri, $transactionId), $headers, $body);
try {
$response = $this->httpClient->send($request);
$data = json_decode((string) $response->getBody(), true);
if (!empty($data['errors'])) {
$msg = sprintf('Neo4j Exception with code "%s" and message "%s"', $data['errors'][0]['code'], $data['errors'][0]['message']);
$exception = new Neo4jException($msg);
$exception->setNeo4jStatusCode($data['errors'][0]['code']);
throw $exception;
}
return $this->responseFormatter->format(json_decode($response->getBody(), true), $statementsStack);
} catch (RequestException $e) {
if ($e->hasResponse()) {
$body = json_decode($e->getResponse()->getBody(), true);
if (!isset($body['code'])) {
throw $e;
}
$msg = sprintf('Neo4j Exception with code "%s" and message "%s"', $body['errors'][0]['code'], $body['errors'][0]['message']);
$exception = new Neo4jException($msg);
$exception->setNeo4jStatusCode($body['errors'][0]['code']);
throw $exception;
}
throw $e;
}
}