@@ -74,6 +74,12 @@ class Config extends BaseConfig
7474 */
7575 public static function connect ($ group = null , bool $ getShared = true )
7676 {
77+ // If a DB connection is passed in, just pass it back
78+ if ($ group instanceof BaseConnection)
79+ {
80+ return $ group ;
81+ }
82+
7783 if (is_array ($ group ))
7884 {
7985 $ config = $ group ;
@@ -135,44 +141,7 @@ public static function getConnections()
135141 */
136142 public static function forge ($ group = null )
137143 {
138- // Allow custom connections to be sent in
139- if (is_array ($ group ))
140- {
141- $ config = $ group ;
142- $ group = 'custom- ' . md5 (json_encode ($ config ));
143- }
144- else
145- {
146- $ config = config ('Database ' );
147- }
148-
149- static ::ensureFactory ();
150-
151- if (empty ($ group ))
152- {
153- $ group = ENVIRONMENT === 'testing ' ? 'tests ' : $ config ->defaultGroup ;
154- }
155-
156- if (is_string ($ group ) && ! isset ($ config ->$ group ) && ! is_array ($ config ))
157- {
158- throw new \InvalidArgumentException ($ group . ' is not a valid database connection group. ' );
159- }
160-
161- if (! isset (static ::$ instances [$ group ]))
162- {
163- if (is_array ($ config ))
164- {
165- $ db = static ::connect ($ config );
166- }
167- else
168- {
169- $ db = static ::connect ($ group );
170- }
171- }
172- else
173- {
174- $ db = static ::$ instances [$ group ];
175- }
144+ $ db = static ::connect ($ group );
176145
177146 return static ::$ factory ->loadForge ($ db );
178147 }
@@ -182,50 +151,13 @@ public static function forge($group = null)
182151 /**
183152 * Returns a new instance of the Database Utilities class.
184153 *
185- * @param string|null $group
154+ * @param string|array| null $group
186155 *
187156 * @return BaseUtils
188157 */
189- public static function utils (string $ group = null )
158+ public static function utils ($ group = null )
190159 {
191- // Allow custom connections to be sent in
192- if (is_array ($ group ))
193- {
194- $ config = $ group ;
195- $ group = 'custom- ' . md5 (json_encode ($ config ));
196- }
197- else
198- {
199- $ config = config ('Database ' );
200- }
201-
202- static ::ensureFactory ();
203-
204- if (empty ($ group ))
205- {
206- $ group = ENVIRONMENT === 'testing ' ? 'tests ' : $ config ->defaultGroup ;
207- }
208-
209- if (is_string ($ group ) && ! isset ($ config ->$ group ) && ! is_array ($ config ))
210- {
211- throw new \InvalidArgumentException ($ group . ' is not a valid database connection group. ' );
212- }
213-
214- if (! isset (static ::$ instances [$ group ]))
215- {
216- if (is_array ($ config ))
217- {
218- $ db = static ::connect ($ config );
219- }
220- else
221- {
222- $ db = static ::connect ($ group );
223- }
224- }
225- else
226- {
227- $ db = static ::$ instances [$ group ];
228- }
160+ $ db = static ::connect ($ group );
229161
230162 return static ::$ factory ->loadUtils ($ db );
231163 }
@@ -241,7 +173,7 @@ public static function utils(string $group = null)
241173 */
242174 public static function seeder (string $ group = null )
243175 {
244- $ config = new \ Config \ Database ( );
176+ $ config = config ( ' Database ' );
245177
246178 return new Seeder ($ config , static ::connect ($ group ));
247179 }
0 commit comments