@@ -92,9 +92,7 @@ public function __construct($app, ConnectionFactory $factory)
9292 */
9393 public function connection ($ name = null )
9494 {
95- $ name = enum_value ($ name ) ?: $ this ->getDefaultConnection ();
96-
97- [$ database , $ type ] = $ this ->parseConnectionName ($ name );
95+ [$ database , $ type ] = $ this ->parseConnectionName ($ name = enum_value ($ name ) ?? $ this ->getDefaultConnection ());
9896
9997 // If we haven't created this connection, we'll create it based on the config
10098 // provided in the application. Once we've created the connections we will
@@ -141,15 +139,15 @@ public static function calculateDynamicConnectionName(array $config)
141139 /**
142140 * Get a database connection instance from the given configuration.
143141 *
144- * @param string $name
142+ * @param \UnitEnum| string $name
145143 * @param array $config
146144 * @param bool $force
147145 * @return \Illuminate\Database\ConnectionInterface
148146 */
149147 public function connectUsing (string $ name , array $ config , bool $ force = false )
150148 {
151149 if ($ force ) {
152- $ this ->purge ($ name );
150+ $ this ->purge ($ name = enum_value ( $ name ) );
153151 }
154152
155153 if (isset ($ this ->connections [$ name ])) {
@@ -173,8 +171,6 @@ public function connectUsing(string $name, array $config, bool $force = false)
173171 */
174172 protected function parseConnectionName ($ name )
175173 {
176- $ name = $ name ?: $ this ->getDefaultConnection ();
177-
178174 return Str::endsWith ($ name , ['::read ' , '::write ' ])
179175 ? explode (':: ' , $ name , 2 )
180176 : [$ name , null ];
@@ -217,8 +213,6 @@ protected function makeConnection($name)
217213 */
218214 protected function configuration ($ name )
219215 {
220- $ name = $ name ?: $ this ->getDefaultConnection ();
221-
222216 $ connections = $ this ->app ['config ' ]['database.connections ' ];
223217
224218 $ config = $ this ->dynamicConnectionConfigurations [$ name ] ?? Arr::get ($ connections , $ name );
@@ -299,40 +293,38 @@ protected function setPdoForType(Connection $connection, $type = null)
299293 /**
300294 * Disconnect from the given database and remove from local cache.
301295 *
302- * @param string|null $name
296+ * @param \UnitEnum| string|null $name
303297 * @return void
304298 */
305299 public function purge ($ name = null )
306300 {
307- $ name = $ name ?: $ this ->getDefaultConnection ();
308-
309- $ this ->disconnect ($ name );
301+ $ this ->disconnect ($ name = enum_value ($ name ) ?? $ this ->getDefaultConnection ());
310302
311303 unset($ this ->connections [$ name ]);
312304 }
313305
314306 /**
315307 * Disconnect from the given database.
316308 *
317- * @param string|null $name
309+ * @param \UnitEnum| string|null $name
318310 * @return void
319311 */
320312 public function disconnect ($ name = null )
321313 {
322- if (isset ($ this ->connections [$ name = $ name ?: $ this ->getDefaultConnection ()])) {
314+ if (isset ($ this ->connections [$ name = enum_value ( $ name) ?? $ this ->getDefaultConnection ()])) {
323315 $ this ->connections [$ name ]->disconnect ();
324316 }
325317 }
326318
327319 /**
328320 * Reconnect to the given database.
329321 *
330- * @param string|null $name
322+ * @param \UnitEnum| string|null $name
331323 * @return \Illuminate\Database\Connection
332324 */
333325 public function reconnect ($ name = null )
334326 {
335- $ this ->disconnect ($ name = $ name ?: $ this ->getDefaultConnection ());
327+ $ this ->disconnect ($ name = enum_value ( $ name) ?? $ this ->getDefaultConnection ());
336328
337329 if (! isset ($ this ->connections [$ name ])) {
338330 return $ this ->connection ($ name );
@@ -344,15 +336,15 @@ public function reconnect($name = null)
344336 /**
345337 * Set the default database connection for the callback execution.
346338 *
347- * @param string $name
339+ * @param \UnitEnum| string $name
348340 * @param callable $callback
349341 * @return mixed
350342 */
351343 public function usingConnection ($ name , callable $ callback )
352344 {
353345 $ previousName = $ this ->getDefaultConnection ();
354346
355- $ this ->setDefaultConnection ($ name );
347+ $ this ->setDefaultConnection ($ name = enum_value ( $ name ) );
356348
357349 try {
358350 return $ callback ();
0 commit comments