1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-10 18:54:08 +02:00

[ticket/11015] Make DBAL classes autoloadable

PHPBB3-11015

This allows us to just create the object without having to include the
driver first. However, it also means that users must specify the full
class name in config.php
This commit is contained in:
Igor Wiedler
2012-07-21 17:43:43 +02:00
parent f7f78adeb9
commit 90a957ad26
26 changed files with 1129 additions and 1189 deletions

View File

@@ -33,7 +33,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
$db_config = $this->get_database_config();
// Firebird requires table and column names to be uppercase
if ($db_config['dbms'] == 'firebird')
if ($db_config['dbms'] == 'phpbb_db_driver_firebird')
{
$xml_data = file_get_contents($path);
$xml_data = preg_replace_callback('/(?:(<table name="))([a-z_]+)(?:(">))/', 'phpbb_database_test_case::to_upper', $xml_data);
@@ -100,9 +100,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
$config = $this->get_database_config();
require_once dirname(__FILE__) . '/../../phpBB/includes/db/' . $config['dbms'] . '.php';
$dbal = 'dbal_' . $config['dbms'];
$db = new $dbal();
$dbms = $config['dbms'];
$db = new $dbms();
$db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']);
return $db;

View File

@@ -108,7 +108,7 @@ class phpbb_database_test_connection_manager
// These require different connection strings on the phpBB side than they do in PDO
// so you must provide a DSN string for ODBC separately
if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'mssql' || $this->config['dbms'] == 'firebird'))
if (!empty($this->config['custom_dsn']) && ($this->config['dbms'] == 'phpbb_db_driver_mssql' || $this->config['dbms'] == 'phpbb_db_driver_firebird'))
{
$dsn = 'odbc:' . $this->config['custom_dsn'];
}
@@ -117,12 +117,12 @@ class phpbb_database_test_connection_manager
{
switch ($this->config['dbms'])
{
case 'mssql':
case 'mssql_odbc':
case 'phpbb_db_driver_mssql':
case 'phpbb_db_driver_mssql_odbc':
$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('mssql', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
break;
case 'firebird':
case 'phpbb_db_driver_firebird':
if (!empty($this->config['custom_dsn']))
{
$this->pdo = new phpbb_database_connection_odbc_pdo_wrapper('firebird', 0, $dsn, $this->config['dbuser'], $this->config['dbpasswd']);
@@ -165,14 +165,14 @@ class phpbb_database_test_connection_manager
{
switch ($this->config['dbms'])
{
case 'sqlite':
case 'phpbb_db_driver_sqlite':
if (file_exists($this->config['dbhost']))
{
unlink($this->config['dbhost']);
}
break;
case 'firebird':
case 'phpbb_db_driver_firebird':
$this->connect();
// Drop all of the tables
foreach ($this->get_tables() as $table)
@@ -182,7 +182,7 @@ class phpbb_database_test_connection_manager
$this->purge_extras();
break;
case 'oracle':
case 'phpbb_db_driver_oracle':
$this->connect();
// Drop all of the tables
foreach ($this->get_tables() as $table)
@@ -232,39 +232,39 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms'])
{
case 'mysql':
case 'mysql4':
case 'mysqli':
case 'phpbb_db_driver_mysql':
case 'phpbb_db_driver_mysql4':
case 'phpbb_db_driver_mysqli':
$sql = 'SHOW TABLES';
break;
case 'sqlite':
case 'phpbb_db_driver_sqlite':
$sql = 'SELECT name
FROM sqlite_master
WHERE type = "table"';
break;
case 'mssql':
case 'mssql_odbc':
case 'mssqlnative':
case 'phpbb_db_driver_mssql':
case 'phpbb_db_driver_mssql_odbc':
case 'phpbb_db_driver_mssqlnative':
$sql = "SELECT name
FROM sysobjects
WHERE type='U'";
break;
case 'postgres':
case 'phpbb_db_driver_postgres':
$sql = 'SELECT relname
FROM pg_stat_user_tables';
break;
case 'firebird':
case 'phpbb_db_driver_firebird':
$sql = 'SELECT rdb$relation_name
FROM rdb$relations
WHERE rdb$view_source is null
AND rdb$system_flag = 0';
break;
case 'oracle':
case 'phpbb_db_driver_oracle':
$sql = 'SELECT table_name
FROM USER_TABLES';
break;
@@ -299,8 +299,8 @@ class phpbb_database_test_connection_manager
protected function load_schema_from_file($directory)
{
$schema = $this->dbms['SCHEMA'];
if ($this->config['dbms'] == 'mysql')
if ($this->config['dbms'] == 'phpbb_db_driver_mysql')
{
$sth = $this->pdo->query('SELECT VERSION() AS version');
$row = $sth->fetch(PDO::FETCH_ASSOC);
@@ -319,7 +319,7 @@ class phpbb_database_test_connection_manager
$queries = file_get_contents($filename);
$sql = phpbb_remove_comments($queries);
$sql = split_sql_file($sql, $this->dbms['DELIM']);
foreach ($sql as $query)
@@ -403,7 +403,7 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms'])
{
case 'firebird':
case 'phpbb_db_driver_firebird':
$sql = 'SELECT RDB$GENERATOR_NAME
FROM RDB$GENERATORS
WHERE RDB$SYSTEM_FLAG = 0';
@@ -415,7 +415,7 @@ class phpbb_database_test_connection_manager
}
break;
case 'oracle':
case 'phpbb_db_driver_oracle':
$sql = 'SELECT sequence_name
FROM USER_SEQUENCES';
$result = $this->pdo->query($sql);

View File

@@ -87,12 +87,8 @@ class phpbb_functional_test_case extends phpbb_test_case
// so we don't reopen an open connection
if (!($this->db instanceof dbal))
{
if (!class_exists('dbal_' . self::$config['dbms']))
{
include($phpbb_root_path . 'includes/db/' . self::$config['dbms'] . ".$phpEx");
}
$sql_db = 'dbal_' . self::$config['dbms'];
$this->db = new $sql_db();
$dbms = self::$config['dbms'];
$this->db = new $dbms();
$this->db->sql_connect(self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']);
}
return $this->db;

View File

@@ -54,7 +54,7 @@ class phpbb_test_case_helpers
if (extension_loaded('sqlite') && version_compare(PHPUnit_Runner_Version::id(), '3.4.15', '>='))
{
$config = array_merge($config, array(
'dbms' => 'sqlite',
'dbms' => 'phpbb_db_driver_sqlite',
'dbhost' => dirname(__FILE__) . '/../phpbb_unit_tests.sqlite2', // filename
'dbport' => '',
'dbname' => '',