Continued:
[core.git] / inc / selector.php
1 <?php
2 // Import framework stuff
3 use CoreFramework\Configuration\FrameworkConfiguration;
4 use CoreFramework\Object\BaseFrameworkSystem;
5
6 /**
7  * The application selector main include file
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 // Try to load these includes in the given order
32 $configAppIncludes = array(
33         'class_' . FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_helper_class'), // The ApplicationHelper class
34         'debug',                // Some debugging stuff
35         'exceptions',   // The application's own exception handler
36         'loader',               // The application's class loader
37         'config',               // The application's own configuration
38         'config-local', // Local configuration file (optional)
39         'data',                 // Application data
40         'init',                 // The application initializer
41         'starter',              // The application starter (calls entryPoint(), etc.)
42 );
43
44 // Cache base path/file here
45 $basePathFile = FrameworkConfiguration::getSelfInstance()->getConfigEntry('application_path') . FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_name');
46
47 // Is the directory there?
48 if (!is_dir($basePathFile)) {
49         // Not found.
50         trigger_error('Application ' . FrameworkConfiguration::getSelfInstance()->getConfigEntry('app_name') . ' not found.');
51         exit;
52 } // END - if
53
54 // Load them all (try only)
55 foreach ($configAppIncludes as $appInc) {
56         // Skip starter in test mode
57         if (($appInc == 'starter') && (defined('TEST'))) {
58                 // Skip it here
59                 continue;
60         } // END - if
61
62         // Generate a FQFN for the helper class
63         $appFqFn = $basePathFile . '/' . $appInc . '.php';
64
65         // Does the include file exists?
66         if (BaseFrameworkSystem::isReadableFile($appFqFn)) {
67                 // Load it
68                 //* DEBUG: */ print basename(__FILE__)."[".__LINE__."]: Loading ".basename($appFqFn)." - START\n";
69                 require($appFqFn);
70                 //* DEBUG: */ print basename(__FILE__)."[".__LINE__."]: Loading ".basename($appFqFn)." - END\n";
71         } elseif (FrameworkConfiguration::getSelfInstance()->getConfigEntry('verbose_level') > 0) {
72                 // File is missing
73                 trigger_error(sprintf('Cannot load application script %s.php! File is missing or read-protected.',
74                         $appInc
75                 ));
76                 exit;
77         }
78 }
79
80 // Remove variables from namespace, which we don't need
81 unset($appInc);
82 unset($configAppIncludes);
83 unset($appFqFn);
84 unset($basePathFile);