Skip to content

Commit ddaa7dd

Browse files
committed
feat: add getConnection method
1 parent 8103020 commit ddaa7dd

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/Schema.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@ class Schema
1818
/**@var \Illuminate\Database\Capsule\Manager $capsule */
1919
protected static Manager $connection;
2020

21+
/**
22+
* Get the database connection used in a schema file
23+
* @param string $fileName The schema file name
24+
* @return string|null
25+
*/
26+
public static function getConnection(string $fileName): ?string
27+
{
28+
return Yaml::parseFile($fileName)['connection'] ?? null;
29+
}
30+
2131
/**
2232
* Migrate your schema file tables
23-
*
2433
* @param string $fileToMigrate The schema file to migrate
2534
* @return bool
2635
*/
@@ -273,7 +282,6 @@ public static function migrate(string $fileToMigrate): bool
273282

274283
/**
275284
* Seed a database table from schema file
276-
*
277285
* @param string $fileToSeed The name of the schema file
278286
* @return bool
279287
*/
@@ -318,7 +326,7 @@ public static function seed(string $fileToSeed): bool
318326
if (strpos($fakerMethod, ':') !== false) {
319327
$fakerMethod = explode(':', $fakerMethod);
320328
if (strpos($fakerMethod[1], ',') !== false) {
321-
$array_params = explode(",",$fakerMethod[1]);
329+
$array_params = explode(",", $fakerMethod[1]);
322330
$localFakerInstance = $localFakerInstance->{$fakerMethod[0]}($array_params);
323331
} else {
324332
$localFakerInstance = $localFakerInstance->{$fakerMethod[0]}($fakerMethod[1]);
@@ -397,6 +405,8 @@ public static function seed(string $fileToSeed): bool
397405

398406
/**
399407
* Reset a database table
408+
* @param string $fileToReset The schema file to reset
409+
* @return bool
400410
*/
401411
public static function reset(string $fileToReset): bool
402412
{
@@ -406,6 +416,8 @@ public static function reset(string $fileToReset): bool
406416

407417
/**
408418
* Drop a database table
419+
* @param string $fileToDrop The schema file to drop
420+
* @return bool
409421
*/
410422
public static function drop(string $fileToDrop): bool
411423
{
@@ -431,6 +443,9 @@ public static function drop(string $fileToDrop): bool
431443

432444
/**
433445
* Rollback db to a previous state
446+
* @param string $fileToRollback The schema file to rollback
447+
* @param int $step The number of steps to rollback
448+
* @return bool
434449
*/
435450
public static function rollback(string $fileToRollback, int $step = 1): bool
436451
{
@@ -467,6 +482,8 @@ public static function rollback(string $fileToRollback, int $step = 1): bool
467482

468483
/**
469484
* Get all column attributes
485+
* @param mixed $value
486+
* @return array
470487
*/
471488
public static function getColumnAttributes($value)
472489
{

0 commit comments

Comments
 (0)