24
24
use Laudis \Neo4j \Databags \DriverConfiguration ;
25
25
use Laudis \Neo4j \Databags \DriverSetup ;
26
26
use Laudis \Neo4j \Databags \HttpPsrBindings ;
27
+ use Laudis \Neo4j \Databags \SessionConfiguration ;
27
28
use Laudis \Neo4j \Databags \TransactionConfiguration ;
28
29
use Laudis \Neo4j \Exception \UnsupportedScheme ;
29
30
use Laudis \Neo4j \Formatter \OGMFormatter ;
@@ -49,7 +50,11 @@ final class ClientBuilder
49
50
*/
50
51
private CypherMap $ driverConfigurations ;
51
52
/** @psalm-readonly */
52
- private DriverConfiguration $ configuration ;
53
+ private DriverConfiguration $ defaultDriverConfig ;
54
+ /** @psalm-readonly */
55
+ private TransactionConfiguration $ defaultTransactionConfig ;
56
+ /** @psalm-readonly */
57
+ private SessionConfiguration $ defaultSessionConfig ;
53
58
/** @psalm-readonly */
54
59
private ?string $ defaultDriver ;
55
60
/** @psalm-readonly */
@@ -61,22 +66,33 @@ final class ClientBuilder
61
66
* @param CypherMap<DriverSetup> $driverConfigurations
62
67
* @param FormatterInterface<T> $formatter
63
68
*/
64
- public function __construct (DriverConfiguration $ configuration , FormatterInterface $ formatter , CypherMap $ driverConfigurations , ?string $ defaultDriver )
69
+ public function __construct (DriverConfiguration $ configuration , SessionConfiguration $ sessionConfiguration , TransactionConfiguration $ transactionConfiguration , FormatterInterface $ formatter , CypherMap $ driverConfigurations , ?string $ defaultDriver )
65
70
{
66
71
$ this ->driverConfigurations = $ driverConfigurations ;
67
- $ this ->configuration = $ configuration ;
72
+ $ this ->defaultDriverConfig = $ configuration ;
68
73
$ this ->defaultDriver = $ defaultDriver ;
69
74
$ this ->formatter = $ formatter ;
75
+ $ this ->defaultSessionConfig = $ sessionConfiguration ;
76
+ $ this ->defaultTransactionConfig = $ transactionConfiguration ;
70
77
}
71
78
72
79
/**
80
+ * Creates a client builder with default configurations and an OGMFormatter.
81
+ *
73
82
* @pure
74
83
*
75
84
* @return ClientBuilder<CypherList<CypherMap<OGMTypes>>>
76
85
*/
77
86
public static function create (): ClientBuilder
78
87
{
79
- return new self (DriverConfiguration::default (), OGMFormatter::create (), new CypherMap (), null );
88
+ return new self (
89
+ DriverConfiguration::default (),
90
+ SessionConfiguration::default (),
91
+ TransactionConfiguration::default (),
92
+ OGMFormatter::create (),
93
+ new CypherMap (),
94
+ null
95
+ );
80
96
}
81
97
82
98
/**
@@ -108,7 +124,14 @@ private function withParsedUrl(string $alias, Uri $uri, AuthenticateInterface $a
108
124
$ setup = new DriverSetup ($ uri , $ authentication , $ socketTimeout );
109
125
$ configs = new CypherMap (array_merge ($ this ->driverConfigurations ->toArray (), [$ alias => $ setup ]));
110
126
111
- return new self ($ this ->configuration , $ this ->formatter , $ configs , $ this ->defaultDriver );
127
+ return new self (
128
+ $ this ->defaultDriverConfig ,
129
+ $ this ->defaultSessionConfig ,
130
+ $ this ->defaultTransactionConfig ,
131
+ $ this ->formatter ,
132
+ $ configs ,
133
+ $ this ->defaultDriver
134
+ );
112
135
}
113
136
114
137
/**
@@ -173,7 +196,9 @@ public function addHttpConnection(string $alias, string $url, HttpConfig $config
173
196
$ uri = $ uri ->withPort ($ uri ->getPort () === 7687 ? 7474 : $ uri ->getPort ());
174
197
175
198
$ self = new self (
176
- $ this ->configuration ->withHttpPsrBindings ($ bindings ),
199
+ $ this ->defaultDriverConfig ->withHttpPsrBindings ($ bindings ),
200
+ $ this ->defaultSessionConfig ,
201
+ $ this ->defaultTransactionConfig ,
177
202
$ this ->formatter ,
178
203
$ this ->driverConfigurations ,
179
204
$ this ->defaultDriver
@@ -204,7 +229,14 @@ public function setDefaultConnection(string $alias): self
204
229
*/
205
230
public function withDefaultDriver (string $ alias ): self
206
231
{
207
- return new self ($ this ->configuration , $ this ->formatter , $ this ->driverConfigurations , $ alias );
232
+ return new self (
233
+ $ this ->defaultDriverConfig ,
234
+ $ this ->defaultSessionConfig ,
235
+ $ this ->defaultTransactionConfig ,
236
+ $ this ->formatter ,
237
+ $ this ->driverConfigurations ,
238
+ $ alias
239
+ );
208
240
}
209
241
210
242
/**
@@ -217,7 +249,14 @@ public function withDefaultDriver(string $alias): self
217
249
*/
218
250
public function withFormatter (FormatterInterface $ formatter ): self
219
251
{
220
- return new self ($ this ->configuration , $ formatter , $ this ->driverConfigurations , $ this ->defaultDriver );
252
+ return new self (
253
+ $ this ->defaultDriverConfig ,
254
+ $ this ->defaultSessionConfig ,
255
+ $ this ->defaultTransactionConfig ,
256
+ $ formatter ,
257
+ $ this ->driverConfigurations ,
258
+ $ this ->defaultDriver
259
+ );
221
260
}
222
261
223
262
/**
@@ -227,16 +266,84 @@ public function withFormatter(FormatterInterface $formatter): self
227
266
*/
228
267
public function build (): ClientInterface
229
268
{
230
- return new Client ($ this ->driverConfigurations , $ this ->configuration , $ this ->formatter , $ this ->defaultDriver );
269
+ return new Client (
270
+ $ this ->driverConfigurations ,
271
+ $ this ->defaultDriverConfig ,
272
+ $ this ->defaultSessionConfig ,
273
+ $ this ->defaultTransactionConfig ,
274
+ $ this ->formatter ,
275
+ $ this ->defaultDriver
276
+ );
231
277
}
232
278
233
279
/**
280
+ * @deprecated
281
+ * @see self::withDefaultDriverConfiguration
282
+ *
234
283
* @psalm-mutation-free
235
284
*/
236
285
public function withHttpPsrBindings (HttpPsrBindings $ bindings ): self
237
286
{
238
- $ config = $ this ->configuration ->withHttpPsrBindings ($ bindings );
287
+ $ config = $ this ->defaultDriverConfig ->withHttpPsrBindings ($ bindings );
239
288
240
- return new self ($ config , $ this ->formatter , $ this ->driverConfigurations , $ this ->defaultDriver );
289
+ return new self (
290
+ $ config ,
291
+ $ this ->defaultSessionConfig ,
292
+ $ this ->defaultTransactionConfig ,
293
+ $ this ->formatter ,
294
+ $ this ->driverConfigurations ,
295
+ $ this ->defaultDriver
296
+ );
297
+ }
298
+
299
+ /**
300
+ * @return self<T>
301
+ *
302
+ * @psalm-mutation-free
303
+ */
304
+ public function withDefaultDriverConfiguration (DriverConfiguration $ config ): self
305
+ {
306
+ return new self (
307
+ $ config ,
308
+ $ this ->defaultSessionConfig ,
309
+ $ this ->defaultTransactionConfig ,
310
+ $ this ->formatter ,
311
+ $ this ->driverConfigurations ,
312
+ $ this ->defaultDriver
313
+ );
314
+ }
315
+
316
+ /**
317
+ * @return self<T>
318
+ *
319
+ * @psalm-mutation-free
320
+ */
321
+ public function withDefaultSessionConfiguration (SessionConfiguration $ config ): self
322
+ {
323
+ return new self (
324
+ $ this ->defaultDriverConfig ,
325
+ $ config ,
326
+ $ this ->defaultTransactionConfig ,
327
+ $ this ->formatter ,
328
+ $ this ->driverConfigurations ,
329
+ $ this ->defaultDriver
330
+ );
331
+ }
332
+
333
+ /**
334
+ * @return self<T>
335
+ *
336
+ * @psalm-mutation-free
337
+ */
338
+ public function withDefaultTransactionConfiguration (TransactionConfiguration $ config ): self
339
+ {
340
+ return new self (
341
+ $ this ->defaultDriverConfig ,
342
+ $ this ->defaultSessionConfig ,
343
+ $ config ,
344
+ $ this ->formatter ,
345
+ $ this ->driverConfigurations ,
346
+ $ this ->defaultDriver
347
+ );
241
348
}
242
349
}
0 commit comments