/** * @param \Doctrine\Bundle\DoctrineBundle\Registry $doctrine */ public function __construct($doctrine) { $dbConfig = $doctrine->getConnection()->getParams(); if (isset($dbConfig['dsn'])) { $data = EhrlichAndreas_Util_Dsn::parseDsn($dbConfig['dsn']); foreach ($data as $key => $value) { $dbConfig[$key] = $value; } $data = EhrlichAndreas_Util_Dsn::parseUri($dbConfig['dsn']); if (isset($data[0])) { $dbConfig['adapter'] = ucfirst($data[0]); } if (isset($dbConfig['adapter']) && $dbConfig['driver']) { $dbConfig['adapter'] = $dbConfig['driver'] . '_' . $dbConfig['adapter']; } } if (!isset($dbConfig['adapter']) && isset($dbConfig['driver'])) { $dbConfig['adapter'] = $dbConfig['driver']; unset($dbConfig['driver']); } if (!isset($dbConfig['driver_options']) && isset($dbConfig['driverOptions'])) { $dbConfig['driver_options'] = $dbConfig['driverOptions']; unset($dbConfig['driverOptions']); } if (!isset($dbConfig['username']) && isset($dbConfig['user'])) { $dbConfig['username'] = $dbConfig['user']; unset($dbConfig['user']); } $this->adapter = EhrlichAndreas_Db_Db::factory($dbConfig); $this->adapter->setConnection($doctrine->getConnection()->getWrappedConnection()); }
/** * * @param string $key * @return EhrlichAndreas_Db_Adapter_Abstract */ public function getDbConnection($key = 'default') { $index = 'dbconnection' . $key; if (!EhrlichAndreas_Mvc_Registry::isRegistered($index)) { $config = EhrlichAndreas_Mvc_Registry::get('config'); if (isset($config['db'][$key])) { $dbConfig = $config['db']['default']; $dbConnection = EhrlichAndreas_Db_Db::factory($dbConfig); EhrlichAndreas_Mvc_Registry::set($index, $dbConnection); return $dbConnection; } } return EhrlichAndreas_Mvc_Registry::get($index); }
/** * @param \Zend\Db\Adapter\Adapter $adapter */ public function __construct($adapter) { $dbConfig = $adapter->getDriver()->getConnection()->getConnectionParameters(); if (isset($dbConfig['dsn'])) { $data = EhrlichAndreas_Util_Dsn::parseDsn($dbConfig['dsn']); foreach ($data as $key => $value) { $dbConfig[$key] = $value; } $data = EhrlichAndreas_Util_Dsn::parseUri($dbConfig['dsn']); if (isset($data[0])) { $dbConfig['adapter'] = ucfirst($data[0]); } if (isset($dbConfig['adapter']) && $dbConfig['driver']) { $dbConfig['adapter'] = $dbConfig['driver'] . '_' . $dbConfig['adapter']; } } $this->adapter = EhrlichAndreas_Db_Db::factory($dbConfig); $this->adapter->setConnection($adapter->getDriver()->getConnection()->getResource()); }
<?php ini_set('display_startup_errors', true); ini_set('display_errors', true); ini_set('error_reporting', -1); error_reporting(-1); date_default_timezone_set('UTC'); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/_errorlog/' . date('Y-m-d') . '.php.log'); if (!file_exists(dirname(__FILE__) . '/_errorlog/') || !is_dir(dirname(__FILE__) . '/_errorlog/')) { mkdir(dirname(__FILE__) . '/_errorlog/', 0777, true); } require_once dirname(dirname(__FILE__)) . '/vendor/autoload_52.php'; $dbConfig = array('adapter' => 'Pdo_Mysql', 'params' => array('host' => 'localhost', 'port' => '8889', 'username' => 'root', 'password' => 'root', 'dbname' => 'cfp', 'charset' => 'utf8')); $dbConnection = EhrlichAndreas_Db_Db::factory($dbConfig); $cmsConfig = array('db' => $dbConnection); $aclCms = new EhrlichAndreas_AclCms_ModuleExtended($cmsConfig); $aclCms->install(); $resourceParents = array(array('child' => 'module-submodule', 'parent' => 'module'), array('child' => 'module-submodule-controller', 'parent' => 'module-submodule'), array('child' => array('module-submodule-controller-action', 'module-submodule-controller-action1', 'module-submodule-controller-action2', 'module-submodule-controller-action3', 'module-submodule-controller-action4', 'module-submodule-controller-action5'), 'parent' => 'module-submodule-controller')); $roles = array('guest', 'editor', 'moderator', 'admin', 'root'); $roleParents = array(array('child' => 'editor', 'parent' => 'guest'), array('child' => 'moderator', 'parent' => 'editor'), array('child' => 'admin', 'parent' => 'moderator')); $permissions = array(array('role' => 'root', 'resource' => 'module', 'permission' => '1'), array('role' => 'guest', 'resource' => 'module', 'permission' => '0'), array('role' => 'guest', 'resource' => 'module-submodule-controller-action', 'permission' => '1'), array('role' => 'editor', 'resource' => 'module-submodule-controller', 'permission' => '1'), array('role' => 'moderator', 'resource' => 'module-submodule', 'permission' => '1')); foreach ($roleParents as $roleParent) { $roles[] = $roleParent['parent']; $roles[] = $roleParent['child']; } $roles = array_values($roles); $roles = array_combine($roles, $roles); $resources = array(); foreach ($resourceParents as $resourceParent) { $parent = $resourceParent['parent'];
/** * 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(); }