/** * Set the field values * * @param array $values * @return Install */ public function setFieldValues(array $values = null) { parent::setFieldValues($values); if ($_POST && !empty($this->db_adapter)) { // If not SQLite, check the DB parameters if (stripos($this->db_adapter, 'sqlite') === false) { $this->getElement('db_name')->addValidator(new Validator\NotEmpty(null, 'The database name is required.')); $this->getElement('db_username')->addValidator(new Validator\NotEmpty(null, 'The database username is required.')); $this->getElement('db_password')->addValidator(new Validator\NotEmpty(null, 'The database password is required.')); $this->getElement('db_host')->addValidator(new Validator\NotEmpty(null, 'The database host is required.')); } // Check the content path if (!$this->checkContentPath()) { $this->getElement('content_path')->addValidator(new Validator\NotEqual($this->content_path, wordwrap('The content directory (or subdirectories) either do not exist or are not writable.', 50, '<br />'))); } // Check the database credentials if ($this->isValid() && stripos($this->db_adapter, 'sqlite') === false) { if (stripos($this->db_adapter, 'pdo_') !== false) { $adapter = 'Pdo'; $type = str_replace('pdo_', '', strtolower($this->db_adapter)); } else { $adapter = ucfirst(strtolower($this->db_adapter)); $type = null; } $oldError = ini_get('error_reporting'); error_reporting(E_ERROR); $creds = ['database' => $this->db_name, 'username' => $this->db_username, 'password' => $this->db_password, 'host' => $this->db_host, 'type' => $type]; $dbCheck = Db::check($creds, $adapter); // If there is a DB error if (null != $dbCheck) { $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, wordwrap($dbCheck, 50, '<br />'))); } else { $db = Db::connect($adapter, $creds); $version = $db->version(); $version = substr($version, strrpos($version, ' ') + 1); if (strpos($version, '-') !== false) { $version = substr($version, 0, strpos($version, '-')); } if (stripos($this->db_adapter, 'mysql') !== false && version_compare($version, '5.0') < 0) { $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, 'The MySQL version must be 5.0 or greater.')); } else { if (stripos($this->db_adapter, 'pgsql') !== false && version_compare($version, '9.0') < 0) { $this->getElement('db_adapter')->addValidator(new Validator\NotEqual($this->db_adapter, 'The PostgreSQL version must be 9.0 or greater.')); } } } error_reporting($oldError); } } return $this; }
<?php /* * 2015 Lace Cart * * @author LaceCart Dev <*****@*****.**> * @copyright 2015 LaceCart Team * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of LaceCart Team */ use Pop\Db\Db as DB; use Pop\Db\Record as Adapter; return ['services' => ['session' => ['call' => 'Pop\\Web\\Session::getInstance'], 'db' => ['call' => function () use($config) { Adapter::setDb(DB::connect($config->database->adapter, ['database' => $config->database->database, 'username' => $config->database->username, 'password' => $config->database->password, 'host' => $config->database->host])); }], 'config' => ['call' => function () use($config) { return $config; }], 'nav' => ['call' => function () use($nav) { return $nav; }]]];