protected function setupConnection() { if (!$this->registry || !$this->dbName) { throw new \RuntimeException('You must setup registry and dbName before calling this method!'); } if ($this->dbName == self::DB_MYSQL) { $this->connection = $this->registry->getMysql(); return; } $credentials = new \tables\MysqlCredentials(); $row = $credentials->findMysqlCredentials(); if (!$row) { throw new \RuntimeException('Credentials is empty'); } $row['mysql_dsn'] = preg_replace('#dbname=([\\w]+)(?=$|\\W)#i', 'dbname=' . $this->dbName, $row['mysql_dsn']); $this->connection = $credentials->createConnectionByRow($row); if (!$this->connection) { throw new \RuntimeException('Cannot create connection!'); } }
protected function checkMysql() { foreach ($this->controllerFront->getControllerChain() as $item) { if (get_class($item['instance']) == 'controllers\\Setup' && strtolower($item['action']) == 'actionindex') { return; } break; } $mysqlModel = new \tables\MysqlCredentials(); $mysql = $mysqlModel->getMysqlConnection(); $setupLink = $this->controllerFront->makeLink('setup/index'); if (is_null($mysql)) { $this->registry->getResponse()->redirect($setupLink); } if ($mysql === false) { $this->registry->getFlashMessenger()->add('Cannot connect to Mysql!', 'error'); $this->registry->getResponse()->redirect($setupLink); } $this->controllerFront->getRegistry()->getConnectionStorage()->add($mysql, db\ConnectionStorage::MYSQL, false); db\table\Mysql::setDefaultConnection($mysql); }