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