1919use function is_string ;
2020
2121use Laudis \Neo4j \Authentication \Authenticate ;
22+ use Laudis \Neo4j \Bolt \BoltConnection ;
2223use Laudis \Neo4j \Bolt \Session ;
2324use Laudis \Neo4j \Common \DNSAddressResolver ;
2425use Laudis \Neo4j \Common \GeneratorHelper ;
2829use Laudis \Neo4j \Contracts \DriverInterface ;
2930use Laudis \Neo4j \Contracts \SessionInterface ;
3031use Laudis \Neo4j \Databags \DriverConfiguration ;
32+ use Laudis \Neo4j \Databags \ServerInfo ;
3133use Laudis \Neo4j \Databags \SessionConfiguration ;
34+ use Laudis \Neo4j \Enum \AccessMode ;
3235use Laudis \Neo4j \Formatter \SummarizedResultFormatter ;
3336use Psr \Http \Message \UriInterface ;
3437use Psr \Log \LogLevel ;
@@ -75,6 +78,8 @@ public static function create(string|UriInterface $uri, ?DriverConfiguration $co
7578 /**
7679 * @psalm-mutation-free
7780 *
81+ * @psalm-suppress UnnecessaryVarAnnotation
82+ *
7883 * @throws Exception
7984 */
8085 public function createSession (?SessionConfiguration $ config = null ): SessionInterface
@@ -99,6 +104,39 @@ public function verifyConnectivity(?SessionConfiguration $config = null): bool
99104 return true ;
100105 }
101106
107+ /**
108+ * Gets server information without running a query.
109+ *
110+ * Acquires a connection from the pool and extracts server metadata.
111+ * The pool handles all connection management, routing, and retries.
112+ *
113+ * @throws Exception if unable to acquire a connection
114+ */
115+ public function getServerInfo (?SessionConfiguration $ config = null ): ServerInfo
116+ {
117+ $ config ??= SessionConfiguration::default ()->withAccessMode (AccessMode::READ ());
118+
119+ $ this ->pool ->refreshRoutingTable ($ config );
120+
121+ $ connectionGenerator = $ this ->pool ->acquire ($ config );
122+ /**
123+ * @var BoltConnection $connection
124+ *
125+ * @psalm-suppress UnnecessaryVarAnnotation
126+ */
127+ $ connection = GeneratorHelper::getReturnFromGenerator ($ connectionGenerator );
128+
129+ try {
130+ return new ServerInfo (
131+ $ connection ->getServerAddress (),
132+ $ connection ->getProtocol (),
133+ $ connection ->getServerAgent ()
134+ );
135+ } finally {
136+ $ this ->pool ->release ($ connection );
137+ }
138+ }
139+
102140 public function closeConnections (): void
103141 {
104142 $ this ->pool ->close ();
0 commit comments