]> git.mxchange.org Git - core.git/blob - inc/database.php
Continued:
[core.git] / inc / database.php
1 <?php
2 // Import framework stuff
3 use CoreFramework\Configuration\FrameworkConfiguration;
4 use CoreFramework\Object\BaseFrameworkSystem;
5
6 /**
7  * Initializes the database layer
8  *
9  * @author              Roland Haeder <webmaster@shipsimu.org>
10  * @version             0.0.0
11  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
12  * @license             GNU GPL 3.0 or any newer version
13  * @link                http://www.shipsimu.org
14  * @deprecated
15  * @todo                Minimize these includes
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program. If not, see <http://www.gnu.org/licenses/>.
29  */
30
31 // Initialize database layer
32 $databaseInstance = NULL;
33
34 // Generate FQFN for the database layer
35 $fqfn = FrameworkConfiguration::getSelfInstance()->getConfigEntry('base_path') . 'inc/database/lib-' . FrameworkConfiguration::getSelfInstance()->getConfigEntry('db_type') . '.php';
36
37 // Load the database layer include
38 if (BaseFrameworkSystem::isReadableFile($fqfn)) {
39         // Load the layer
40         require($fqfn);
41 } else {
42         // Layer is missing!
43         ApplicationEntryPoint::app_exit(sprintf('[Main:] Database layer is missing! (%s) -&gt; R.I.P.',
44                 FrameworkConfiguration::getSelfInstance()->getConfigEntry('db_type')
45         ));
46 }
47
48 // Clean it up
49 unset($fqfn);
50
51 // Prepare database instance
52 $connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getSelfInstance(), $databaseInstance);
53
54 // Is the app variable there and valid?
55 // @TODO Rewrite this
56 if (is_object($app)) $app->setDatabaseInstance($connectionInstance);