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