1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
/*
4
6
* This file is part of the Neo4j PHP Client and Driver package.
5
7
*
17
19
use Laudis \Neo4j \Contracts \ConnectionInterface ;
18
20
use Laudis \Neo4j \Contracts \ConnectionPoolInterface ;
19
21
use Laudis \Neo4j \Contracts \SemaphoreInterface ;
22
+ use Laudis \Neo4j \Databags \ConnectionRequestData ;
20
23
use Laudis \Neo4j \Databags \SessionConfiguration ;
21
24
use Laudis \Neo4j \Databags \SslConfiguration ;
25
+ use Psr \Http \Message \UriInterface ;
26
+
22
27
use function method_exists ;
23
28
use function microtime ;
24
29
use function shuffle ;
27
32
* @template T
28
33
* @implements ConnectionPoolInterface<T>
29
34
*/
30
- class ConnectionPool implements ConnectionPoolInterface
35
+ final class ConnectionPool implements ConnectionPoolInterface
31
36
{
32
37
private SemaphoreInterface $ semaphore ;
33
38
34
39
/** @var list<ConnectionInterface<T>> */
35
40
private array $ activeConnections = [];
36
- private AuthenticateInterface $ auth ;
37
41
/** @var ConnectionFactoryInterface<T> */
38
42
private ConnectionFactoryInterface $ factory ;
39
- private string $ userAgent ;
40
- private SslConfiguration $ sslConfiguration ;
43
+ private ConnectionRequestData $ data ;
41
44
42
45
/**
43
46
* @param ConnectionFactoryInterface<T> $factory
44
47
*/
45
- public function __construct (AuthenticateInterface $ auth , string $ userAgent , SslConfiguration $ sslConfiguration , SemaphoreInterface $ semaphore , ConnectionFactoryInterface $ factory )
48
+ public function __construct (SemaphoreInterface $ semaphore , ConnectionFactoryInterface $ factory, ConnectionRequestData $ data )
46
49
{
47
50
$ this ->semaphore = $ semaphore ;
48
- $ this ->auth = $ auth ;
49
51
$ this ->factory = $ factory ;
50
- $ this ->userAgent = $ userAgent ;
51
- $ this ->sslConfiguration = $ sslConfiguration ;
52
+ $ this ->data = $ data ;
52
53
}
53
54
54
55
public function acquire (SessionConfiguration $ config ): Generator
@@ -72,7 +73,7 @@ public function acquire(SessionConfiguration $config): Generator
72
73
}
73
74
74
75
return $ this ->returnAnyAvailableConnection ($ config ) ??
75
- $ this ->factory ->createConnection ($ this ->userAgent , $ this -> sslConfiguration , $ config, $ this -> auth );
76
+ $ this ->factory ->createConnection ($ this ->data , $ config );
76
77
}
77
78
78
79
public function release (ConnectionInterface $ connection ): void
@@ -101,7 +102,7 @@ private function returnAnyAvailableConnection(SessionConfiguration $config): ?Co
101
102
foreach ($ this ->activeConnections as $ activeConnection ) {
102
103
// We prefer a connection that is just ready
103
104
if ($ activeConnection ->getServerState () === 'READY ' ) {
104
- if ($ this ->factory ->canReuseConnection ($ activeConnection , $ this ->userAgent , $ this -> sslConfiguration , $ this -> auth )) {
105
+ if ($ this ->factory ->canReuseConnection ($ activeConnection , $ this ->data )) {
105
106
return $ this ->factory ->reuseConnection ($ activeConnection , $ config );
106
107
} else {
107
108
$ requiresReconnectConnection = $ activeConnection ;
@@ -116,7 +117,7 @@ private function returnAnyAvailableConnection(SessionConfiguration $config): ?Co
116
117
// https://github.com/neo4j-php/neo4j-php-client/issues/146
117
118
// NOTE: we cannot work with TX_STREAMING as we cannot force the transaction to implicitly close.
118
119
if ($ streamingConnection === null && $ activeConnection ->getServerState () === 'STREAMING ' ) {
119
- if ($ this ->factory ->canReuseConnection ($ activeConnection , $ this ->userAgent , $ this -> sslConfiguration , $ this -> auth )) {
120
+ if ($ this ->factory ->canReuseConnection ($ activeConnection , $ this ->data )) {
120
121
$ streamingConnection = $ activeConnection ;
121
122
if (method_exists ($ streamingConnection , 'consumeResults ' )) {
122
123
$ streamingConnection ->consumeResults (); // State should now be ready
@@ -134,7 +135,7 @@ private function returnAnyAvailableConnection(SessionConfiguration $config): ?Co
134
135
if ($ requiresReconnectConnection ) {
135
136
$ this ->release ($ requiresReconnectConnection );
136
137
137
- return $ this ->factory ->createConnection ($ this ->userAgent , $ this -> sslConfiguration , $ config, $ this -> auth );
138
+ return $ this ->factory ->createConnection ($ this ->data , $ config );
138
139
}
139
140
140
141
return null ;
0 commit comments