aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb
diff options
context:
space:
mode:
authorTristan Darricau <github@nicofuma.fr>2014-06-29 21:58:17 +0200
committerTristan Darricau <github@nicofuma.fr>2014-07-07 01:02:40 +0200
commited812a9dfb59b1eb83263adbaa52723ff826a791 (patch)
treec75d2136fa2486fb994dbddb8b7fa88401237e44 /phpBB/phpbb
parent98e8be966bd8174c2a3f4e8fb80167b23573441f (diff)
downloadforums-ed812a9dfb59b1eb83263adbaa52723ff826a791.tar
forums-ed812a9dfb59b1eb83263adbaa52723ff826a791.tar.gz
forums-ed812a9dfb59b1eb83263adbaa52723ff826a791.tar.bz2
forums-ed812a9dfb59b1eb83263adbaa52723ff826a791.tar.xz
forums-ed812a9dfb59b1eb83263adbaa52723ff826a791.zip
[ticket/12775] Move phpbb_convert_30_dbms_to_31 into the config file class
PHPBB3-12775
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r--phpBB/phpbb/config_php_file.php47
-rw-r--r--phpBB/phpbb/di/container_builder.php2
-rw-r--r--phpBB/phpbb/di/extension/config.php2
3 files changed, 49 insertions, 2 deletions
diff --git a/phpBB/phpbb/config_php_file.php b/phpBB/phpbb/config_php_file.php
index ba8d3a0d9d..c0aa3567e6 100644
--- a/phpBB/phpbb/config_php_file.php
+++ b/phpBB/phpbb/config_php_file.php
@@ -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");
+ }
}
diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php
index fbbe736e47..95b82b26c7 100644
--- a/phpBB/phpbb/di/container_builder.php
+++ b/phpBB/phpbb/di/container_builder.php
@@ -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'),
diff --git a/phpBB/phpbb/di/extension/config.php b/phpBB/phpbb/di/extension/config.php
index ec2d7f6e44..27ebc94bae 100644
--- a/phpBB/phpbb/di/extension/config.php
+++ b/phpBB/phpbb/di/extension/config.php
@@ -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'));