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