From 54473bdf79e1e3814644a42c54961b10cd6bca44 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Tue, 14 May 2024 21:10:36 -0400 Subject: [PATCH] Add configuration dir, add datbase connection interface --- .../Configuration/DatabaseConfiguration.php | 25 +++++++++++++++++++ .../src/Infrastructure/DatabaseConnection.php | 25 +++++-------------- .../DatabaseConnectionInterface.php | 15 +++++++++++ 3 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 code/src/Infrastructure/Configuration/DatabaseConfiguration.php create mode 100644 code/src/Infrastructure/DatabaseConnectionInterface.php diff --git a/code/src/Infrastructure/Configuration/DatabaseConfiguration.php b/code/src/Infrastructure/Configuration/DatabaseConfiguration.php new file mode 100644 index 0000000..34754b1 --- /dev/null +++ b/code/src/Infrastructure/Configuration/DatabaseConfiguration.php @@ -0,0 +1,25 @@ + Expect::structure([ + 'driver' => Expect::anyOf('mysql', 'sqlite')->required(), + 'host' => Expect::string()->default('localhost'), + 'post' => Expect::int()->min(1)->max(65535), + 'database' => Expect::string()->required(), + 'username' => Expect::string()->required(), + 'password' => Expect::string()->nullable() + ]) + ]); + } + +} diff --git a/code/src/Infrastructure/DatabaseConnection.php b/code/src/Infrastructure/DatabaseConnection.php index 1eb8a14..e605a23 100644 --- a/code/src/Infrastructure/DatabaseConnection.php +++ b/code/src/Infrastructure/DatabaseConnection.php @@ -2,38 +2,25 @@ namespace Slovocast\Infrastructure; -use League\Config\Configuration; -use Nette\Schema\Expect; use PDO; +use Slovocast\Infrastructure\DatabaseConnectionInterface; /** * Represents an active connection to a database */ -class DatabaseConnection +class DatabaseConnection implements DatabaseConnectionInterface { + private string $name; private PDO $pdo; - public function __construct(Configuration $config) + public function __construct(string $name, PDO $pdo) { - $this->pdo = new PDO(); + $this->name = $name; + $this->pdo = $pdo; } public function getConnection(): PDO { return $this->pdo; } - - public static function getConfigSchema(): Configuration - { - return new Configuration([ - 'database' => Expect::structure([ - 'driver' => Expect::anyOf('mysql', 'sqlite')->required(), - 'host' => Expect::string()->default('localhost'), - 'post' => Expect::int()->min(1)->max(65535), - 'database' => Expect::string()->required(), - 'username' => Expect::string()->required(), - 'password' => Expect::string()->nullable() - ]) - ]); - } } diff --git a/code/src/Infrastructure/DatabaseConnectionInterface.php b/code/src/Infrastructure/DatabaseConnectionInterface.php new file mode 100644 index 0000000..00f6a05 --- /dev/null +++ b/code/src/Infrastructure/DatabaseConnectionInterface.php @@ -0,0 +1,15 @@ +