mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
137 lines
2.7 KiB
PHP
137 lines
2.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;
|
|
|
|
use phpOMS\DataStorage\Database\Connection\ConnectionAbstract;
|
|
use phpOMS\DataStorage\Database\Connection\ConnectionFactory;
|
|
|
|
/**
|
|
* Database pool handler.
|
|
*
|
|
* @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 Pool
|
|
{
|
|
|
|
/**
|
|
* Databases.
|
|
*
|
|
* @var ConnectionAbstract[]
|
|
* @since 1.0.0
|
|
*/
|
|
private $pool = [];
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
*/
|
|
public function __construct()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Add database.
|
|
*
|
|
* @param mixed $key Database key
|
|
* @param ConnectionAbstract $db Database
|
|
*
|
|
* @return \bool
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
*/
|
|
public function add($key = 'core', ConnectionAbstract $db) : \bool
|
|
{
|
|
if (isset($this->pool[$key])) {
|
|
return false;
|
|
}
|
|
|
|
$this->pool[$key] = $db;
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get database.
|
|
*
|
|
* @param mixed $key Database key
|
|
*
|
|
* @return ConnectionAbstract
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
*/
|
|
public function get($key = 'core')
|
|
{
|
|
if (!isset($this->pool[$key])) {
|
|
return false;
|
|
}
|
|
|
|
return $this->pool[$key];
|
|
}
|
|
|
|
/**
|
|
* Remove database.
|
|
*
|
|
* @param mixed $key Database key
|
|
*
|
|
* @return \bool
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
*/
|
|
public function remove($key) : \bool
|
|
{
|
|
if (!isset($this->pool[$key])) {
|
|
return false;
|
|
}
|
|
|
|
unset($this->pool[$key]);
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Create database.
|
|
*
|
|
* @param mixed $key Database key
|
|
* @param array $config Database config data
|
|
*
|
|
* @return void
|
|
*
|
|
* @since 1.0.0
|
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
|
*/
|
|
public function create($key, array $config)
|
|
{
|
|
if (isset($this->pool[$key])) {
|
|
return;
|
|
}
|
|
|
|
$this->pool[$key] = ConnectionFactory::create($config);
|
|
}
|
|
|
|
}
|