Derive mode from DSN function

- Add headers in all files
- Minor field name changes
This commit is contained in:
2024-07-20 21:47:21 -04:00
parent 1a37b009ea
commit d8330d828a
81 changed files with 1053 additions and 551 deletions

View File

@@ -1,4 +1,10 @@
<?php declare(strict_types=1);
<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace BitBadger\PDODocument;
@@ -12,4 +18,19 @@ enum Mode
/** Storing documents in a SQLite database */
case SQLite;
/**
* Derive the mode from the Data Source Name (DSN)
*
* @return Mode The database mode based on the DSN
* @throws DocumentException If the DSN does not start with `pgsql:` or `sqlite:`
*/
public static function deriveFromDSN(string $dsn): Mode
{
return match (true) {
str_starts_with($dsn, 'pgsql:') => Mode::PgSQL,
str_starts_with($dsn, 'sqlite:') => Mode::SQLite,
default => throw new DocumentException('This library currently supports PostgreSQL and SQLite')
};
}
}