Moved from 'hub' code.
[core.git] / inc / selector.php
1 <?php
2 /**
3  * The application selector main include file
4  *
5  * @author              Roland Haeder <webmaster@shipsimu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.shipsimu.org
10  * @deprecated
11  * @todo                Minimize these includes
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  */
26
27 // Try to load these includes in the given order
28 $configAppIncludes = array(
29         'class_' . FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class'), // The ApplicationHelper class
30         'debug',                // Some debugging stuff
31         'exceptions',   // The application's own exception handler
32         'loader',               // The application's class loader
33         'config',               // The application's own configuration
34         'config-local', // Local configuration file (optional)
35         'data',                 // Application data
36         'init',                 // The application initializer
37         'starter',              // The application starter (calls entryPoint(), etc.)
38 );
39
40 // Cache base path/file here
41 $basePathFile = FrameworkConfiguration::getSelfInstance()->getConfigEntry('application_path') . FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_name');
42
43 // Is the directory there?
44 if (!is_dir($basePathFile)) {
45         // Not found.
46         trigger_error('Application ' . FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_name') . ' not found.');
47         exit;
48 } // END - if
49
50 // Load them all (try only)
51 foreach ($configAppIncludes as $appInc) {
52         // Skip starter in test mode
53         if (($appInc == 'starter') && (defined('TEST'))) {
54                 // Skip it here
55                 continue;
56         } // END - if
57
58         // Generate a FQFN for the helper class
59         $appFqFn = $basePathFile . '/' . $appInc . '.php';
60
61         // Does the include file exists?
62         if ((file_exists($appFqFn)) && (is_file($appFqFn)) && (is_readable($appFqFn))) {
63                 // Load it
64                 //* DEBUG: */ print basename(__FILE__)."[".__LINE__."]: Loading ".basename($appFqFn)." - START\n";
65                 require($appFqFn);
66                 //* DEBUG: */ print basename(__FILE__)."[".__LINE__."]: Loading ".basename($appFqFn)." - END\n";
67         } elseif (FrameworkConfiguration::getSelfInstance()->getConfigEntry('verbose_level') > 0) {
68                 // File is missing
69                 trigger_error(sprintf('Cannot load application script %s.php! File is missing or read-protected.',
70                         $appInc
71                 ));
72                 exit;
73         }
74 }
75
76 // Remove variables from namespace, which we don't need
77 unset($appInc);
78 unset($configAppIncludes);
79 unset($appFqFn);
80 unset($basePathFile);
81
82 // [EOF]
83 ?>