phpOMS/DataStorage/Database/Connection/ConnectionFactory.php
Dennis Eichhorn 14d4061beb Fixes during secondary app dev
While working on another app some bugs came up that are related to the
way the framework is included and working in combination with the app.
These changes make it more general purpose friendly.
2016-09-07 20:54:28 +02:00

71 lines
1.7 KiB
PHP

<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Connection;
/**
* Database connection factory.
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class ConnectionFactory
{
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
public static function create(array $dbdata) : ConnectionInterface
{
switch ($dbdata['db']) {
case 'mysql':
return new MysqlConnection($dbdata);
break;
case 'mssql':
return new SqlServerConnection($dbdata);
break;
default:
throw new \InvalidArgumentException('Database "' . $dbdata['db'] . '" is not supported.');
}
}
}