@@ -59,10 +59,17 @@ public function __construct($config = 'influxdb:')
5959 if (empty ($ config )) {
6060 $ config = [];
6161 } elseif (is_string ($ config )) {
62- $ config = $ this -> parseDsn ($ config );
62+ $ config = self :: parseDsn ($ config );
6363 } elseif (is_array ($ config )) {
64- $ config = empty ($ config ['dsn ' ]) ? $ config : $ this -> parseDsn ($ config ['dsn ' ]);
64+ $ config = empty ($ config ['dsn ' ]) ? $ config : self :: parseDsn ($ config ['dsn ' ]);
6565 } elseif ($ config instanceof Client) {
66+ // Passing Client instead of array config is deprecated because it prevents setting any configuration values
67+ // and causes library to use defaults.
68+ @trigger_error (
69+ sprintf ('Passing %s as %s argument is deprecated. Pass it as "client" array property or use createWithClient instead ' ,
70+ Client::class,
71+ __METHOD__
72+ ), E_USER_DEPRECATED );
6673 $ this ->client = $ config ;
6774 $ config = [];
6875 } else {
@@ -97,6 +104,22 @@ public function __construct($config = 'influxdb:')
97104 $ this ->config = $ config ;
98105 }
99106
107+ /**
108+ * @param Client $client
109+ * @param string $config
110+ *
111+ * @return InfluxDbStorage
112+ */
113+ public static function createWithClient (Client $ client , $ config = 'influxdb: ' ): self
114+ {
115+ if (is_string ($ config )) {
116+ $ config = self ::parseDsn ($ config );
117+ }
118+ $ config ['client ' ] = $ client ;
119+
120+ return new static ($ config );
121+ }
122+
100123 public function pushConsumerStats (ConsumerStats $ stats ): void
101124 {
102125 $ points = [];
@@ -221,7 +244,7 @@ private function getDb(): Database
221244 return $ this ->database ;
222245 }
223246
224- private function parseDsn (string $ dsn ): array
247+ private static function parseDsn (string $ dsn ): array
225248 {
226249 $ dsn = Dsn::parseFirst ($ dsn );
227250
0 commit comments