/** * Non-persistent database connection * * @param bool $persistent * @return SQLite3 */ public function db_connect($persistent = FALSE) { if ($persistent) { Logger::logDebug('SQLite3 doesn\'t support persistent connections'); } try { return !$this->password ? new SQLite3($this->database) : new SQLite3($this->database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $this->password); } catch (Exception $e) { return FALSE; } }
/** * Constructor * * Initialize class properties based on the configuration array. * * @param array $config = array() * @return void */ public function __construct($config = array()) { isset($config['adapter']) && ($this->_adapter = $config['adapter']); isset($config['backup']) && ($this->_backup_driver = $config['backup']); isset($config['key_prefix']) && ($this->key_prefix = $config['key_prefix']); // If the specified adapter isn't available, check the backup. if (!$this->is_supported($this->_adapter)) { if (!$this->is_supported($this->_backup_driver)) { // Backup isn't supported either. Default to 'Dummy' driver. Logger::logError('Cache adapter "' . $this->_adapter . '" and backup "' . $this->_backup_driver . '" are both unavailable. Cache is now using "Dummy" adapter.'); $this->_adapter = 'dummy'; } else { // Backup is supported. Set it to primary. Logger::logDebug('Cache adapter "' . $this->_adapter . '" is unavailable. Falling back to "' . $this->_backup_driver . '" backup adapter.'); $this->_adapter = $this->_backup_driver; } } }
/** * Set Cache Directory Path * * @param string $path Path to the cache directory * @return bool */ public function check_path($path = '') { $path = $path === '' ? Core::$tempDir . DS . 'Database' : $path; // Add a trailing slash to the path if needed $path = realpath($path) ? rtrim(realpath($path), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : rtrim($path, '/') . '/'; if (!is_dir($path)) { if (!mkdir($path, 0777, false)) { Logger::logDebug('DB cache path error: ' . $path); // If the path is wrong we'll turn off caching return $this->db->cache_off(); } } if (!Core::isReallyWritable($path)) { Logger::logDebug('DB cache dir not writable: ' . $path); // If the path is not really writable we'll turn off caching return $this->db->cache_off(); } $this->db->cachedir = $path; return TRUE; }
/** * Complete Transaction * * @return bool */ public function trans_complete() { if (!$this->trans_enabled) { return FALSE; } // The query() function will set this flag to FALSE in the event that a query failed if ($this->_trans_status === FALSE or $this->_trans_failure === TRUE) { $this->trans_rollback(); // If we are NOT running in strict mode, we will reset // the _trans_status flag so that subsequent groups of // transactions will be permitted. if ($this->trans_strict === FALSE) { $this->_trans_status = TRUE; } Logger::logDebug('DB Transaction Failure'); return FALSE; } return $this->trans_commit(); }
/** * Initialize * * @param array $params Configuration parameters * @return Encryption */ public function initialize(array $params) { if (!empty($params['driver'])) { if (isset($this->_drivers[$params['driver']])) { if ($this->_drivers[$params['driver']]) { $this->_driver = $params['driver']; } else { Logger::logError("Encryption: Driver '" . $params['driver'] . "' is not available."); } } else { Logger::logError("Encryption: Unknown driver '" . $params['driver'] . "' cannot be configured."); } } if (empty($this->_driver)) { $this->_driver = $this->_drivers['openssl'] === TRUE ? 'openssl' : 'mcrypt'; Logger::logDebug("Encryption: Auto-configured driver '" . $this->_driver . "'."); } empty($params['cipher']) && ($params['cipher'] = $this->_cipher); empty($params['key']) or $this->_key = $params['key']; $this->{'_' . $this->_driver . '_initialize'}($params); return $this; }