/** * Formats the Neo4j Response. * * @param array $response * @param \GraphAware\Common\Cypher\Statement[] $statements * * @return ResultCollection * * @throws Neo4jException */ public function format(array $response, array $statements) { if (isset($response['errors'][0])) { $e = new Neo4jException($response['errors'][0]['message']); $e->setNeo4jStatusCode($response['errors'][0]['code']); throw $e; } $results = new ResultCollection(); foreach ($response['results'] as $k => $result) { $resultO = new Result($statements[$k]); $resultO->setFields($result['columns']); foreach ($result['data'] as $data) { $resultO->pushRecord($data['rest'], $data['graph']); } if (array_key_exists('stats', $result)) { $resultO->setStats($result['stats']); } $results->add($resultO, $statements[$k]->getTag()); } return $results; }
/** * Run a Cypher statement against the default database or the database specified. * * @param $query * @param null|array $parameters * @param null|string $tag * @param null|string $connectionAlias * * @return \GraphAware\Common\Result\Result|null * * @throws \GraphAware\Neo4j\Client\Exception\Neo4jExceptionInterface */ public function run($query, $parameters = null, $tag = null, $connectionAlias = null) { $connection = $this->connectionManager->getConnection($connectionAlias); $params = null !== $parameters ? $parameters : array(); $statement = Statement::create($query, $params, $tag); $this->eventDispatcher->dispatch(Neo4jClientEvents::NEO4J_PRE_RUN, new PreRunEvent(array($statement))); try { $result = $connection->run($query, $parameters, $tag); $this->eventDispatcher->dispatch(Neo4jClientEvents::NEO4J_POST_RUN, new PostRunEvent(ResultCollection::withResult($result))); } catch (Neo4jException $e) { $event = new FailureEvent($e); $this->eventDispatcher->dispatch(Neo4jClientEvents::NEO4J_ON_FAILURE, $event); if ($event->shouldThrowException()) { throw $e; } return; } return $result; }