Finished first cleanup (still a lot is broken):
[core.git] / inc / includes.php
1 <?php
2 // Import framework stuff
3 use CoreFramework\Configuration\FrameworkConfiguration;
4 use CoreFramework\Loader\ClassLoader;
5
6 /**
7  * Loads more include files by using the generic class loader
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 // Include the class loader function
32 require(FrameworkConfiguration::getSelfInstance()->getConfigEntry('base_path') . 'inc/loader/class_ClassLoader.php');
33
34 /*
35  * Shall we include additional configs where you can configure some things?
36  * Then load matching config file.
37  */
38 ClassLoader::getSelfInstance()->loadExtraConfigs();
39
40 // Register auto-load function with the SPL
41 // @TODO This makes the core depending on the SPL. But it should be installed anyway.
42 spl_autoload_register('CoreFramework\Loader\ClassLoader::autoLoad');
43
44 // Does the user has an application specified?
45 // @TODO Find a nicer OOP-ed way for this
46 if (!empty($_GET['app'])) {
47         // Set the application from string
48         $application = (string) $_GET['app'];
49 } elseif (!empty($_SERVER['argv'][1])) {
50         // Set the application from string
51         $application = (string) $_SERVER['argv'][1];
52         $app = explode('=', trim($application));
53         if ($app[0] == 'app') {
54                 // Application is valid!
55                 $application = trim($app[1]);
56         } else {
57                 // Invalid entry found, first must be "app"!
58                 $application = FrameworkConfiguration::getSelfInstance()->getConfigEntry('default_application');
59         }
60 } else {
61         // Set the "application selector" application
62         $application = FrameworkConfiguration::getSelfInstance()->getConfigEntry('default_application');
63 }
64
65 // Secure it, by keeping out tags
66 $application = htmlentities(strip_tags($application), ENT_QUOTES);
67
68 // Secure it a little more with a reg.exp.
69 $application = preg_replace('/([^a-z0-9_-])+/i', '', $application);
70
71 // Set the application name for later usage
72 FrameworkConfiguration::getSelfInstance()->setConfigEntry('app_name', $application);
73
74 // Scan for all framework classes, exceptions and interfaces
75 ClassLoader::scanFrameworkClasses();