/** * Return the connection resource * If we are not connected, the connection is made * * @throws EhrlichAndreas_AbstractCms_Exception * @return EhrlichAndreas_Db_Adapter_Abstract Connection resource */ public function getConnection() { if (!empty($this->db) || !empty($this->options['db'])) { if (EhrlichAndreas_Util_Object::isInstanceOf($this->db, 'EhrlichAndreas_Db_Adapter_Abstract') || EhrlichAndreas_Util_Object::isInstanceOf($this->db, 'Zend_Db_Adapter_Abstract')) { return $this->db; } else { $this->db = $this->options['db']; if (!EhrlichAndreas_Util_Object::isInstanceOf($this->db, 'EhrlichAndreas_Db_Adapter_Abstract') && !EhrlichAndreas_Util_Object::isInstanceOf($this->db, 'Zend_Db_Adapter_Abstract')) { $this->throwException("Impossible to open " . $this->options['db'] . " DB", $this->options['exceptionclass']); } return $this->db; } } elseif (!empty($this->options['dbconfig'])) { $adapter = EhrlichAndreas_Db_Db::getAdapterName($this->options['dbconfig']); if (!EhrlichAndreas_Util_Object::isInstanceOf($adapter, 'EhrlichAndreas_Db_Adapter_Abstract') && !EhrlichAndreas_Util_Object::isInstanceOf($this->db, 'Zend_Db_Adapter_Abstract')) { $this->throwException("Impossible to open " . $adapter . " DB", $this->options['exceptionclass']); } $dbconfig = $this->options['dbconfig']; if (isset($dbconfig['dbtableprefix'])) { unset($dbconfig['dbtableprefix']); } if (isset($dbconfig['dbtableprefixlength'])) { unset($dbconfig['dbtableprefixlength']); } if (isset($dbconfig['dbtableprefixlengthmax'])) { unset($dbconfig['dbtableprefixlengthmax']); } if (isset($dbconfig['dbtableprefixoffset'])) { unset($dbconfig['dbtableprefixoffset']); } if (isset($dbconfig['dbtablesuffix'])) { unset($dbconfig['dbtablesuffix']); } if (isset($dbconfig['dbtablesuffixlength'])) { unset($dbconfig['dbtablesuffixlength']); } if (isset($dbconfig['dbtablesuffixlengthmax'])) { unset($dbconfig['dbtablesuffixlengthmax']); } if (isset($dbconfig['dbtablesuffixoffset'])) { unset($dbconfig['dbtablesuffixoffset']); } $this->db = EhrlichAndreas_Db_Db::factory($dbconfig); return $this->db; } else { $this->throwException("Impossible to open DB", $this->options['exceptionclass']); } }
/** * Constructor * * @param array $options * Associative array of options * @throws EhrlichAndreas_AbstractCms_Exception * @return void */ public function __construct($options = array()) { $options = $this->_getCmsConfigFromAdapter($options); if (empty($options['exceptionclass'])) { $options['exceptionclass'] = 'EhrlichAndreas_AbstractCms_Exception'; } if (empty($options['db']) && empty($options['dbconfig'])) { $this->throwException('db or dbconfig option has to set', $options['exceptionclass']); } if (!empty($options['db']) && !EhrlichAndreas_Util_Object::isInstanceOf($options['db'], 'EhrlichAndreas_Db_Adapter_Abstract') && !EhrlichAndreas_Util_Object::isInstanceOf($options['db'], 'Zend_Db_Adapter_Abstract')) { $this->throwException("Impossible to open " . $options['db'] . " DB", $options['exceptionclass']); } elseif (isset($options['dbconfig'])) { $adapter = EhrlichAndreas_Db_Db::getAdapterName($options['dbconfig']); if (!EhrlichAndreas_Util_Object::isInstanceOf($adapter, 'EhrlichAndreas_Db_Adapter_Abstract') && !EhrlichAndreas_Util_Object::isInstanceOf($adapter, 'Zend_Db_Adapter_Abstract')) { $this->throwException("Impossible to open " . $adapter . " DB", $options['exceptionclass']); } } else { // $this->throwException("Impossible to open // DB",$options['exceptionclass']); } if (empty($options['db'])) { $options['db'] = null; } if (!isset($options['dbtableprefix']) && isset($options['dbconfig']['dbtableprefix'])) { $options['dbtableprefix'] = $options['dbconfig']['dbtableprefix']; } if (!isset($options['dbtableprefix']) && isset($options['dbconfig']['params']['dbtableprefix'])) { $options['dbtableprefix'] = $options['dbconfig']['params']['dbtableprefix']; } if (!isset($options['dbtableprefix']) && isset($options['dbconfig']['dbtableprefix'])) { $options['dbtableprefix'] = $options['dbconfig']['dbtableprefix']; } if (!isset($options['dbtableprefix']) && isset($options['dbconfig']['params']['dbtableprefix'])) { $options['dbtableprefix'] = $options['dbconfig']['params']['dbtableprefix']; } if (!isset($options['dbtableprefixlength']) && isset($options['dbconfig']['dbtableprefixlength'])) { $options['dbtableprefixlength'] = $options['dbconfig']['dbtableprefixlength']; } if (!isset($options['dbtableprefixlength']) && isset($options['dbconfig']['params']['dbtableprefixlength'])) { $options['dbtableprefixlength'] = $options['dbconfig']['params']['dbtableprefixlength']; } if (!isset($options['dbtableprefixlengthmax']) && isset($options['dbconfig']['dbtableprefixlengthmax'])) { $options['dbtableprefixlengthmax'] = $options['dbconfig']['dbtableprefixlengthmax']; } if (!isset($options['dbtableprefixlengthmax']) && isset($options['dbconfig']['params']['dbtableprefixlengthmax'])) { $options['dbtableprefixlengthmax'] = $options['dbconfig']['params']['dbtableprefixlengthmax']; } if (!isset($options['dbtableprefixoffset']) && isset($options['dbconfig']['dbtableprefixoffset'])) { $options['dbtableprefixoffset'] = $options['dbconfig']['dbtableprefixoffset']; } if (!isset($options['dbtableprefixoffset']) && isset($options['dbconfig']['params']['dbtableprefixoffset'])) { $options['dbtableprefixoffset'] = $options['dbconfig']['params']['dbtableprefixoffset']; } if (!isset($options['dbtablesuffix']) && isset($options['dbconfig']['dbtablesuffix'])) { $options['dbtablesuffix'] = $options['dbconfig']['dbtablesuffix']; } if (!isset($options['dbtablesuffix']) && isset($options['dbconfig']['params']['dbtablesuffix'])) { $options['dbtablesuffix'] = $options['dbconfig']['params']['dbtablesuffix']; } if (!isset($options['dbtablesuffixlength']) && isset($options['dbconfig']['dbtablesuffixlength'])) { $options['dbtablesuffixlength'] = $options['dbconfig']['dbtablesuffixlength']; } if (!isset($options['dbtablesuffixlength']) && isset($options['dbconfig']['params']['dbtablesuffixlength'])) { $options['dbtablesuffixlength'] = $options['dbconfig']['params']['dbtablesuffixlength']; } if (!isset($options['dbtablesuffixlengthmax']) && isset($options['dbconfig']['dbtablesuffixlengthmax'])) { $options['dbtablesuffixlengthmax'] = $options['dbconfig']['dbtablesuffixlengthmax']; } if (!isset($options['dbtablesuffixlengthmax']) && isset($options['dbconfig']['params']['dbtablesuffixlengthmax'])) { $options['dbtablesuffixlengthmax'] = $options['dbconfig']['params']['dbtablesuffixlengthmax']; } if (!isset($options['dbtablesuffixoffset']) && isset($options['dbconfig']['dbtablesuffixoffset'])) { $options['dbtablesuffixoffset'] = $options['dbconfig']['dbtablesuffixoffset']; } if (!isset($options['dbtablesuffixoffset']) && isset($options['dbconfig']['params']['dbtablesuffixoffset'])) { $options['dbtablesuffixoffset'] = $options['dbconfig']['params']['dbtablesuffixoffset']; } $this->options = $options; //if (empty($options['db'])) //{ $class = ''; if (!empty($adapter)) { $class = $adapter; } elseif (!empty($options['db'])) { $class = get_class($options['db']); } else { $class = EhrlichAndreas_Db_Db::getAdapterName($options['dbconfig']); } // TODO if (stripos($class, 'ibm') !== false) { $class = 'Pdo_Ibm'; $this->switch = 'ibm'; } elseif (stripos($class, 'mssql') !== false) { $class = 'Pdo_Mssql'; $this->switch = 'mssql'; } elseif (stripos($class, 'mysql') !== false) { $class = 'Pdo_Mysql'; $this->switch = 'mysql'; } elseif (stripos($class, 'oci') !== false) { $class = 'Pdo_Oci'; $this->switch = 'oci'; } elseif (stripos($class, 'sqlite') !== false) { $class = 'Pdo_Pgsql'; $this->switch = 'pgsql'; } elseif (stripos($class, 'sqlite') !== false) { $class = 'Pdo_Sqlite'; $this->switch = 'sqlite'; } $adapterNamespace = 'EhrlichAndreas_AbstractCms_Abstract_Adapter'; if (isset($options['adapterNamespace'])) { if ($options['adapterNamespace'] != '') { $adapterNamespace = $options['adapterNamespace']; } unset($options['adapterNamespace']); } $adapterNamespace = trim($adapterNamespace, '_'); $class = $adapterNamespace . '_' . $class; $this->adapter = new $class($options); //} //else //{ // $this->adapter = $options['db']; //} $this->modelBasic = new EhrlichAndreas_AbstractCms_Abstract_Model(); }