1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-14 12:44:06 +02:00

[ticket/12775] Move phpbb_convert_30_dbms_to_31 into the config file class

PHPBB3-12775
This commit is contained in:
Tristan Darricau
2014-06-29 21:58:17 +02:00
parent 98e8be966b
commit ed812a9dfb
10 changed files with 73 additions and 72 deletions

View File

@@ -124,4 +124,51 @@ class config_php_file
return true;
}
/**
* Convert either 3.0 dbms or 3.1 db driver class name to 3.1 db driver class name.
*
* If $dbms is a valid 3.1 db driver class name, returns it unchanged.
* Otherwise prepends phpbb\db\driver\ to the dbms to convert a 3.0 dbms
* to 3.1 db driver class name.
*
* @param string $dbms dbms parameter
* @return string driver class
* @throws \RuntimeException
*/
public function convert_30_dbms_to_31($dbms)
{
// Note: this check is done first because mysqli extension
// supplies a mysqli class, and class_exists($dbms) would return
// true for mysqli class.
// However, per the docblock any valid 3.1 driver name should be
// recognized by this function, and have priority over 3.0 dbms.
if (strpos($dbms, 'phpbb\db\driver') === false && class_exists('phpbb\db\driver\\' . $dbms))
{
return 'phpbb\db\driver\\' . $dbms;
}
if (class_exists($dbms))
{
// Additionally we could check that $dbms extends phpbb\db\driver\driver.
// http://php.net/manual/en/class.reflectionclass.php
// Beware of possible performance issues:
// http://stackoverflow.com/questions/294582/php-5-reflection-api-performance
// We could check for interface implementation in all paths or
// only when we do not prepend phpbb\db\driver\.
/*
$reflection = new \ReflectionClass($dbms);
if ($reflection->isSubclassOf('phpbb\db\driver\driver'))
{
return $dbms;
}
*/
return $dbms;
}
throw new \RuntimeException("You have specified an invalid dbms driver: $dbms");
}
}

View File

@@ -302,7 +302,7 @@ class container_builder
{
if ($this->dbal_connection === null)
{
$dbal_driver_class = phpbb_convert_30_dbms_to_31($this->config_php_handler->get('dbms'));
$dbal_driver_class = $this->config_php_handler->convert_30_dbms_to_31($this->config_php_handler->get('dbms'));
$this->dbal_connection = new $dbal_driver_class();
$this->dbal_connection->sql_connect(
$this->config_php_handler->get('dbhost'),

View File

@@ -42,7 +42,7 @@ class config extends Extension
$container->setParameter('core.adm_relative_path', ($this->config_php->get('phpbb_adm_relative_path') ? $this->config_php->get('phpbb_adm_relative_path') : 'adm/'));
$container->setParameter('core.table_prefix', $this->config_php->get('table_prefix'));
$container->setParameter('cache.driver.class', $this->convert_30_acm_type($this->config_php->get('acm_type')));
$container->setParameter('dbal.driver.class', phpbb_convert_30_dbms_to_31($this->config_php->get('dbms')));
$container->setParameter('dbal.driver.class', $this->config_php->convert_30_dbms_to_31($this->config_php->get('dbms')));
$container->setParameter('dbal.dbhost', $this->config_php->get('dbhost'));
$container->setParameter('dbal.dbuser', $this->config_php->get('dbuser'));
$container->setParameter('dbal.dbpasswd', $this->config_php->get('dbpasswd'));