/** * run the batch to create entity * * @access public * @param array $aOptions options of script * @return void */ public function createDb(array $aOptions = array()) { /** * option -a [indicated the sql json file] */ if (isset($aOptions['a'])) { $sSqlJsonFile = $aOptions['a']; } else { $sSqlJsonFile = false; } /** * option -b [indicated the sql json] */ if (isset($aOptions['b'])) { $sSqlJson = $aOptions['b']; } else { $sSqlJson = false; $sSqlJsonFile = str_replace('Batch', '', __DIR__) . 'Db.conf'; } /** * option -i [indicated the const json file to manage annotation in files] */ if (isset($aOptions['i'])) { $oConstJson = json_decode(file_get_contents($aOptions['i'])); } else { $oConstJson = '../Const.conf'; } if (is_object($oConstJson)) { foreach ($oConstJson as $sKey => $mValue) { if (is_string($mValue) || is_int($mValue) || is_float($mValue)) { if (!defined(strtoupper($sKey))) { define(strtoupper($sKey), $mValue); } } } } if ($sSqlJsonFile !== false) { $oJson = json_decode(file_get_contents($sSqlJsonFile)); } else { $oJson = json_decode($sSqlJson); } $oConnection = $oJson->configuration; $oContainer = new DbContainer(); $oContainer->setHost($oConnection->host)->setName($oConnection->db)->setPassword($oConnection->password)->setType($oConnection->type)->setUser($oConnection->user); $oPdo = Db::connect($oContainer); $oPdo->query("CREATE DATABASE " . $oConnection->db); echo "\n\n"; echo Bash::setBackground(" ", 'green'); echo Bash::setBackground(" [OK] Success ", 'green'); echo Bash::setBackground(" ", 'green'); echo "\n\n"; }