@@ -43,44 +43,34 @@ class ArangoClient
4343 * @throws UnknownProperties
4444 */
4545 public function __construct (array $ config = [], ?GuzzleClient $ httpClient = null )
46+ {
47+ $ this ->connect ($ config , $ httpClient );
48+ }
49+
50+ /**
51+ * ArangoClient constructor.
52+ *
53+ * @param array<string|numeric|null> $config
54+ * @param GuzzleClient|null $httpClient
55+ *
56+ * @throws UnknownProperties
57+ */
58+ public function connect (array $ config = [], ?GuzzleClient $ httpClient = null ): void
4659 {
4760 $ config ['endpoint ' ] = $ this ->generateEndpoint ($ config );
4861 $ this ->config = new HttpClientConfig ($ config );
4962
5063 $ this ->httpClient = $ httpClient ?? new GuzzleClient ($ this ->config ->mapGuzzleHttpClientConfig ());
5164 }
5265
53- public function __destruct ()
54- {
55- $ this -> disconnect ();
56- }
57-
66+ /**
67+ * We disconnect by creating a new guzzle client. The old client will remove the current connection upon destruction.
68+ *
69+ * @return bool
70+ */
5871 public function disconnect (): bool
5972 {
60- $ config = $ this ->getConfig ();
61-
62- if ($ config ['connection ' ] !== 'Keep-Alive ' ) {
63- return true ;
64- }
65-
66- $ response = $ this ->rawRequest (
67- 'HEAD ' ,
68- '/_api/version ' ,
69- [
70- 'headers ' => [
71- 'Connection ' => 'close ' ,
72- ],
73- ],
74- );
75-
76- if ($ response === null ) {
77- return false ;
78- }
79-
80- $ connection = $ response ->getHeader ('Connection ' );
81- if (reset ($ connection ) !== 'Close ' ) {
82- return false ;
83- }
73+ $ this ->httpClient = new GuzzleClient ($ this ->config ->mapGuzzleHttpClientConfig ());
8474
8575 return true ;
8676 }
0 commit comments