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\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
9 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
10 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
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 - 2017 City 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 BaseFrameworkSystem implements ManageableApplication, Registerable {
55 * The version number of this application
57 private $appVersion = '';
60 * The human-readable name for this application
62 private $appName = '';
65 * The short uni*-like name for this application
67 private $shortName = '';
70 * An instance of this class
72 private static $selfInstance = NULL;
79 protected function __construct () {
80 // Call parent constructor
81 parent::__construct(__CLASS__);
85 * Getter for an instance of this class
87 * @return $selfInstance An instance of this class
89 public static final function getSelfInstance () {
90 // Is the instance there?
91 if (is_null(self::$selfInstance)) {
92 self::$selfInstance = new ApplicationHelper();
95 // Return the instance
96 return self::$selfInstance;
100 * Getter for the version number
102 * @return $appVersion The application's version number
104 public final function getAppVersion () {
105 return $this->appVersion;
108 * Setter for the version number
110 * @param $appVersion The application's version number
113 public final function setAppVersion ($appVersion) {
115 $this->appVersion = (string) $appVersion;
119 * Getter for human-readable name
121 * @return $appName The application's human-readable name
123 public final function getAppName () {
124 return $this->appName;
128 * Setter for human-readable name
130 * @param $appName The application's human-readable name
133 public final function setAppName ($appName) {
135 $this->appName = (string) $appName;;
139 * Getter for short uni*-like name
141 * @return $shortName The application's short uni*-like name
143 public final function getAppShortName () {
144 return $this->shortName;
148 * Setter for short uni*-like name
150 * @param $shortName The application's short uni*-like name
153 public final function setAppShortName ($shortName) {
155 $this->shortName = (string) $shortName;
159 * 1) Setups application data
163 public function setupApplicationData () {
164 // Set all application data
165 $this->setAppName('City Growth Simulation');
166 $this->setAppVersion('0.0.0');
167 $this->setAppShortName('city');
171 * 2) Does initial stuff before starting the application
175 public function initApplication () {
176 // Initialize output system
177 ApplicationHelper::createDebugInstance('ApplicationHelper');
180 * This application needs a database connection then simply call init
183 FrameworkBootstrap::initDatabaseInstance();
187 * 3) Launches the application
191 public function launchApplication () {
192 // Get request/response instances
193 $requestInstance = FrameworkBootstrap::getRequestInstance();
194 $responseInstance = FrameworkBootstrap::getResponseInstance();
196 // Get the parameter from the request
197 $commandName = $requestInstance->getRequestElement('command');
199 // If it is null then get default command
200 if (is_null($commandName)) {
201 // Get default command
202 $commandName = $responseInstance->determineDefaultCommand();
205 $requestInstance->setRequestElement('command', $commandName);
208 // Get a controller resolver
209 $resolverClass = sprintf(
210 'Org\Mxchange\City\Resolver\Controller\%s',
211 self::convertToClassName(sprintf(
212 '%s_%s_controller_resolver',
213 $this->getAppShortName(),
214 FrameworkBootstrap::getRequestTypeFromSystem()
217 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
219 // Get a controller instance as well
220 $this->setControllerInstance($resolverInstance->resolveController());
222 // Initialize language system
223 $languageInstance = ObjectFactory::createObjectByConfiguredName('language_system_class');
226 $this->setLanguageInstance($languageInstance);
228 // Launch the test suite here
229 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
231 // -------------------------- Shutdown phase --------------------------
232 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...');
233 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
234 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
238 * Handle the indexed array of fatal messages and puts them out in an
241 * @param $messageList An array of fatal messages
244 public function handleFatalMessages (array $messageList) {
245 // Walk through all messages
246 foreach ($messageList as $message) {
247 exit(__METHOD__ . ':MSG:' . $message);
252 * Builds the master template's name
254 * @return $masterTemplateName Name of the master template
256 public function buildMasterTemplateName () {
261 * Assigns extra application-depending data
263 * @param $templateInstance An instance of a CompileableTemplate
265 * @todo Nothing to add?
267 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
268 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());