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{
46
46
*/
47
47
final class VersionDiscovery
48
48
{
49
+ private RequestFactory $ requestFactory ;
50
+ private ClientInterface $ client ;
51
+
52
+ public function __construct (RequestFactory $ requestFactory , ClientInterface $ client )
53
+ {
54
+ $ this ->requestFactory = $ requestFactory ;
55
+ $ this ->client = $ client ;
56
+ }
57
+
49
58
/**
50
59
* @throws ClientExceptionInterface
51
60
* @throws JsonException
52
61
*/
53
- public function discoverTransactionUrl (string $ url , HttpInjections $ injections ): string
62
+ public function discoverTransactionUrl (RequestData $ data , string $ database ): string
54
63
{
55
- $ discovery = $ this ->discovery ($ injections -> client (), $ injections -> requestFactory (), $ url );
64
+ $ discovery = $ this ->discovery ($ data );
56
65
$ version = $ discovery ['neo4j_version ' ] ?? null ;
57
66
58
67
if ($ version === null ) {
59
- $ discovery = $ this ->discovery ($ injections -> client (), $ injections -> requestFactory (), $ url .'/db/data ' );
68
+ $ discovery = $ this ->discovery ($ data -> withEndpoint ( $ discovery [ ' data ' ] ?? $ data -> getEndpoint () .'/db/data ' ) );
60
69
}
61
70
$ tsx = $ discovery ['transaction ' ];
62
71
63
- return str_replace ('{databaseName} ' , $ injections -> database () , $ tsx );
72
+ return str_replace ('{databaseName} ' , $ database , $ tsx );
64
73
}
65
74
66
75
/**
@@ -69,9 +78,9 @@ public function discoverTransactionUrl(string $url, HttpInjections $injections):
69
78
*
70
79
* @return DiscoveryResult|DiscoveryResultLegacy $discovery
71
80
*/
72
- private function discovery (ClientInterface $ client , RequestFactoryInterface $ factory , string $ uri ): array
81
+ private function discovery (RequestData $ data ): array
73
82
{
74
- $ response = $ client ->sendRequest ($ factory -> createRequest ('GET ' , $ uri ));
83
+ $ response = $ this -> client ->sendRequest ($ this -> requestFactory -> createRequest ($ data , 'GET ' ));
75
84
76
85
/** @var DiscoveryResultLegacy|DiscoveryResult $result */
77
86
$ result = json_decode ($ response ->getBody ()->getContents (), true , 512 , JSON_THROW_ON_ERROR );
0 commit comments