diff --git a/src/mibew/install/migrate.php b/src/mibew/install/migrate.php index 071e155e..2dda441f 100644 --- a/src/mibew/install/migrate.php +++ b/src/mibew/install/migrate.php @@ -17,7 +17,7 @@ require_once(dirname(dirname(__FILE__)).'/libs/init.php'); -$db = Database::getInstance(); +$db = \Mibew\Database::getInstance(); $db->throwExeptions(true); diff --git a/src/mibew/libs/canned.php b/src/mibew/libs/canned.php index 603e1678..4b9ac1c7 100644 --- a/src/mibew/libs/canned.php +++ b/src/mibew/libs/canned.php @@ -15,6 +15,9 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + function load_canned_messages($locale, $groupid) { $db = Database::getInstance(); diff --git a/src/mibew/libs/chat.php b/src/mibew/libs/chat.php index 5cb6d3a0..c2f305cf 100644 --- a/src/mibew/libs/chat.php +++ b/src/mibew/libs/chat.php @@ -16,6 +16,7 @@ */ // Import namespaces and classes of the core +use Mibew\Database; use Mibew\Settings; // Initialize libraries diff --git a/src/mibew/libs/classes/database.php b/src/mibew/libs/classes/Mibew/Database.php similarity index 92% rename from src/mibew/libs/classes/database.php rename to src/mibew/libs/classes/Mibew/Database.php index 7180be97..624ded5c 100644 --- a/src/mibew/libs/classes/database.php +++ b/src/mibew/libs/classes/Mibew/Database.php @@ -15,6 +15,8 @@ * limitations under the License. */ +namespace Mibew; + /** * Encapsulates work with database. Implenets singleton pattern to provide only * one instance. @@ -35,7 +37,7 @@ Class Database{ /** * PDO object - * @var PDO + * @var \PDO */ protected $dbh = NULL; @@ -155,16 +157,16 @@ Class Database{ public static function initialize($host, $user, $pass, $use_pconn, $db, $prefix, $force_charset = false, $encoding = 'utf8') { // Check PDO if (! extension_loaded('PDO')) { - throw new Exception('PDO extension is not loaded'); + throw new \Exception('PDO extension is not loaded'); } if (! extension_loaded('pdo_mysql')) { - throw new Exception('pdo_mysql extension is not loaded'); + throw new \Exception('pdo_mysql extension is not loaded'); } // Check if initialization if (! is_null(self::$instance)) { - throw new Exception('Database already initialized'); + throw new \Exception('Database already initialized'); } // Create database instance @@ -181,11 +183,11 @@ Class Database{ $instance->usePersistentConnection = $use_pconn; // Create PDO object - $instance->dbh = new PDO( + $instance->dbh = new \PDO( "mysql:host={$instance->dbHost};dbname={$instance->dbName}", $instance->dbLogin, $instance->dbPass, - array(PDO::ATTR_PERSISTENT => $instance->usePersistentConnection) + array(\PDO::ATTR_PERSISTENT => $instance->usePersistentConnection) ); if ($instance->forceCharsetInConnection) { @@ -208,9 +210,9 @@ Class Database{ /** * Handles errors - * @param Exception $e + * @param \Exception $e */ - protected function handleError(Exception $e){ + protected function handleError(\Exception $e){ if ($this->throwExceptions) { throw $e; } @@ -299,7 +301,7 @@ Class Database{ // Check if error occurs if ($this->preparedStatements[$query_key]->errorCode() !== '00000') { $errorInfo = $this->preparedStatements[$query_key]->errorInfo(); - throw new Exception(' Query failed: ' . $errorInfo[2]); + throw new \Exception(' Query failed: ' . $errorInfo[2]); } // No need to return rows @@ -315,16 +317,16 @@ Class Database{ } switch($params['fetch_type']){ case Database::FETCH_NUM: - $fetch_type = PDO::FETCH_NUM; + $fetch_type = \PDO::FETCH_NUM; break; case Database::FETCH_ASSOC: - $fetch_type = PDO::FETCH_ASSOC; + $fetch_type = \PDO::FETCH_ASSOC; break; case Database::FETCH_BOTH: - $fetch_type = PDO::FETCH_BOTH; + $fetch_type = \PDO::FETCH_BOTH; break; default: - throw new Exception("Unknown 'fetch_type' value!"); + throw new \Exception("Unknown 'fetch_type' value!"); } // Get results @@ -334,12 +336,12 @@ Class Database{ } elseif ($params['return_rows'] == Database::RETURN_ALL_ROWS) { $rows = $this->preparedStatements[$query_key]->fetchAll($fetch_type); } else { - throw new Exception("Unknown 'return_rows' value!"); + throw new \Exception("Unknown 'return_rows' value!"); } $this->preparedStatements[$query_key]->closeCursor(); return $rows; - } catch(Exception $e) { + } catch(\Exception $e) { $this->handleError($e); } } @@ -348,7 +350,7 @@ Class Database{ * Returns value of PDOStatement::$errorInfo property for last query * @return string Error info array * - * @see PDOStatement::$erorrInfo + * @see \PDOStatement::$erorrInfo */ public function errorInfo(){ if (is_null($this->lastQuery)) { @@ -356,7 +358,7 @@ Class Database{ } try{ $errorInfo = $this->preparedStatements[$this->lastQuery]->errorInfo(); - } catch (Exception $e) { + } catch (\Exception $e) { $this->handleError($e); } return $errorInfo; @@ -370,7 +372,7 @@ Class Database{ public function insertedId(){ try{ $lastInsertedId = $this->dbh->lastInsertId(); - } catch(Exception $e) { + } catch(\Exception $e) { $this->handleError($e); } return $lastInsertedId; @@ -387,7 +389,7 @@ Class Database{ } try{ $affected_rows = $this->preparedStatements[$this->lastQuery]->rowCount(); - } catch(Exception $e) { + } catch(\Exception $e) { $this->handleError($e); } return $affected_rows; diff --git a/src/mibew/libs/classes/Mibew/Settings.php b/src/mibew/libs/classes/Mibew/Settings.php index a04e5ed5..517683a0 100644 --- a/src/mibew/libs/classes/Mibew/Settings.php +++ b/src/mibew/libs/classes/Mibew/Settings.php @@ -17,9 +17,6 @@ namespace Mibew; -// Import namespaces and classes of the core -use \Database; - /** * Encapsulates work with system settings. */ diff --git a/src/mibew/libs/classes/client_side_processor.php b/src/mibew/libs/classes/client_side_processor.php index 9585e685..290c5b35 100644 --- a/src/mibew/libs/classes/client_side_processor.php +++ b/src/mibew/libs/classes/client_side_processor.php @@ -15,6 +15,9 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + /** * Base class for all request processors that interact with JavaScript * applications at the client side. diff --git a/src/mibew/libs/classes/request_processor.php b/src/mibew/libs/classes/request_processor.php index 8f6b64fc..0e31fe6c 100644 --- a/src/mibew/libs/classes/request_processor.php +++ b/src/mibew/libs/classes/request_processor.php @@ -15,6 +15,9 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + /** * Implements abstract class for request processing * diff --git a/src/mibew/libs/classes/thread.php b/src/mibew/libs/classes/thread.php index f249f4d8..81340fb0 100644 --- a/src/mibew/libs/classes/thread.php +++ b/src/mibew/libs/classes/thread.php @@ -16,6 +16,7 @@ */ // Import namespaces and classes of the core +use Mibew\Database; use Mibew\Settings; /** diff --git a/src/mibew/libs/classes/users_processor.php b/src/mibew/libs/classes/users_processor.php index 340e9824..fb780a6a 100644 --- a/src/mibew/libs/classes/users_processor.php +++ b/src/mibew/libs/classes/users_processor.php @@ -16,6 +16,7 @@ */ // Import namespaces and classes of the core +use Mibew\Database; use Mibew\Settings; /** diff --git a/src/mibew/libs/groups.php b/src/mibew/libs/groups.php index 8db0e9de..7a72dd67 100644 --- a/src/mibew/libs/groups.php +++ b/src/mibew/libs/groups.php @@ -16,6 +16,7 @@ */ // Import namespaces and classes of the core +use Mibew\Database; use Mibew\Settings; function group_by_id($id) diff --git a/src/mibew/libs/init.php b/src/mibew/libs/init.php index 52472fa9..9693ed13 100644 --- a/src/mibew/libs/init.php +++ b/src/mibew/libs/init.php @@ -37,7 +37,6 @@ require_once(MIBEW_FS_ROOT.'/libs/common/autoload.php'); spl_autoload_register('class_autoload'); // Include system classes -require_once(MIBEW_FS_ROOT.'/libs/classes/database.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/event_dispatcher.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/plugin_manager.php'); require_once(MIBEW_FS_ROOT.'/libs/classes/plugin.php'); @@ -66,7 +65,7 @@ if (is_secure_request()) { session_start(); // Initialize the database -Database::initialize( +\Mibew\Database::initialize( $mysqlhost, $mysqllogin, $mysqlpass, diff --git a/src/mibew/libs/invitation.php b/src/mibew/libs/invitation.php index 07dd8196..7be20eb6 100644 --- a/src/mibew/libs/invitation.php +++ b/src/mibew/libs/invitation.php @@ -16,6 +16,7 @@ */ // Import namespaces and classes of the core +use Mibew\Database; use Mibew\Settings; /** diff --git a/src/mibew/libs/operator.php b/src/mibew/libs/operator.php index 8c4c8a94..182acfc6 100644 --- a/src/mibew/libs/operator.php +++ b/src/mibew/libs/operator.php @@ -16,6 +16,7 @@ */ // Import namespaces and classes of the core +use Mibew\Database; use Mibew\Settings; /** diff --git a/src/mibew/libs/pagination.php b/src/mibew/libs/pagination.php index 4c08a2ee..247cca7c 100644 --- a/src/mibew/libs/pagination.php +++ b/src/mibew/libs/pagination.php @@ -15,6 +15,9 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + $pagination_spacing = "   "; $links_on_page = 5; @@ -82,9 +85,9 @@ function setup_pagination($items, $default_items_per_page = 15) * @param string $order Order clause * @param string $countfields Field, substituted in SQL COUNT function * @param array $values Associative array of substituted values. Keys are named placeholders in the - * query(see Database::query() and its $values parameter description) + * query(see \Mibew\Database::query() and its $values parameter description) * - * @see Database::query() + * @see \Mibew\Database::query() */ function select_with_pagintation($fields, $table, $conditions, $order, $countfields, $values) { diff --git a/src/mibew/libs/statistics.php b/src/mibew/libs/statistics.php index 1ba2cd56..ab03a434 100644 --- a/src/mibew/libs/statistics.php +++ b/src/mibew/libs/statistics.php @@ -16,6 +16,7 @@ */ // Import namespaces and classes of the core +use Mibew\Database; use Mibew\Settings; function get_statistics_query($type) diff --git a/src/mibew/libs/track.php b/src/mibew/libs/track.php index 29c77945..4aa8f487 100644 --- a/src/mibew/libs/track.php +++ b/src/mibew/libs/track.php @@ -16,6 +16,7 @@ */ // Import namespaces and classes of the core +use Mibew\Database; use Mibew\Settings; // Initialize libraries diff --git a/src/mibew/operator/ban.php b/src/mibew/operator/ban.php index af924ba6..cd7da435 100644 --- a/src/mibew/operator/ban.php +++ b/src/mibew/operator/ban.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/chat.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); diff --git a/src/mibew/operator/blocked.php b/src/mibew/operator/blocked.php index bd6f8800..7818c12d 100644 --- a/src/mibew/operator/blocked.php +++ b/src/mibew/operator/blocked.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/chat.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); diff --git a/src/mibew/operator/canned.php b/src/mibew/operator/canned.php index 3a57d774..883955fa 100644 --- a/src/mibew/operator/canned.php +++ b/src/mibew/operator/canned.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/canned.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); diff --git a/src/mibew/operator/group.php b/src/mibew/operator/group.php index c811db9b..8a69582d 100644 --- a/src/mibew/operator/group.php +++ b/src/mibew/operator/group.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); require_once(MIBEW_FS_ROOT.'/libs/groups.php'); diff --git a/src/mibew/operator/groupmembers.php b/src/mibew/operator/groupmembers.php index 93da0559..6d2c84d1 100644 --- a/src/mibew/operator/groupmembers.php +++ b/src/mibew/operator/groupmembers.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); require_once(MIBEW_FS_ROOT.'/libs/groups.php'); diff --git a/src/mibew/operator/groups.php b/src/mibew/operator/groups.php index e1aaf543..dd991d55 100644 --- a/src/mibew/operator/groups.php +++ b/src/mibew/operator/groups.php @@ -16,6 +16,7 @@ */ // Import namespaces and classes of the core +use Mibew\Database; use Mibew\Settings; // Initialize libraries diff --git a/src/mibew/operator/history.php b/src/mibew/operator/history.php index e76e5b6b..e137b906 100644 --- a/src/mibew/operator/history.php +++ b/src/mibew/operator/history.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); require_once(MIBEW_FS_ROOT.'/libs/chat.php'); diff --git a/src/mibew/operator/operators.php b/src/mibew/operator/operators.php index c0d80f92..640fa1cb 100644 --- a/src/mibew/operator/operators.php +++ b/src/mibew/operator/operators.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); require_once(MIBEW_FS_ROOT.'/libs/interfaces/style.php'); diff --git a/src/mibew/operator/opgroups.php b/src/mibew/operator/opgroups.php index aadb89bf..115f12a5 100644 --- a/src/mibew/operator/opgroups.php +++ b/src/mibew/operator/opgroups.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); require_once(MIBEW_FS_ROOT.'/libs/operator_settings.php'); diff --git a/src/mibew/operator/redirect.php b/src/mibew/operator/redirect.php index aae2acef..39198c85 100644 --- a/src/mibew/operator/redirect.php +++ b/src/mibew/operator/redirect.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); require_once(MIBEW_FS_ROOT.'/libs/chat.php'); diff --git a/src/mibew/operator/resetpwd.php b/src/mibew/operator/resetpwd.php index 7238f5e9..d5add122 100644 --- a/src/mibew/operator/resetpwd.php +++ b/src/mibew/operator/resetpwd.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); require_once(MIBEW_FS_ROOT.'/libs/settings.php'); diff --git a/src/mibew/operator/restore.php b/src/mibew/operator/restore.php index 614ef678..ed2ba094 100644 --- a/src/mibew/operator/restore.php +++ b/src/mibew/operator/restore.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); require_once(MIBEW_FS_ROOT.'/libs/settings.php'); diff --git a/src/mibew/operator/statistics.php b/src/mibew/operator/statistics.php index 5312eeb1..67096b6c 100644 --- a/src/mibew/operator/statistics.php +++ b/src/mibew/operator/statistics.php @@ -16,6 +16,7 @@ */ // Import namespaces and classes of the core +use Mibew\Database; use Mibew\Settings; // Initialize libraries diff --git a/src/mibew/operator/threadprocessor.php b/src/mibew/operator/threadprocessor.php index 9fdd1215..0225781f 100644 --- a/src/mibew/operator/threadprocessor.php +++ b/src/mibew/operator/threadprocessor.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); require_once(MIBEW_FS_ROOT.'/libs/chat.php'); diff --git a/src/mibew/operator/userhistory.php b/src/mibew/operator/userhistory.php index 46681112..3b471f84 100644 --- a/src/mibew/operator/userhistory.php +++ b/src/mibew/operator/userhistory.php @@ -15,6 +15,10 @@ * limitations under the License. */ +// Import namespaces and classes of the core +use Mibew\Database; + +// Initialize libraries require_once(dirname(dirname(__FILE__)).'/libs/init.php'); require_once(MIBEW_FS_ROOT.'/libs/operator.php'); require_once(MIBEW_FS_ROOT.'/libs/chat.php');