@@ -28,6 +28,11 @@ public function __construct($config = null)
2828 $ this ->config = $ config ;
2929 }
3030
31+ if ($ config instanceof Connection) {
32+ $ this ->config = Config::instance ();
33+ $ this ->setDefaultConnection ('default ' , $ config );
34+ }
35+
3136 if (is_array ($ config )) {
3237 $ this ->config = Config::instance ($ config );
3338 }
@@ -80,13 +85,13 @@ public function query($connection = null): WmiQueryFactory
8085 public function addConnection (string $ name , $ connection ): self
8186 {
8287 if ($ connection instanceof Connection) {
83- $ this ->config ->addConnection ($ name , $ connection );
88+ $ this ->getConfig () ->addConnection ($ name , $ connection );
8489
8590 return $ this ;
8691 }
8792
8893 if (is_array ($ connection )) {
89- $ this ->config ->addConnection ($ name , new Connection (
94+ $ this ->getConfig () ->addConnection ($ name , new Connection (
9095 $ connection ['server ' ] ?? Connection::DEFAULT_SERVER ,
9196 $ connection ['namespace ' ] ?? Connection::DEFAULT_NAMESPACE ,
9297 $ connection ['user ' ] ?? null ,
@@ -116,8 +121,26 @@ public function setDefaultConnection(string $name, $connection = null): self
116121 $ this ->addConnection ($ name , $ connection );
117122 }
118123
119- $ this ->config ->setDefaultConnection ($ name );
124+ $ this ->getConfig () ->setDefaultConnection ($ name );
120125
121126 return $ this ;
122127 }
128+
129+ /**
130+ * @param string|null $name
131+ *
132+ * @return Connection|null
133+ */
134+ public function getConnection (string $ name = null )
135+ {
136+ return $ this ->getConfig ()->getConnection ($ name );
137+ }
138+
139+ /**
140+ * @return Connection|null
141+ */
142+ public function getDefaultConnection ()
143+ {
144+ return $ this ->getConnection ();
145+ }
123146}
0 commit comments