26
26
use Laudis \Neo4j \Databags \TransactionConfiguration ;
27
27
use Laudis \Neo4j \Enum \AccessMode ;
28
28
use Laudis \Neo4j \Types \CypherList ;
29
- use function microtime ;
30
- use function parse_url ;
31
- use const PHP_URL_PATH ;
32
29
use Psr \Http \Client \ClientInterface ;
33
30
use Psr \Http \Message \RequestInterface ;
34
31
use Psr \Http \Message \StreamFactoryInterface ;
32
+ use stdClass ;
33
+ use function is_object ;
34
+ use function microtime ;
35
+ use function parse_url ;
36
+ use const PHP_URL_PATH ;
35
37
36
38
/**
37
39
* @template T
@@ -76,21 +78,22 @@ final class HttpSession implements SessionInterface
76
78
/**
77
79
* @psalm-mutation-free
78
80
*
79
- * @param FormatterInterface<T> $formatter
81
+ * @param FormatterInterface<T> $formatter
80
82
* @param Resolvable<StreamFactoryInterface> $factory
81
- * @param Resolvable<string> $uri
82
- * @param Resolvable<RequestFactory> $requestFactory
83
+ * @param Resolvable<string> $uri
84
+ * @param Resolvable<RequestFactory> $requestFactory
83
85
*/
84
86
public function __construct (
85
- Resolvable $ factory ,
86
- HttpConnectionPool $ manager ,
87
- SessionConfiguration $ config ,
88
- FormatterInterface $ formatter ,
89
- Resolvable $ requestFactory ,
90
- Resolvable $ uri ,
87
+ Resolvable $ factory ,
88
+ HttpConnectionPool $ manager ,
89
+ SessionConfiguration $ config ,
90
+ FormatterInterface $ formatter ,
91
+ Resolvable $ requestFactory ,
92
+ Resolvable $ uri ,
91
93
AuthenticateInterface $ auth ,
92
- string $ userAgent
93
- ) {
94
+ string $ userAgent
95
+ )
96
+ {
94
97
$ this ->streamFactory = $ factory ;
95
98
$ this ->config = $ config ;
96
99
$ this ->pool = $ manager ;
@@ -131,7 +134,7 @@ public function openTransaction(iterable $statements = null, ?TransactionConfigu
131
134
132
135
public function writeTransaction (callable $ tsxHandler , ?TransactionConfiguration $ config = null )
133
136
{
134
- return TransactionHelper::retry (fn () => $ this ->openTransaction (), $ tsxHandler );
137
+ return TransactionHelper::retry (fn () => $ this ->openTransaction (), $ tsxHandler );
135
138
}
136
139
137
140
public function readTransaction (callable $ tsxHandler , ?TransactionConfiguration $ config = null )
@@ -171,11 +174,21 @@ public function beginTransaction(?iterable $statements = null, ?TransactionConfi
171
174
{
172
175
$ request = $ this ->requestFactory ->resolve ()->createRequest ('POST ' , $ this ->uri ->resolve ());
173
176
$ connection = $ this ->pool ->acquire ($ request ->getUri (), $ this ->auth , $ this ->config );
177
+
178
+ $ request = $ this ->formatter ->decorateRequest ($ request , $ connection );
174
179
$ request ->getBody ()->write (HttpHelper::statementsToJson ($ connection , $ this ->formatter , $ statements ?? []));
175
180
$ response = $ connection ->getImplementation ()->sendRequest ($ request );
176
181
177
- /** @var string */
178
- $ url = HttpHelper::interpretResponse ($ response )->commit ;
182
+ $ response = HttpHelper::interpretResponse ($ response );
183
+ /** @var stdClass|null $info */
184
+ $ info = $ response ->info ;
185
+ if (is_object ($ info )) {
186
+ /** @var string */
187
+ $ url = $ info ->commit ;
188
+ } else {
189
+ /** @var string */
190
+ $ url = $ response ->commit ;
191
+ }
179
192
$ path = str_replace ('/commit ' , '' , parse_url ($ url , PHP_URL_PATH ));
180
193
$ uri = $ request ->getUri ()->withPath ($ path );
181
194
$ request = $ request ->withUri ($ uri );
@@ -200,7 +213,7 @@ private function makeTransaction(ConnectionInterface $connection, RequestInterfa
200
213
201
214
private function instantCommitRequest (RequestInterface $ request ): RequestInterface
202
215
{
203
- $ path = $ request ->getUri ()->getPath (). '/commit ' ;
216
+ $ path = $ request ->getUri ()->getPath () . '/commit ' ;
204
217
$ uri = $ request ->getUri ()->withPath ($ path );
205
218
206
219
return $ request ->withUri ($ uri );
0 commit comments