/** * Class constructor * * Setup Memcache(d) * * @return void */ public function __construct() { // Try to load memcached server info from the config file. $defaults = $this->_config['default']; $this->_config = Config::get('cache')->memcached; if (class_exists('Memcached', FALSE)) { $this->_memcached = new Memcached(); } elseif (class_exists('Memcache', FALSE)) { $this->_memcached = new Memcache(); } else { Logger::logError('Cache: Failed to create Memcache(d) object; extension not loaded?'); return; } foreach ($this->_config as $cache_server) { isset($cache_server['hostname']) or $cache_server['hostname'] = $defaults['host']; isset($cache_server['port']) or $cache_server['port'] = $defaults['port']; isset($cache_server['weight']) or $cache_server['weight'] = $defaults['weight']; if ($this->_memcached instanceof Memcache) { // Third parameter is persistance and defaults to TRUE. $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], TRUE, $cache_server['weight']); } elseif ($this->_memcached instanceof Memcached) { $this->_memcached->addServer($cache_server['hostname'], $cache_server['port'], $cache_server['weight']); } } }
/** * Non-persistent database connection * * @param bool $persistent * @return resource */ public function db_connect($persistent = FALSE) { $error = NULL; $conn_id = $persistent === TRUE ? sqlite_popen($this->database, 0666, $error) : sqlite_open($this->database, 0666, $error); isset($error) && Logger::logError($error); return $conn_id; }
/** * 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; } }
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * @author TechFuze * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License * * @link http://techfuze.net/fuzeworks * @since Version 0.0.1 * * @version Version 1.0.0 */ use FuzeWorks\Logger; use Tracy\Debugger; // Load the FuzeWorks container $container = (require dirname(__DIR__) . '/application/bootstrap.php'); // Load the test abstract require_once 'TestCase.php'; // Reset error and exception handlers ob_start(); restore_error_handler(); restore_exception_handler(); // Display all errors ini_set('display_errors', 1); error_reporting(E_ALL | E_STRICT); // Set localhost "remote" IP isset($_SERVER['REMOTE_ADDR']) or $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Set a logger which works better with the CLI interface Logger::setLoggerTemplate('logger_cli'); //require_once('mocks/autoloader.php'); //spl_autoload_register('autoload');
/** * Load a single line from the language array * * @param string $line * @param boolean $log_errors * @return string */ public static function line($line, $log_errors = TRUE) { $value = isset(self::$language[$line]) ? self::$language[$line] : FALSE; // Because killer robots like unicorns! if ($value === FALSE && $log_errors === TRUE) { Logger::logError('Could not find the language line "' . $line . '"'); } return $value; }
/** * Non-persistent database connection * * @param bool $persistent * @return resource */ public function db_connect($persistent = FALSE) { $client_flags = $this->compress === FALSE ? 0 : MYSQL_CLIENT_COMPRESS; if ($this->encrypt === TRUE) { $client_flags = $client_flags | MYSQL_CLIENT_SSL; } // Error suppression is necessary mostly due to PHP 5.5+ issuing E_DEPRECATED messages $this->conn_id = $persistent === TRUE ? mysql_pconnect($this->hostname, $this->username, $this->password, $client_flags) : mysql_connect($this->hostname, $this->username, $this->password, TRUE, $client_flags); // ---------------------------------------------------------------- // Select the DB... assuming a database name is specified in the config file if ($this->database !== '' && !$this->db_select()) { Logger::logError('Unable to select database: ' . $this->database); return $this->db_debug === TRUE ? $this->display_error('db_unable_to_select', $this->database) : FALSE; } if (isset($this->stricton) && is_resource($this->conn_id)) { if ($this->stricton) { $this->simple_query('SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'); } else { $this->simple_query('SET SESSION sql_mode = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( @@sql_mode, "STRICT_ALL_TABLES,", ""), ",STRICT_ALL_TABLES", ""), "STRICT_ALL_TABLES", ""), "STRICT_TRANS_TABLES,", ""), ",STRICT_TRANS_TABLES", ""), "STRICT_TRANS_TABLES", "")'); } } return $this->conn_id; }
/** * Class constructor * * @param object &$db Database object * @return void */ public function __construct(&$db) { $this->db =& $db; $this->factory = Factory::getInstance(); Logger::log('Database Utility Class Initialized'); }
/** * Class constructor * * @param object &$db Database object * @return void */ public function __construct(&$db) { $this->db =& $db; Logger::log('Database Forge Class Initialized'); }
/** * Load a helper. * * Supply the name and the helper will be loaded from the supplied directory, * or from one of the helperPaths (which you can add). * * @param string $helperName Name of the helper * @param string|null $directory Directory to load the helper from, will ignore $helperPaths * @return bool Whether the helper was succesfully loaded (true if yes) */ public function load($helperName, $directory = null) { // First determine the name of the helper $helperName = strtolower(str_replace(array('_helper', '.php'), '', $helperName) . '_helper'); // Determine what directories should be checked $directories = is_null($directory) ? $this->helperPaths : array($directory); // Check it is already loaded if (isset($this->helpers[$helperName])) { Logger::log("Helper '" . $helperName . "' is already loaded. Skipping"); return false; } // First check if there is an 'extension' class $extendedHelper = Config::get('main')->application_prefix . $helperName; $extendedHelperLoaded = false; foreach ($directories as $helperPath) { $file = $helperPath . DS . $extendedHelper . '.php'; if (file_exists($file)) { $extendedHelperLoaded = true; $extendedHelperFile = $file; } } // If an extension is loaded there needs to be a base helper if ($extendedHelperLoaded) { $baseHelper = Core::$coreDir . DS . 'Helpers' . DS . $helperName . '.php'; if (!file_exists($baseHelper)) { throw new HelperException("Could not load helper. Base Helper not found while Extension loaded", 1); } // Fire the associated event $event = Events::fireEvent('helperLoadEvent', $helperName, $baseHelper, $extendedHelper, $extendedHelperFile); if ($event->isCancelled()) { Logger::log("Not loading helper. Aborted by event"); return false; } include_once $event->extendedHelperFile; include_once $event->helperFile; $this->helpers[$event->helperName] = true; Logger::log("Loading base helper '" . $event->helperName . "' and extended helper '" . $event->extendedHelperName . "'"); return true; } // If no extension exists, try loading a regular helper foreach ($directories as $helperPath) { $file = $helperPath . DS . $helperName . '.php'; if (file_exists($file)) { // Fire the associated event $event = Events::fireEvent('helperLoadEvent', $helperName, $file); if ($event->isCancelled()) { Logger::log("Not loading helper. Aborted by event"); return false; } include_once $event->helperFile; $this->helpers[$event->helperName] = true; Logger::log("Loading helper '" . $event->helperName . "'"); return true; } } throw new HelperException("Could not load helper. Helper not found.", 1); }
/** * Create the container which holds FuzeWorks. * * Due to the static nature of FuzeWorks, this is not yet possible. * When issue #101 is completed, this should be resolved. * * @return void */ public function createContainer() { // First set all the directories Core::$appDir = $this->parameters['appDir']; Core::$wwwDir = $this->parameters['wwwDir']; Core::$tempDir = $this->parameters['tempDir']; Core::$logDir = $this->parameters['logDir']; // Then set debug mode if ($this->parameters['debugMode']) { define('ENVIRONMENT', 'DEVELOPMENT'); } else { define('ENVIRONMENT', 'PRODUCTION'); } // And enable Tracy Debugger if (class_exists('Tracy\\Debugger', true)) { Debugger::enable(!$this->parameters['debugMode'], realpath($this->parameters['logDir'])); Logger::$useTracy = true; } // Then load the framework Core::init(); }
/** * Initialize OpenSSL * * @param array $params Configuration parameters * @return void */ protected function _openssl_initialize($params) { if (!empty($params['cipher'])) { $params['cipher'] = strtolower($params['cipher']); $this->_cipher_alias($params['cipher']); $this->_cipher = $params['cipher']; } if (!empty($params['mode'])) { $params['mode'] = strtolower($params['mode']); if (!isset($this->_modes['openssl'][$params['mode']])) { Logger::logError('Encryption: OpenSSL mode ' . strtoupper($params['mode']) . ' is not available.'); } else { $this->_mode = $this->_modes['openssl'][$params['mode']]; } } if (isset($this->_cipher, $this->_mode)) { // This is mostly for the stream mode, which doesn't get suffixed in OpenSSL $handle = empty($this->_mode) ? $this->_cipher : $this->_cipher . '-' . $this->_mode; if (!in_array($handle, openssl_get_cipher_methods(), TRUE)) { $this->_handle = NULL; Logger::logError('Encryption: Unable to initialize OpenSSL with method ' . strtoupper($handle) . '.'); } else { $this->_handle = $handle; Logger::log('Encryption: OpenSSL initialized with method ' . strtoupper($handle) . '.'); } } }
/** * Database connection * * @param bool $persistent * @return object */ public function db_connect($persistent = FALSE) { // Do we have a socket path? if ($this->hostname[0] === '/') { $hostname = NULL; $port = NULL; $socket = $this->hostname; } else { // Persistent connection support was added in PHP 5.3.0 $hostname = $persistent === TRUE && Core::isPHP('5.3') ? 'p:' . $this->hostname : $this->hostname; $port = empty($this->port) ? NULL : $this->port; $socket = NULL; } $client_flags = $this->compress === TRUE ? MYSQLI_CLIENT_COMPRESS : 0; $this->_mysqli = mysqli_init(); $this->_mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10); if (isset($this->stricton)) { if ($this->stricton) { $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'); } else { $this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( @@sql_mode, "STRICT_ALL_TABLES,", ""), ",STRICT_ALL_TABLES", ""), "STRICT_ALL_TABLES", ""), "STRICT_TRANS_TABLES,", ""), ",STRICT_TRANS_TABLES", ""), "STRICT_TRANS_TABLES", "")'); } } if (is_array($this->encrypt)) { $ssl = array(); empty($this->encrypt['ssl_key']) or $ssl['key'] = $this->encrypt['ssl_key']; empty($this->encrypt['ssl_cert']) or $ssl['cert'] = $this->encrypt['ssl_cert']; empty($this->encrypt['ssl_ca']) or $ssl['ca'] = $this->encrypt['ssl_ca']; empty($this->encrypt['ssl_capath']) or $ssl['capath'] = $this->encrypt['ssl_capath']; empty($this->encrypt['ssl_cipher']) or $ssl['cipher'] = $this->encrypt['ssl_cipher']; if (!empty($ssl)) { if (isset($this->encrypt['ssl_verify'])) { if ($this->encrypt['ssl_verify']) { defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') && $this->_mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, TRUE); } elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT')) { $this->_mysqli->options(MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT, TRUE); } } $client_flags |= MYSQLI_CLIENT_SSL; $this->_mysqli->ssl_set(isset($ssl['key']) ? $ssl['key'] : NULL, isset($ssl['cert']) ? $ssl['cert'] : NULL, isset($ssl['ca']) ? $ssl['ca'] : NULL, isset($ssl['capath']) ? $ssl['capath'] : NULL, isset($ssl['cipher']) ? $ssl['cipher'] : NULL); } } if ($this->_mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags)) { // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails if ($client_flags & MYSQLI_CLIENT_SSL && version_compare($this->_mysqli->client_info, '5.7.3', '<=') && empty($this->_mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value)) { $this->_mysqli->close(); $message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!'; Logger::logError($message); return $this->db->db_debug ? $this->db->display_error($message, '', TRUE) : FALSE; } return $this->_mysqli; } return FALSE; }
/** * Database connection * * @param bool $persistent * @return object */ public function db_connect($persistent = FALSE) { /* Prior to PHP 5.3.6, even if the charset was supplied in the DSN * on connect - it was ignored. This is a work-around for the issue. * * Reference: http://www.php.net/manual/en/ref.pdo-mysql.connection.php */ if (!Core::isPHP('5.3.6') && !empty($this->char_set)) { $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $this->char_set . (empty($this->dbcollat) ? '' : ' COLLATE ' . $this->dbcollat); } if (isset($this->stricton)) { if ($this->stricton) { $sql = 'CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")'; } else { $sql = 'REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( @@sql_mode, "STRICT_ALL_TABLES,", ""), ",STRICT_ALL_TABLES", ""), "STRICT_ALL_TABLES", ""), "STRICT_TRANS_TABLES,", ""), ",STRICT_TRANS_TABLES", ""), "STRICT_TRANS_TABLES", "")'; } if (!empty($sql)) { if (empty($this->options[PDO::MYSQL_ATTR_INIT_COMMAND])) { $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION sql_mode = ' . $sql; } else { $this->options[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', @@session.sql_mode = ' . $sql; } } } if ($this->compress === TRUE) { $this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE; } // SSL support was added to PDO_MYSQL in PHP 5.3.7 if (is_array($this->encrypt) && Core::isPHP('5.3.7')) { $ssl = array(); empty($this->encrypt['ssl_key']) or $ssl[PDO::MYSQL_ATTR_SSL_KEY] = $this->encrypt['ssl_key']; empty($this->encrypt['ssl_cert']) or $ssl[PDO::MYSQL_ATTR_SSL_CERT] = $this->encrypt['ssl_cert']; empty($this->encrypt['ssl_ca']) or $ssl[PDO::MYSQL_ATTR_SSL_CA] = $this->encrypt['ssl_ca']; empty($this->encrypt['ssl_capath']) or $ssl[PDO::MYSQL_ATTR_SSL_CAPATH] = $this->encrypt['ssl_capath']; empty($this->encrypt['ssl_cipher']) or $ssl[PDO::MYSQL_ATTR_SSL_CIPHER] = $this->encrypt['ssl_cipher']; // DO NOT use array_merge() here! // It re-indexes numeric keys and the PDO_MYSQL_ATTR_SSL_* constants are integers. empty($ssl) or $this->options += $ssl; } // Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails if (($pdo = parent::db_connect($persistent)) !== FALSE && !empty($ssl) && version_compare($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), '5.7.3', '<=') && empty($pdo->query("SHOW STATUS LIKE 'ssl_cipher'")->fetchObject()->Value)) { $message = 'PDO_MYSQL was configured for an SSL connection, but got an unencrypted connection instead!'; Logger::logError($message); return $this->db->db_debug ? $this->db->display_error($message, '', TRUE) : FALSE; } return $pdo; }
/** * The Module Callable. * * When a module listens for a specific routing path, this callable get's called. * After this the module can handle the request with the route() function in the module's root directory * * @param array Regex matches */ public static function moduleCallable($matches = array()) { // First detect what module is attached to this route Logger::newLevel('Module callable called!'); // Get the route $route = !empty($matches['route']) ? $matches['route'] : null; // See if the route exists if (isset(self::$module_routes[$route])) { Logger::log("Module '" . self::$module_routes[$route] . "' matched given route"); // Load the module $mod = self::get(self::$module_routes[$route]); unset($matches['route']); $mod->route($matches); } else { Logger::logError('Route did not match known module. Fatal error'); return Logger::http_error(500); } Logger::stopLevel(); }
/** * Get random bytes * * @param int $length Output length * @return string */ public function get_random_bytes($length) { if (empty($length) or !ctype_digit((string) $length)) { return FALSE; } if (function_exists('random_bytes')) { try { // The cast is required to avoid TypeError return random_bytes((int) $length); } catch (Exception $e) { // If random_bytes() can't do the job, we can't either ... // There's no point in using fallbacks. Logger::logError($e->getMessage()); return FALSE; } } // Unfortunately, none of the following PRNGs is guaranteed to exist ... if (defined('MCRYPT_DEV_URANDOM') && ($output = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)) !== FALSE) { return $output; } if (is_readable('/dev/urandom') && ($fp = fopen('/dev/urandom', 'rb')) !== FALSE) { // Try not to waste entropy ... Core::isPHP('5.4') && stream_set_chunk_size($fp, $length); $output = fread($fp, $length); fclose($fp); if ($output !== FALSE) { return $output; } } if (function_exists('openssl_random_pseudo_bytes')) { return openssl_random_pseudo_bytes($length); } return FALSE; }
/** * Constructor - Sets Email Preferences * * The constructor can be passed an array of config values * * @param array $config = array() * @return void */ public function __construct(array $config = array()) { $this->charset = Config::get('main')->charset; if (count($config) > 0) { $this->initialize($config); } else { $this->_smtp_auth = !($this->smtp_user === '' && $this->smtp_pass === ''); } $this->_safe_mode = !Core::isPHP('5.4') && ini_get('safe_mode'); $this->charset = strtoupper($this->charset); Logger::log('Email Class Initialized'); }
/** * 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; }
public function getPanel() { // If an error is thrown, log it $errfile = 'Unknown file'; $errstr = 'shutdown'; $errno = E_CORE_ERROR; $errline = 0; $error = error_get_last(); if ($error !== null) { $errno = $error['type']; $errfile = $error['file']; $errline = $error['line']; $errstr = $error['message']; // Log it! Logger::errorHandler($errno, $errstr, $errfile, $errline); } // Reverse the logs $logs = array_reverse(Logger::$Logs, true); // Parse the panel ob_start(function () { }); require dirname(__DIR__) . '/views/view.tracyloggerpanel.php'; return ob_get_clean(); }
/** * Disables the event system. */ public static function disable() { Logger::log('Disabled the Event system'); self::$enabled = false; }
/** * Class constructor * * Only present so that an error message is logged * if APC is not available. * * @return void */ public function __construct() { if (!$this->is_supported()) { Logger::logError('Cache: Failed to initialize APC; extension not loaded/enabled?'); } }
/** * 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; } } }
/** * Resets the layout manager to its default state. */ public static function reset() { if (!is_null(self::$current_engine)) { self::$current_engine->reset(); } // Unload the engines self::$engines = array(); self::$engines_loaded = false; self::$file_extensions = array(); self::$current_engine = null; self::$assigned_variables = array(); self::$directory = Core::$appDir . DS . 'Views'; Logger::log('Reset the layout manager to its default state'); }
/** * Non-persistent database connection * * @param bool $persistent * @return resource */ public function db_connect($persistent = FALSE) { $this->conn_id = $persistent ? mssql_pconnect($this->hostname, $this->username, $this->password) : mssql_connect($this->hostname, $this->username, $this->password); if (!$this->conn_id) { return FALSE; } // ---------------------------------------------------------------- // Select the DB... assuming a database name is specified in the config file if ($this->database !== '' && !$this->db_select()) { Logger::logError('Unable to select database: ' . $this->database); return $this->db_debug === TRUE ? $this->display_error('db_unable_to_select', $this->database) : FALSE; } // Determine how identifiers are escaped $query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi'); $query = $query->row_array(); $this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi']; $this->_escape_char = $this->_quoted_identifier ? '"' : array('[', ']'); return $this->conn_id; }
/** * Stored Procedure. Executes a stored procedure * * @param string package name in which the stored procedure is in * @param string stored procedure name to execute * @param array parameters * @return mixed * * params array keys * * KEY OPTIONAL NOTES * name no the name of the parameter should be in :<param_name> format * value no the value of the parameter. If this is an OUT or IN OUT parameter, * this should be a reference to a variable * type yes the type of the parameter * length yes the max size of the parameter */ public function stored_procedure($package, $procedure, array $params) { if ($package === '' or $procedure === '') { Logger::logError('Invalid query: ' . $package . '.' . $procedure); return $this->db_debug ? $this->display_error('db_invalid_query') : FALSE; } // Build the query string $sql = 'BEGIN ' . $package . '.' . $procedure . '('; $have_cursor = FALSE; foreach ($params as $param) { $sql .= $param['name'] . ','; if (isset($param['type']) && $param['type'] === OCI_B_CURSOR) { $have_cursor = TRUE; } } $sql = trim($sql, ',') . '); END;'; $this->_reset_stmt_id = FALSE; $this->stmt_id = oci_parse($this->conn_id, $sql); $this->_bind_params($params); $result = $this->query($sql, FALSE, $have_cursor); $this->_reset_stmt_id = TRUE; return $result; }
/** * Class constructor * * Setup Redis * * Loads Redis config file if present. Will halt execution * if a Redis connection can't be established. * * @return void * @see Redis::connect() */ public function __construct() { if (!$this->is_supported()) { Logger::logError('Cache: Failed to create Redis object; extension not loaded?'); return; } $config = array_merge(self::$_default_config, Config::get('cache')->redis); $this->_redis = new Redis(); try { if ($config['socket_type'] === 'unix') { $success = $this->_redis->connect($config['socket']); } else { $success = $this->_redis->connect($config['host'], $config['port'], $config['timeout']); } if (!$success) { Logger::logError('Cache: Redis connection failed. Check your configuration.'); } if (isset($config['password']) && !$this->_redis->auth($config['password'])) { Logger::logError('Cache: Redis authentication failed.'); } } catch (RedisException $e) { Logger::logError('Cache: Redis connection refused (' . $e->getMessage() . ')'); } // Initialize the index of serialized values. $serialized = $this->_redis->sMembers('_ci_redis_serialized'); empty($serialized) or $this->_serialized = array_flip($serialized); }
/** * Display an error message * * @param string the error message * @param string any "swap" values * @param bool whether to localize the message * @return string sends the application/views/errors/error_db.php template */ public function display_error($error = '', $swap = '', $native = FALSE) { // First load the language Language::get('db'); $heading = Language::line('db_error_heading'); if ($native === TRUE) { $message = (array) $error; } else { $message = is_array($error) ? $error : array(str_replace('%s', $swap, Language::line($error))); } // Find the most likely culprit of the error by going through // the backtrace until the source file is no longer in the // database folder. $trace = debug_backtrace(); foreach ($trace as $call) { if (isset($call['file'], $call['class'])) { // We'll need this on Windows, as APPPATH and BASEPATH will always use forward slashes if (DIRECTORY_SEPARATOR !== '/') { $call['file'] = str_replace('\\', '/', $call['file']); } if (strpos($call['file'], Core::$coreDir . DS . 'Database') === FALSE && strpos($call['class'], 'Loader') === FALSE) { // Found it - use a relative path for safety $message[] = 'Filename: ' . str_replace(array('Application', 'Core'), '', $call['file']); $message[] = 'Line Number: ' . $call['line']; break; } } } Logger::logError($heading); foreach ($message as $message) { Logger::logError($message); } Logger::http_error(500); exit(8); // EXIT_DATABASE }
/** * Class constructor * * Validates the DSN string and/or detects the subdriver. * * @param array $params * @return void */ public function __construct($params) { parent::__construct($params); if (preg_match('/([^:]+):/', $this->dsn, $match) && count($match) === 2) { // If there is a minimum valid dsn string pattern found, we're done // This is for general PDO users, who tend to have a full DSN string. $this->subdriver = $match[1]; return; } elseif (preg_match('/([^:]+):/', $this->hostname, $match) && count($match) === 2) { $this->dsn = $this->hostname; $this->hostname = NULL; $this->subdriver = $match[1]; return; } elseif (in_array($this->subdriver, array('mssql', 'sybase'), TRUE)) { $this->subdriver = 'dblib'; } elseif ($this->subdriver === '4D') { $this->subdriver = '4d'; } elseif (!in_array($this->subdriver, array('4d', 'cubrid', 'dblib', 'firebird', 'ibm', 'informix', 'mysql', 'oci', 'odbc', 'pgsql', 'sqlite', 'sqlsrv'), TRUE)) { Logger::logError('PDO: Invalid or non-existent subdriver'); if ($this->db_debug) { throw new DatabaseException('Invalid or non-existent PDO subdriver', 1); } } $this->dsn = NULL; }
/** * Stop FuzeWorks and run all shutdown functions. * * Afterwards run the Logger shutdown function in order to possibly display the log */ public static function shutdown() { // Fix Apache bug where CWD is changed upon shutdown chdir(self::$cwd); // Fire the Shutdown event $event = Events::fireEvent('coreShutdownEvent'); if ($event->isCancelled() === false) { // If the output should be displayed, send the final render and parse the logger Logger::shutdownError(); Factory::getInstance()->output->_display(); Logger::shutdown(); } }