public function setDriver($driver = NULL) { $driver = strtolower(\apf\validate\String::mustBeNotEmpty($driver, "Driver name can't be empty")); if (!\apf\db\Adapter::isAvailableDriver($driver)) { $msg = "Given database driver \"{$driver}\" doesn't seems to be available," . "perhaps you need to install it?"; throw new \Exception($msg); } $this->driver = $driver; }
public static function configureAdapter(ProjectConfig &$config, LogInterface &$log) { $log->debug('[ Select database adapter ]'); $options = Adapter::listAvailable(); $options['B'] = 'Back'; $opt = strtolower(Cmd::select($options, 'adapter>', $log)); if ($opt == 'b') { return; } $adapterCliClass = sprintf('\\apf\\db\\adapter\\%s\\config\\Cli', $opt); return $adapterCliClass::configure($config, $log); }
public static function configure(&$config = NULL, LogInterface &$log) { do { Cmd::clear(); $log->debug('[ Select database connection type ]'); if (!$config) { $options = Adapter::listAvailable(); $options['B'] = 'Back'; $opt = Cmd::selectWithKeys($options, '>', $log); } switch (strtolower($opt)) { case 'b': break 2; break; default: $opt = $options[$opt]; $adapterClass = "\\apf\\db\\adapter\\{$opt}\\Adapter"; $adapterConfigClass = "\\apf\\db\\adapter\\{$opt}\\adapter\\Config"; $connectionClass = "\\apf\\db\\adapter\\{$opt}\\Connection"; $connectionConfigClass = "\\apf\\db\\adapter\\{$opt}\\connection\\Config"; $cliConfigClass = "\\apf\\db\\adapter\\{$opt}\\connection\\config\\Cli"; $connectionConfig = new $connectionConfigClass(); do { try { $connection = $cliConfigClass::configure($connectionConfig, $log); $adapterConfig = new $adapterConfigClass(); $adapterConfig->setConnection($connection); $adapter = new $adapterClass($adapterConfig); $connectionConfig->setAdapter($adapter); return $connection; } catch (\Exception $e) { $log->error($e->getMessage()); $opt = Cmd::selectWithKeys(array('A' => 'Abort', 'C' => 'Correct errors'), '>', $log); if (strtolower($opt) == 'a') { break 2; } } } while (TRUE); break; } } while (TRUE); }