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 @@ +