13
13
14
14
namespace Laudis \Neo4j \Authentication ;
15
15
16
- use Bolt \protocol \V4_4 ;
17
- use Bolt \protocol \V5 ;
18
- use Bolt \protocol \V5_1 ;
19
- use Bolt \protocol \V5_2 ;
20
- use Bolt \protocol \V5_3 ;
21
- use Bolt \protocol \V5_4 ;
22
16
use Exception ;
17
+ use Laudis \Neo4j \Bolt \BoltConnection ;
23
18
use Laudis \Neo4j \Bolt \BoltMessageFactory ;
24
19
use Laudis \Neo4j \Common \Neo4jLogger ;
25
- use Laudis \Neo4j \Common \ResponseHelper ;
26
20
use Laudis \Neo4j \Contracts \AuthenticateInterface ;
27
21
use Psr \Http \Message \UriInterface ;
28
22
@@ -43,27 +37,26 @@ public function __construct(
43
37
*
44
38
* @return array{server: string, connection_id: string, hints: list}
45
39
*/
46
- public function authenticateBolt (V4_4 | V5 | V5_1 | V5_2 | V5_3 | V5_4 $ protocol , string $ userAgent ): array
40
+ public function authenticateBolt (BoltConnection $ connection , string $ userAgent ): array
47
41
{
48
- $ factory = $ this ->createMessageFactory ($ protocol );
42
+ $ factory = $ this ->createMessageFactory ($ connection );
49
43
44
+ $ protocol = $ connection ->protocol ();
50
45
if (method_exists ($ protocol , 'logon ' )) {
51
46
$ helloMetadata = ['user_agent ' => $ userAgent ];
52
47
53
- $ factory ->createHelloMessage ($ helloMetadata )->send ();
54
- $ response = ResponseHelper::getResponse ($ protocol );
48
+ $ responseHello = $ factory ->createHelloMessage ($ helloMetadata )->send ()->getResponse ();
55
49
56
50
$ credentials = [
57
51
'scheme ' => 'basic ' ,
58
52
'principal ' => $ this ->username ,
59
53
'credentials ' => $ this ->password ,
60
54
];
61
55
62
- $ factory ->createLogonMessage ($ credentials )->send ();
63
- ResponseHelper::getResponse ($ protocol );
56
+ $ response = $ factory ->createLogonMessage ($ credentials )->send ()->getResponse ();
64
57
65
58
/** @var array{server: string, connection_id: string, hints: list} */
66
- return $ response ->content ;
59
+ return array_merge ( $ responseHello -> content , $ response ->content ) ;
67
60
}
68
61
69
62
$ helloMetadata = [
@@ -73,22 +66,15 @@ public function authenticateBolt(V4_4|V5|V5_1|V5_2|V5_3|V5_4 $protocol, string $
73
66
'credentials ' => $ this ->password ,
74
67
];
75
68
76
- $ factory ->createHelloMessage ($ helloMetadata )->send ();
69
+ $ response = $ factory ->createHelloMessage ($ helloMetadata )->send ()-> getResponse ();
77
70
78
71
/** @var array{server: string, connection_id: string, hints: list} */
79
- return ResponseHelper:: getResponse ( $ protocol ) ->content ;
72
+ return $ response ->content ;
80
73
}
81
74
82
75
/**
83
76
* @throws Exception
84
77
*/
85
- public function logoff (V4_4 |V5 |V5_1 |V5_2 |V5_3 |V5_4 $ protocol ): void
86
- {
87
- $ factory = $ this ->createMessageFactory ($ protocol );
88
- $ factory ->createLogoffMessage ()->send ();
89
- ResponseHelper::getResponse ($ protocol );
90
- }
91
-
92
78
public function toString (UriInterface $ uri ): string
93
79
{
94
80
return sprintf ('Basic %s:%s@%s:%s ' , $ this ->username , '###### ' , $ uri ->getHost (), $ uri ->getPort () ?? '' );
@@ -97,8 +83,8 @@ public function toString(UriInterface $uri): string
97
83
/**
98
84
* Helper to create message factory.
99
85
*/
100
- private function createMessageFactory (V4_4 | V5 | V5_1 | V5_2 | V5_3 | V5_4 $ protocol ): BoltMessageFactory
86
+ private function createMessageFactory (BoltConnection $ connection ): BoltMessageFactory
101
87
{
102
- return new BoltMessageFactory ($ protocol , $ this ->logger );
88
+ return new BoltMessageFactory ($ connection , $ this ->logger );
103
89
}
104
90
}
0 commit comments