3 * The application selector main include file
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 // Does the user has an application specified?
26 if (!empty($_GET[FrameworkConfiguration::getInstance()->readConfig('app_selector_get')])) {
27 // Set the application from string
28 $application = (string) $_GET[FrameworkConfiguration::getInstance()->readConfig('app_selector_get')];
29 } elseif (!empty($_SERVER['argv'][1])) {
30 // Set the application from string
31 $application = (string) $_SERVER['argv'][1];
32 $app = explode('=', trim($application));
33 if ($app[0] == FrameworkConfiguration::getInstance()->readConfig('app_selector_get')) {
34 // Application is valid!
35 $application = trim($app[1]);
37 // Invalid entry found, first must be "app"!
38 $application = FrameworkConfiguration::getInstance()->readConfig('default_application');
41 // Set the "application selector" application
42 $application = FrameworkConfiguration::getInstance()->readConfig('default_application');
45 // Secure it, by keeping out tags
46 $application = htmlentities(strip_tags($application), ENT_QUOTES);
48 // Secure it a little more with a reg.exp.
49 $application = preg_replace('/([^a-z_-])+/i', "", $application);
51 // Try to load these includes in the given order
52 $configAppIncludes = array(
53 sprintf("class_%s", FrameworkConfiguration::getInstance()->readConfig('app_helper_class')), // The ApplicationHelper class
54 "config", // The application's own configuration
55 "init", // The application initializer
56 "loader", // The application's class loader
57 "debug", // Some debugging stuff
58 "exceptions", // The application's own exception handler
59 "starter", // The application starter (calls entryPoint(), etc.)
62 // Load them all (try only)
63 foreach ($configAppIncludes as $inc) {
64 // Skip starter in test mode
65 if (($inc == "starter") && (defined('TEST'))) {
70 // Generate a FQFN for the helper class
71 $fqfn = sprintf("%s%s/%s/%s%s",
73 FrameworkConfiguration::getInstance()->readConfig('application_path'),
76 FrameworkConfiguration::getInstance()->readConfig('php_extension')
79 // Does the include file exists?
80 if ((file_exists($fqfn)) && (is_file($fqfn)) && (is_readable($fqfn))) {
83 } elseif (FrameworkConfiguration::getInstance()->readConfig('verbose_level') > 0) {
85 trigger_error(sprintf("Cannot load application script %s! File is missing or read-protected.",
86 $inc . FrameworkConfiguration::getInstance()->readConfig('php_extension')