-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Worksome\FoggyLaravel\Concerns; | ||
|
||
use Doctrine\DBAL\Driver\Connection as DriverConnection; | ||
use Doctrine\DBAL\Driver\PDO\Connection; | ||
|
||
trait ConnectsToDatabase | ||
{ | ||
public function connect(array $params): DriverConnection | ||
{ | ||
if (! isset($params['pdo']) || ! $params['pdo'] instanceof \PDO) { | ||
throw new \InvalidArgumentException('Laravel requires the "pdo" property to be set and be a PDO instance.'); | ||
} | ||
|
||
return new Connection($params['pdo']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Worksome\FoggyLaravel\Enums; | ||
|
||
use Doctrine\DBAL\Driver; | ||
use Worksome\FoggyLaravel\Concerns\ConnectsToDatabase; | ||
|
||
enum SupportedDriver | ||
{ | ||
case MySQL; | ||
case PostgreSQL; | ||
case SQLite; | ||
case SqlServer; | ||
|
||
public function driverName(): string | ||
{ | ||
return match ($this) { | ||
self::MySQL => 'pdo_mysql', | ||
self::PostgreSQL => 'pdo_pgsql', | ||
self::SQLite => 'pdo_sqlite', | ||
self::SqlServer => 'pdo_sqlsrv', | ||
}; | ||
} | ||
|
||
public function driver(): Driver | ||
{ | ||
return match ($this) { | ||
self::MySQL => new class extends Driver\AbstractMySQLDriver | ||
{ | ||
use ConnectsToDatabase; | ||
}, | ||
self::PostgreSQL => new class extends Driver\AbstractPostgreSQLDriver | ||
{ | ||
use ConnectsToDatabase; | ||
}, | ||
self::SQLite => new class extends Driver\AbstractSQLiteDriver | ||
{ | ||
use ConnectsToDatabase; | ||
}, | ||
self::SqlServer => new class extends Driver\AbstractSQLServerDriver | ||
{ | ||
use ConnectsToDatabase; | ||
}, | ||
}; | ||
} | ||
} |