| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | namespace Aurora\System\Db; |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | class Creator |
| 20: | { |
| 21: | |
| 22: | |
| 23: | |
| 24: | public static $oDbConnector; |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | public static $oSlaveDbConnector; |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | public static $oCommandCreatorHelper; |
| 35: | |
| 36: | private function __construct() |
| 37: | { |
| 38: | } |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | public static function ClearStatic() |
| 44: | { |
| 45: | self::$oDbConnector = null; |
| 46: | self::$oSlaveDbConnector = null; |
| 47: | } |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | public static function ConnectorFabric($aData) |
| 54: | { |
| 55: | $oConnector = null; |
| 56: | if (isset($aData['Type'])) { |
| 57: | $iDbType = $aData['Type']; |
| 58: | |
| 59: | if (isset($aData['DBHost'], $aData['DBLogin'], $aData['DBPassword'], $aData['DBName'], $aData['DBTablePrefix'])) { |
| 60: | if (\Aurora\System\Enums\DbType::PostgreSQL === $iDbType) { |
| 61: | $oConnector = new Pdo\Postgres($aData['DBHost'], $aData['DBLogin'], $aData['DBPassword'], $aData['DBName'], $aData['DBTablePrefix']); |
| 62: | } else { |
| 63: | $oConnector = new Pdo\MySql($aData['DBHost'], $aData['DBLogin'], $aData['DBPassword'], $aData['DBName'], $aData['DBTablePrefix']); |
| 64: | } |
| 65: | } |
| 66: | } |
| 67: | |
| 68: | return $oConnector; |
| 69: | } |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | public static function CommandCreatorHelperFabric($iDbType = \Aurora\System\Enums\DbType::MySQL) |
| 76: | { |
| 77: | $oHelper = null; |
| 78: | if (\Aurora\System\Enums\DbType::PostgreSQL === $iDbType) { |
| 79: | $oHelper = new Pdo\Postgres\Helper(); |
| 80: | } else { |
| 81: | $oHelper = new Pdo\MySql\Helper(); |
| 82: | } |
| 83: | |
| 84: | return $oHelper; |
| 85: | } |
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: | |
| 91: | public static function &CreateConnector(\Aurora\System\AbstractSettings $oSettings) |
| 92: | { |
| 93: | $aResult = array(); |
| 94: | if (!is_object(self::$oDbConnector)) { |
| 95: | Creator::$oDbConnector = Creator::ConnectorFabric(array( |
| 96: | 'Type' => $oSettings->DBType, |
| 97: | 'DBHost' => $oSettings->DBHost, |
| 98: | 'DBLogin' => $oSettings->DBLogin, |
| 99: | 'DBPassword' => $oSettings->DBPassword, |
| 100: | 'DBName' => $oSettings->DBName, |
| 101: | 'DBTablePrefix' => $oSettings->DBPrefix |
| 102: | )); |
| 103: | |
| 104: | if ($oSettings->UseSlaveConnection) { |
| 105: | Creator::$oSlaveDbConnector = Creator::ConnectorFabric(array( |
| 106: | 'Type' => $oSettings->DBType, |
| 107: | 'DBHost' => $oSettings->DBSlaveHost, |
| 108: | 'DBLogin' => $oSettings->DBSlaveLogin, |
| 109: | 'DBPassword' => $oSettings->DBSlavePassword, |
| 110: | 'DBName' => $oSettings->DBSlaveName, |
| 111: | 'DBTablePrefix' => $oSettings->DBPrefix |
| 112: | )); |
| 113: | } |
| 114: | } |
| 115: | |
| 116: | $aResult = array(&Creator::$oDbConnector, &Creator::$oSlaveDbConnector); |
| 117: | return $aResult; |
| 118: | } |
| 119: | |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: | public static function &CreateCommandCreatorHelper(\Aurora\System\AbstractSettings $oSettings) |
| 125: | { |
| 126: | if (is_object(Creator::$oCommandCreatorHelper)) { |
| 127: | return Creator::$oCommandCreatorHelper; |
| 128: | } |
| 129: | |
| 130: | Creator::$oCommandCreatorHelper = Creator::CommandCreatorHelperFabric( |
| 131: | $oSettings->DBType |
| 132: | ); |
| 133: | |
| 134: | return Creator::$oCommandCreatorHelper; |
| 135: | } |
| 136: | } |
| 137: | |