<?php
declare(strict_types=1);

namespace PSLauncher;

final class Db
{
    private static ?\PDO $pdo = null;

    public static function get(array $config): \PDO
    {
        if (self::$pdo !== null) return self::$pdo;
        $cfg = $config['db'];
        self::$pdo = new \PDO(
            $cfg['dsn'],
            $cfg['username'],
            $cfg['password'],
            [
                \PDO::ATTR_ERRMODE            => \PDO::ERRMODE_EXCEPTION,
                \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
                \PDO::ATTR_EMULATE_PREPARES   => false,
            ]
        );
        return self::$pdo;
    }
}
