* @author Dennis Eichhorn * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 * @link http://orange-management.com */ declare(strict_types=1); namespace phpOMS\DataStorage\Database\Connection; /** * Database connection factory. * * @category Framework * @package phpOMS\DataStorage\Database * @author OMS Development Team * @author Dennis Eichhorn * @license OMS License 1.0 * @link http://orange-management.com * @since 1.0.0 */ class ConnectionFactory { /** * Constructor. * * @since 1.0.0 * @author Dennis Eichhorn */ private function __construct() { } /** * Create database connection. * * Overwrites current connection if existing * * @param string[] $dbdata the basic database information for establishing a connection * * @return ConnectionInterface * * @throws \InvalidArgumentException Throws this exception if the database is not supported. * * @since 1.0.0 * @author Dennis Eichhorn */ public static function create(array $dbdata) : ConnectionInterface { switch ($dbdata['db']) { case DatabaseType::MYSQL: return new MysqlConnection($dbdata); break; case DatabaseType::SQLSRV: return new SqlServerConnection($dbdata); break; default: throw new \InvalidArgumentException('Database "' . $dbdata['db'] . '" is not supported.'); } } }