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