14
14
namespace Laudis \Neo4j \Network ;
15
15
16
16
use JsonException ;
17
- use Laudis \Neo4j \Network \Http \HttpInjections ;
17
+ use Laudis \Neo4j \Databags \RequestData ;
18
+ use Laudis \Neo4j \HttpDriver \RequestFactory ;
18
19
use Psr \Http \Client \ClientExceptionInterface ;
19
20
use Psr \Http \Client \ClientInterface ;
20
- use Psr \Http \Message \RequestFactoryInterface ;
21
21
22
22
/**
23
23
* @psalm-type DiscoveryResult = array{
24
24
* bolt_routing:string,
25
25
* transaction: string,
26
26
* bolt_direct: string,
27
27
* neo4j_version: string,
28
- * neo4j_edition: string
28
+ * neo4j_edition: string,
29
+ * data?: string
29
30
* }
30
31
* @psalm-type DiscoveryResultLegacy = array{
31
32
* extensions: array,
46
47
*/
47
48
final class VersionDiscovery
48
49
{
50
+ private RequestFactory $ requestFactory ;
51
+ private ClientInterface $ client ;
52
+
53
+ public function __construct (RequestFactory $ requestFactory , ClientInterface $ client )
54
+ {
55
+ $ this ->requestFactory = $ requestFactory ;
56
+ $ this ->client = $ client ;
57
+ }
58
+
49
59
/**
50
60
* @throws ClientExceptionInterface
51
61
* @throws JsonException
52
62
*/
53
- public function discoverTransactionUrl (string $ url , HttpInjections $ injections ): string
63
+ public function discoverTransactionUrl (RequestData $ data , string $ database ): string
54
64
{
55
- $ discovery = $ this ->discovery ($ injections -> client (), $ injections -> requestFactory (), $ url );
65
+ $ discovery = $ this ->discovery ($ data );
56
66
$ version = $ discovery ['neo4j_version ' ] ?? null ;
57
67
58
68
if ($ version === null ) {
59
- $ discovery = $ this ->discovery ($ injections -> client (), $ injections -> requestFactory (), $ url .'/db/data ' );
69
+ $ discovery = $ this ->discovery ($ data -> withEndpoint ( $ discovery [ ' data ' ] ?? $ data -> getEndpoint () .'/db/data ' ) );
60
70
}
61
71
$ tsx = $ discovery ['transaction ' ];
62
72
63
- return str_replace ('{databaseName} ' , $ injections -> database () , $ tsx );
73
+ return str_replace ('{databaseName} ' , $ database , $ tsx );
64
74
}
65
75
66
76
/**
@@ -69,9 +79,9 @@ public function discoverTransactionUrl(string $url, HttpInjections $injections):
69
79
*
70
80
* @return DiscoveryResult|DiscoveryResultLegacy $discovery
71
81
*/
72
- private function discovery (ClientInterface $ client , RequestFactoryInterface $ factory , string $ uri ): array
82
+ private function discovery (RequestData $ data ): array
73
83
{
74
- $ response = $ client ->sendRequest ($ factory -> createRequest ('GET ' , $ uri ));
84
+ $ response = $ this -> client ->sendRequest ($ this -> requestFactory -> createRequest ($ data , 'GET ' ));
75
85
76
86
/** @var DiscoveryResultLegacy|DiscoveryResult $result */
77
87
$ result = json_decode ($ response ->getBody ()->getContents (), true , 512 , JSON_THROW_ON_ERROR );
0 commit comments