summaryrefslogtreecommitdiff
path: root/vendor/fguillot/picodb/lib/PicoDb/DriverFactory.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2017-10-25 16:22:10 -0700
committerFrederic Guillot <fred@kanboard.net>2017-10-25 16:22:10 -0700
commit9e2b2a32fd0e967ad3184e9a5d091a29953acb91 (patch)
tree00822e24aa1110c73ca455a8d096ef296c008cbc /vendor/fguillot/picodb/lib/PicoDb/DriverFactory.php
parentc507c5416251c505cb3e088a03c6664bed73c812 (diff)
Include composer dependencies in repo
Diffstat (limited to 'vendor/fguillot/picodb/lib/PicoDb/DriverFactory.php')
-rw-r--r--vendor/fguillot/picodb/lib/PicoDb/DriverFactory.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/fguillot/picodb/lib/PicoDb/DriverFactory.php b/vendor/fguillot/picodb/lib/PicoDb/DriverFactory.php
new file mode 100644
index 00000000..13151ba7
--- /dev/null
+++ b/vendor/fguillot/picodb/lib/PicoDb/DriverFactory.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace PicoDb;
+
+use LogicException;
+use PicoDb\Driver\Mssql;
+use PicoDb\Driver\Mysql;
+use PicoDb\Driver\Postgres;
+use PicoDb\Driver\Sqlite;
+
+/**
+ * Class DriverFactory
+ *
+ * @package PicoDb
+ * @author Frederic Guillot
+ */
+class DriverFactory
+{
+ /**
+ * Get database driver from settings or environment URL
+ *
+ * @access public
+ * @param array $settings
+ * @return Mssql|Mysql|Postgres|Sqlite
+ */
+ public static function getDriver(array $settings)
+ {
+ if (! isset($settings['driver'])) {
+ throw new LogicException('You must define a database driver');
+ }
+
+ switch ($settings['driver']) {
+ case 'sqlite':
+ return new Sqlite($settings);
+ case 'mssql':
+ return new Mssql($settings);
+ case 'mysql':
+ return new Mysql($settings);
+ case 'postgres':
+ return new Postgres($settings);
+ default:
+ throw new LogicException('This database driver is not supported');
+ }
+ }
+}