1313
1414namespace Laudis \Neo4j \HttpDriver ;
1515
16- use function json_encode ;
17- use const JSON_THROW_ON_ERROR ;
1816use JsonException ;
1917use Laudis \Neo4j \Contracts \ClientInterface ;
2018use Laudis \Neo4j \Databags \RequestData ;
2321use Psr \Http \Message \RequestFactoryInterface ;
2422use Psr \Http \Message \RequestInterface ;
2523use Psr \Http \Message \StreamFactoryInterface ;
26- use stdClass ;
2724
2825final class RequestFactory
2926{
@@ -62,7 +59,7 @@ private function createRequest(RequestData $data, string $method, string $body =
6259 */
6360 public function pushToTransaction (RequestData $ data , int $ transactionId , iterable $ statements ): RequestInterface
6461 {
65- $ body = $ this ->prepareBody ($ statements , $ data );
62+ $ body = $ this ->formatter -> prepareBody ($ statements , $ data );
6663 $ endpoint = $ data ->getEndpoint ().'/ ' .$ transactionId ;
6764
6865 return $ this ->createRequest ($ data ->withEndpoint ($ endpoint ), 'POST ' , $ body );
@@ -75,7 +72,7 @@ public function pushToTransaction(RequestData $data, int $transactionId, iterabl
7572 */
7673 public function post (RequestData $ data , iterable $ statements ): RequestInterface
7774 {
78- $ body = $ this ->prepareBody ($ statements , $ data );
75+ $ body = $ this ->formatter -> prepareBody ($ statements , $ data );
7976
8077 return $ this ->createRequest ($ data , 'POST ' , $ body );
8178 }
@@ -84,28 +81,4 @@ public function delete(RequestData $data): RequestInterface
8481 {
8582 return $ this ->createRequest ($ data , 'DELETE ' );
8683 }
87-
88- /**
89- * @param iterable<Statement> $statements
90- *
91- * @throws JsonException
92- */
93- private function prepareBody (iterable $ statements , RequestData $ config ): string
94- {
95- $ tbr = [];
96- foreach ($ statements as $ statement ) {
97- $ st = [
98- 'statement ' => $ statement ->getText (),
99- 'resultDataContents ' => ['ROW ' ],
100- 'includeStats ' => $ config ->includeStats (),
101- ];
102- $ parameters = $ statement ->getParameters ();
103- $ st ['parameters ' ] = $ parameters === [] ? new stdClass () : $ parameters ;
104- $ tbr [] = $ st ;
105- }
106-
107- return json_encode ([
108- 'statements ' => $ tbr ,
109- ], JSON_THROW_ON_ERROR );
110- }
11184}
0 commit comments