@@ -111,57 +111,40 @@ public function createSession(?SessionConfiguration $config = null): SessionInte
111
111
$ config = $ config ->merge (SessionConfiguration::fromUri ($ this ->uri ));
112
112
$ streamFactoryResolve = $ this ->streamFactory ();
113
113
114
+ $ tsxUrl = $ this ->tsxUrl ($ config );
115
+
114
116
return new HttpSession (
115
117
$ streamFactoryResolve ,
116
- $ this ->getHttpConnectionPool (),
118
+ $ this ->getHttpConnectionPool ($ tsxUrl ),
117
119
$ config ,
118
120
$ this ->formatter ,
119
121
$ factory ,
120
- Resolvable::once ($ this ->key .':tsxUrl ' , function () use ($ config , $ factory ) {
121
- $ database = $ config ->getDatabase () ?? 'neo4j ' ;
122
- $ request = $ factory ->resolve ()->createRequest ('GET ' , $ this ->uri );
123
- $ client = $ this ->config ->getHttpPsrBindings ()->getClient ();
124
-
125
- $ response = $ client ->sendRequest ($ request );
126
-
127
- $ discovery = HttpHelper::interpretResponse ($ response );
128
- /** @var string|null */
129
- $ version = $ discovery ->neo4j_version ?? null ;
130
-
131
- if ($ version === null ) {
132
- /** @var string */
133
- $ uri = $ discovery ->data ;
134
- $ request = $ request ->withUri (Uri::create ($ uri ));
135
- $ discovery = HttpHelper::interpretResponse ($ client ->sendRequest ($ request ));
136
- }
137
-
138
- /** @var string */
139
- $ tsx = $ discovery ->transaction ;
140
-
141
- return str_replace ('{databaseName} ' , $ database , $ tsx );
142
- }),
122
+ $ tsxUrl ,
143
123
$ this ->auth ,
144
124
$ this ->config ->getUserAgent ()
145
125
);
146
126
}
147
127
148
128
public function verifyConnectivity (?SessionConfiguration $ config = null ): bool
149
129
{
150
- return $ this ->getHttpConnectionPool ()->canConnect ($ this ->uri , $ this ->auth );
130
+ return $ this ->getHttpConnectionPool ($ this ->tsxUrl ($ config ?? SessionConfiguration::default ()))
131
+ ->canConnect ($ this ->uri , $ this ->auth );
151
132
}
152
133
153
134
/**
135
+ * @param Resolvable<string> $tsxUrl
136
+ *
154
137
* @psalm-mutation-free
155
138
*/
156
- private function getHttpConnectionPool (): HttpConnectionPool
139
+ private function getHttpConnectionPool (Resolvable $ tsxUrl ): HttpConnectionPool
157
140
{
158
141
return new HttpConnectionPool (
159
142
Resolvable::once ($ this ->key .':client ' , fn () => $ this ->config ->getHttpPsrBindings ()->getClient ()),
160
143
$ this ->resolvableFactory (),
161
144
$ this ->streamFactory (),
162
- $ this ->uri ,
163
145
$ this ->auth ,
164
- $ this ->config ->getUserAgent ()
146
+ $ this ->config ->getUserAgent (),
147
+ $ tsxUrl
165
148
);
166
149
}
167
150
@@ -188,4 +171,36 @@ private function streamFactory(): Resolvable
188
171
{
189
172
return Resolvable::once ($ this ->key .':streamFactory ' , fn () => $ this ->config ->getHttpPsrBindings ()->getStreamFactory ());
190
173
}
174
+
175
+ /**
176
+ * @return Resolvable<string>
177
+ *
178
+ * @psalm-mutation-free
179
+ */
180
+ private function tsxUrl (SessionConfiguration $ config ): Resolvable
181
+ {
182
+ return Resolvable::once ($ this ->key .':tsxUrl ' , function () use ($ config ) {
183
+ $ database = $ config ->getDatabase () ?? 'neo4j ' ;
184
+ $ request = $ this ->resolvableFactory ()->resolve ()->createRequest ('GET ' , $ this ->uri );
185
+ $ client = $ this ->config ->getHttpPsrBindings ()->getClient ();
186
+
187
+ $ response = $ client ->sendRequest ($ request );
188
+
189
+ $ discovery = HttpHelper::interpretResponse ($ response );
190
+ /** @var string|null */
191
+ $ version = $ discovery ->neo4j_version ?? null ;
192
+
193
+ if ($ version === null ) {
194
+ /** @var string */
195
+ $ uri = $ discovery ->data ;
196
+ $ request = $ request ->withUri (Uri::create ($ uri ));
197
+ $ discovery = HttpHelper::interpretResponse ($ client ->sendRequest ($ request ));
198
+ }
199
+
200
+ /** @var string */
201
+ $ tsx = $ discovery ->transaction ;
202
+
203
+ return str_replace ('{databaseName} ' , $ database , $ tsx );
204
+ });
205
+ }
191
206
}
0 commit comments