1: <?php
2: /**
3: * You may not change or alter any portion of this comment or credits
4: * of supporting developers from this source code or any supporting source code
5: * which is considered copyrighted (c) material of the original comment or credit authors.
6: *
7: * This program is distributed in the hope that it will be useful,
8: * but WITHOUT ANY WARRANTY; without even the implied warranty of
9: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: use Xoops\Core\Database\Factory;
13:
14: /**
15: * XoopsDatabaseFactory class
16: *
17: * PHP version 5.3
18: *
19: * @category Xoops\Class\Database\Factory
20: * @package DatabaseFactory
21: * @author Kazumi Ono <onokazu@xoops.org>
22: * @author readheadedrod <redheadedrod@hotmail.com>
23: * @copyright 2013-2014 XOOPS Project (http://xoops.org)
24: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
25: * @version Release:2.6
26: * @link http://xoops.org
27: * @since 2.6.0
28: */
29: class XoopsDatabaseFactory extends Factory
30: {
31:
32: /**
33: * Get a reference to the only instance of database class and connects to DB
34: *
35: * if the class has not been instantiated yet, this will also take
36: * care of that
37: *
38: * Legacy support function
39: *
40: * NOTE: Persistance connection is not supported nor needed with Doctrine.
41: * XOOPS_DB_PCONNECT is ignored.
42: *
43: * @return XoopsDatabase Reference to the only instance of database class
44: */
45: public static function getDatabaseConnection()
46: {
47: static $legacy;
48:
49: $file = \XoopsBaseConfig::get('root-path') . '/class/database/mysqldatabase.php';
50: if (!isset($legacy) && file_exists($file)) {
51: require_once $file;
52: if (!defined('XOOPS_DB_PROXY')) {
53: $class = 'XoopsMysqlDatabaseSafe';
54: } else {
55: $class = 'XoopsMysqlDatabaseProxy';
56: }
57: \Xoops::getInstance()->events()->triggerEvent('core.class.database.databasefactory.connection', array(&$class));
58: $legacy = new $class();
59: $legacy->setPrefix(\XoopsBaseConfig::get('db-prefix'));
60: $legacy->conn = \Xoops\Core\Database\Factory::getConnection();
61: }
62: if (is_null($legacy->conn)) {
63: trigger_error('notrace:Unable to connect to database', E_USER_ERROR);
64: }
65: return $legacy;
66: }
67: }
68: