13
13
14
14
namespace Laudis \Neo4j \HttpDriver ;
15
15
16
- use function json_encode ;
17
- use const JSON_THROW_ON_ERROR ;
18
16
use JsonException ;
19
17
use Laudis \Neo4j \Contracts \ClientInterface ;
20
18
use Laudis \Neo4j \Databags \RequestData ;
23
21
use Psr \Http \Message \RequestFactoryInterface ;
24
22
use Psr \Http \Message \RequestInterface ;
25
23
use Psr \Http \Message \StreamFactoryInterface ;
26
- use stdClass ;
27
24
28
25
final class RequestFactory
29
26
{
@@ -62,7 +59,7 @@ private function createRequest(RequestData $data, string $method, string $body =
62
59
*/
63
60
public function pushToTransaction (RequestData $ data , int $ transactionId , iterable $ statements ): RequestInterface
64
61
{
65
- $ body = $ this ->prepareBody ($ statements , $ data );
62
+ $ body = $ this ->formatter -> prepareBody ($ statements , $ data );
66
63
$ endpoint = $ data ->getEndpoint ().'/ ' .$ transactionId ;
67
64
68
65
return $ this ->createRequest ($ data ->withEndpoint ($ endpoint ), 'POST ' , $ body );
@@ -75,7 +72,7 @@ public function pushToTransaction(RequestData $data, int $transactionId, iterabl
75
72
*/
76
73
public function post (RequestData $ data , iterable $ statements ): RequestInterface
77
74
{
78
- $ body = $ this ->prepareBody ($ statements , $ data );
75
+ $ body = $ this ->formatter -> prepareBody ($ statements , $ data );
79
76
80
77
return $ this ->createRequest ($ data , 'POST ' , $ body );
81
78
}
@@ -84,28 +81,4 @@ public function delete(RequestData $data): RequestInterface
84
81
{
85
82
return $ this ->createRequest ($ data , 'DELETE ' );
86
83
}
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
- }
111
84
}
0 commit comments