Backup #760
| ID | 760 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Infrastructure/Config/DatabaseFactory.php |
| Version | 2 |
| Typ |
modified |
| Größe | 2.1 KB |
| Hash | a7267ba3688d760ff6cb5a054ab7738ef950f5410fa30e6a57f147ba215ec9fd |
| Datum | 2025-12-23 08:00:56 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?php
declare(strict_types=1);
namespace Infrastructure\Config;
// @responsibility: Factory für benannte Datenbankverbindungen (dev, content)
use PDO;
use RuntimeException;
*
* Connections are cached per-request for efficiency.
*/
final class DatabaseFactory
{
private const array DATABASES = [
'dev' => 'ki_dev',
'content' => 'ki_content',
];
/** @var array<string, PDO> */
private static array $connections = [];
/**
* Gets the 'dev' database connection (ki_dev).
*
* Contains: dokumentation, dokumentation_chunks, tasks, contracts, protokoll
*/
public static function dev(): PDO
{
return self::getConnection('dev');
}
/**
* Gets the 'content' database connection (ki_content).
*
* Contains: content studio data, semantic entities, relations
*/
public static function content(): PDO
{
return self::getConnection('content');
}
/**
* Gets a connection by name.
*
* @param string $name Connection name ('dev' or 'content')
*/
public static function getConnection(string $name): PDO
{
if (!isset(self::DATABASES[$name])) {
throw new RuntimeException("Unknown database connection: {$name}");
}
if (!isset(self::$connections[$name])) {
self::$connections[$name] = self::createConnection(self::DATABASES[$name]);
}
return self::$connections[$name];
}
/**
* Closes all connections and clears the cache.
*/
public static function closeAll(): void
{
self::$connections = [];
}
/**
* Creates a new PDO connection.
*/
private static function createConnection(string $database): PDO
{
$password = CredentialService::getMariaDbPassword();
return new PDO(
"mysql:host=localhost;dbname={$database};charset=utf8mb4",
'root',
$password,
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
]
);
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1362 |
3 |
modified |
2.1 KB |
2025-12-25 16:55 |
| 760 |
2 |
modified |
2.1 KB |
2025-12-23 08:00 |
| 758 |
1 |
modified |
2.3 KB |
2025-12-23 08:00 |
← Zurück zur Übersicht