6249535f47918677b53f3c5d4faf0b9567a2807c
[core.git] / framework / 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 = sprintf(
38         '%sframework/database/lib-%s.php',
39         FrameworkConfiguration::getSelfInstance()->getConfigEntry('base_path'),
40         FrameworkConfiguration::getSelfInstance()->getConfigEntry('db_type')
41 );
42
43 // Load the database layer include
44 if (BaseFrameworkSystem::isReadableFile($fqfn)) {
45         // Load the layer
46         require($fqfn);
47 } else {
48         // Layer is missing!
49         ApplicationEntryPoint::app_exit(sprintf('[Main:] Database layer is missing! (%s) -&gt; R.I.P.',
50                 FrameworkConfiguration::getSelfInstance()->getConfigEntry('db_type')
51         ));
52 }
53
54 // Clean it up
55 unset($fqfn);
56
57 // Prepare database instance
58 $connectionInstance = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getSelfInstance(), $databaseInstance);
59
60 // Is the app variable there and valid?
61 // @TODO Rewrite this
62 if (is_object($app)) {
63         $app->setDatabaseInstance($connectionInstance);
64 } // END - if