2 // Must be this namespace, else the launcher cannot find the class.
3 namespace Org\Mxchange\CoreFramework\Helper\Application;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Application\BaseApplication;
7 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
8 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
9 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
10 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
11 use Org\Mxchange\CoreFramework\Registry\Registerable;
12 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
15 * A class holding general data about the application and some methods for
16 * the management including the entry point.
20 * index.php?app=my_app
22 * You need to create a folder in the folder "application" named "my_app"
23 * (without the quotes) and create a include file called
24 * class_ApplicationHelper.php. You have to write the same class for your
25 * application and implement the same interface called ManageableApplication
26 * because this class include file will be searched for.
28 * It is good when you avoid more GET parameters to keep URLs short and sweet.
29 * But sometimes you need some GET paramerers e.g. for your imprint or info page
30 * or other linked pages which you have to create and state some informations.
32 * Please remember that this include file is being loaded *before* the class
33 * loader is loading classes from "exceptions", "interfaces" and "main"!
35 * @author Roland Haeder <webmaster@shipsimu.org>
37 * @copyright Copyright (c) 2007 - 2008 Roland Haeder, 2009 - 2022 Ship-Simu Developer Team
38 * @license GNU GPL 3.0 or any newer version
40 * This program is free software: you can redistribute it and/or modify
41 * it under the terms of the GNU General Public License as published by
42 * the Free Software Foundation, either version 3 of the License, or
43 * (at your option) any later version.
45 * This program is distributed in the hope that it will be useful,
46 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 * GNU General Public License for more details.
50 * You should have received a copy of the GNU General Public License
51 * along with this program. If not, see <http://www.gnu.org/licenses/>.
53 class ApplicationHelper extends BaseApplication implements ManageableApplication, Registerable {
59 private function __construct () {
60 // Call parent constructor
61 parent::__construct(__CLASS__);
65 * Getter for an instance of this class
67 * @return $selfInstance An instance of this class
69 public static final function getSelfInstance () {
70 // Is the instance there?
71 if (is_null(self::getApplicationInstance())) {
72 self::setApplicationInstance(new ApplicationHelper());
75 // Return the instance
76 return self::getApplicationInstance();
80 * 1) Setups application data
84 public function setupApplicationData () {
85 // Set all application data
86 $this->setAppName('Ship-Simu Shipping Simulator');
87 $this->setAppVersion('0.0.0');
88 $this->setAppShortName('shipsimu');
92 * 2) Does initial stuff before starting the application
96 public function initApplication () {
97 // Get config instance
98 $cfg = FrameworkBootstrap::getConfigurationInstance();
100 // Initialize output system
101 ApplicationHelper::createDebugInstance('ApplicationHelper');
104 * This application needs a database connection then simply call init
107 FrameworkBootstrap::initDatabaseInstance();
111 * 3) Launches the application
115 public function launchApplication () {
116 // Get request/response instances
117 $requestInstance = FrameworkBootstrap::getRequestInstance();
118 $responseInstance = FrameworkBootstrap::getResponseInstance();
120 // Get the parameter from the request
121 $commandName = $requestInstance->getRequestElement('command');
123 // If it is null then get default command
124 if (is_null($commandName)) {
125 // Get default command
126 $commandName = $responseInstance->determineDefaultCommand();
129 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('commandName[%s]=%s', gettype($commandName), $commandName));
132 $requestInstance->setRequestElement('command', $commandName);
135 // Is the request type 'html' ?
136 if (FrameworkBootstrap::getRequestTypeFromSystem() == 'html') {
137 // The language system is needed for this
138 $languageInstance = ObjectFactory::createObjectByConfiguredName('language_system_class');
141 $this->setLanguageInstance($languageInstance);
144 // Configuration entry key
145 $configEntry = sprintf(
146 '%s_%s_controller_resolver_class',
147 $this->getAppShortName(),
148 FrameworkBootstrap::getRequestTypeFromSystem()
151 // Get a controller resolver instance
152 $resolverInstance = ObjectFactory::createObjectByConfiguredName($configEntry, [
156 // Get a controller instance as well
157 $this->setControllerInstance($resolverInstance->resolveController());
159 // Launch the test suite here
160 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
162 // Only for console requests as this is the actual daemon
163 if ($requestType == 'console') {
164 // -------------------------- Shutdown phase --------------------------
165 // Shutting down the hub by saying "good bye" to all connected peers
166 // and other hubs, flushing all queues and caches.
167 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress, main loop exited.');
168 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
169 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
174 * Assigns extra application-depending data
176 * @param $templateInstance An instance of a CompileableTemplate class
178 * @todo Nothing to add?
180 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
184 * Handle the indexed array of fatal messages and puts them out in an
187 * @param $messageList An array of fatal messages
190 public function handleFatalMessages (array $messageList) {
191 // Walk through all messages
192 foreach ($messageList as $message) {
193 exit(__METHOD__ . ':MSG:' . $message);
198 * Builds the master template's name
200 * @return $masterTemplateName Name of the master template
202 public function buildMasterTemplateName () {
203 return 'node_daemon';