Skip to content

Commit

Permalink
DatabaseConfiguration update
Browse files Browse the repository at this point in the history
  • Loading branch information
Trehinos committed Jul 10, 2023
1 parent a3957b6 commit 3ff7eb7
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions thor/Framework/Configurations/DatabasesConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

use PDO;
use Thor\Configuration\Configuration;
use Thor\Configuration\ConfigurationFromFile;
use Thor\Database\PdoExtension\PdoHandler;
use Thor\Database\PdoExtension\PdoRequester;
use Thor\Database\PdoExtension\PdoCollection;
use Thor\Configuration\ConfigurationFromFile;

final class DatabasesConfiguration extends ConfigurationFromFile
{
Expand Down Expand Up @@ -44,20 +45,40 @@ public function createPdoCollection(): PdoCollection
foreach ($this->getArrayCopy() as $connectionName => $config) {
$pdos->add(
$connectionName,
new PdoHandler(
$config['dsn'] ?? '',
$config['user'] ?? null,
$config['password'] ?? null,
match (strtolower($config['case'] ?? 'natural')) {
'upper' => PDO::CASE_UPPER,
'lower' => PDO::CASE_LOWER,
default => PDO::CASE_NATURAL
},
)
$this->createPdoHandler($connectionName)
);
}

return $pdos;
}

public function createPdoRequester(string $name): ?PdoRequester
{
$config = $this[$name] ?? null;
if ($config === null) {
return null;
}

return new PdoRequester($this->createPdoHandler($name));
}

public function createPdoHandler(string $name): ?PdoHandler
{
$config = $this[$name] ?? null;
if ($config === null) {
return null;
}

return new PdoHandler(
$config['dsn'] ?? '',
$config['user'] ?? null,
$config['password'] ?? null,
match (strtolower($config['case'] ?? 'natural')) {
'upper' => PDO::CASE_UPPER,
'lower' => PDO::CASE_LOWER,
default => PDO::CASE_NATURAL
},
);
}

}

0 comments on commit 3ff7eb7

Please sign in to comment.