]> git.mxchange.org Git - shipsimu.git/blob - ship-simu/inc/selector.php
Initial import of current development status
[shipsimu.git] / ship-simu / inc / selector.php
1 <?php
2 /**
3  * @desc        The application selector main include file
4  */
5
6 // Does the user has an application specified?
7 if (!empty($_GET[FrameworkConfiguration::getInstance()->readConfig("app_selector_get")])) {
8         // Set the application from string
9         $application = (string) $_GET[FrameworkConfiguration::getInstance()->readConfig("app_selector_get")];
10 } elseif (!empty($_SERVER['argv'][1])) {
11         // Set the application from string
12         $application = (string) $_SERVER['argv'][1];
13         $app = explode("=", trim($application));
14         if ($app[0] == FrameworkConfiguration::getInstance()->readConfig("app_selector_get")) {
15                 // Application is valid!
16                 $application = trim($app[1]);
17         } else {
18                 // Invalid entry found, first must be "app"!
19                 $application = FrameworkConfiguration::getInstance()->readConfig("default_application");
20         }
21 } else {
22         // Set the "application selector" application
23         $application = FrameworkConfiguration::getInstance()->readConfig("default_application");
24 }
25
26 // Secure it, by keeping out tags
27 $application = htmlentities(strip_tags($application), ENT_QUOTES);
28
29 // Secure it a little more with a reg.exp.
30 $application = preg_replace('/([^a-z_-])+/i', "", $application);
31
32 // Try to load these includes in the given order
33 $configAppIncludes = array(
34         sprintf("class_%s", FrameworkConfiguration::getInstance()->readConfig("app_helper_class")), // The ApplicationHelper class
35         "config",               // The application's own configuration
36         "init",         // The application initializer
37         "loader",       // The application's class loader
38         "debug",                // Some debugging stuff
39         "exceptions",   // The application's own exception handler
40         "starter",      // The application starter (calls entryPoint(), etc.)
41 );
42
43 // Load them all (try only)
44 foreach ($configAppIncludes as $inc) {
45         // Skip starter in test mode
46         if (($inc == "starter") && (defined('TEST'))) {
47                 // Skip it here
48                 continue;
49         }
50
51         // Generate a FQFN for the helper class
52         $fqfn = sprintf("%s%s/%s/%s%s",
53                 PATH,
54                 FrameworkConfiguration::getInstance()->readConfig("application_path"),
55                 $application,
56                 $inc,
57                 FrameworkConfiguration::getInstance()->readConfig("php_extension")
58         );
59
60         // Does the include file exists?
61         if ((file_exists($fqfn)) && (is_file($fqfn)) && (is_readable($fqfn))) {
62                 // Load it
63                 require_once($fqfn);
64         } elseif (FrameworkConfiguration::getInstance()->readConfig("verbose_level") > 0) {
65                 // File is missing
66                 trigger_error(sprintf("Cannot load application script %s! File is missing or read-protected.",
67                         $inc . FrameworkConfiguration::getInstance()->readConfig("php_extension")
68                 ));
69         }
70 }
71
72 // [EOF]
73 ?>