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\Registry\Registry;
13 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
16 * A class holding general data about the application and some methods for
17 * the management including the entry point.
21 * index.php?app=my_app
23 * You need to create a folder in the folder "application" named "my_app"
24 * (without the quotes) and create a include file called
25 * class_ApplicationHelper.php. You have to write the same class for your
26 * application and implement the same interface called ManageableApplication
27 * because this class include file will be searched for.
29 * It is good when you avoid more GET parameters to keep URLs short and sweet.
30 * But sometimes you need some GET paramerers e.g. for your imprint or info page
31 * or other linked pages which you have to create and state some informations.
33 * Please remember that this include file is being loaded *before* the class
34 * loader is loading classes from "exceptions", "interfaces" and "main"!
36 * @author Roland Haeder <webmaster@shipsimu.org>
38 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
39 * @license GNU GPL 3.0 or any newer version
41 * This program is free software: you can redistribute it and/or modify
42 * it under the terms of the GNU General Public License as published by
43 * the Free Software Foundation, either version 3 of the License, or
44 * (at your option) any later version.
46 * This program is distributed in the hope that it will be useful,
47 * but WITHOUT ANY WARRANTY; without even the implied warranty of
48 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 * GNU General Public License for more details.
51 * You should have received a copy of the GNU General Public License
52 * along with this program. If not, see <http://www.gnu.org/licenses/>.
54 class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
56 * The version number of this application
58 private $appVersion = '';
61 * The human-readable name for this application
63 private $appName = '';
66 * The short uni*-like name for this application
68 private $shortName = '';
71 * An instance of this class
73 private static $selfInstance = NULL;
80 protected function __construct () {
81 // Call parent constructor
82 parent::__construct(__CLASS__);
86 * Getter for an instance of this class
88 * @return $selfInstance An instance of this class
90 public static final function getSelfInstance () {
91 // Is the instance there?
92 if (is_null(self::$selfInstance)) {
93 self::$selfInstance = new ApplicationHelper();
96 // Return the instance
97 return self::$selfInstance;
101 * Getter for the version number
103 * @return $appVersion The application's version number
105 public final function getAppVersion () {
106 return $this->appVersion;
109 * Setter for the version number
111 * @param $appVersion The application's version number
114 public final function setAppVersion ($appVersion) {
116 $this->appVersion = (string) $appVersion;
120 * Getter for human-readable name
122 * @return $appName The application's human-readable name
124 public final function getAppName () {
125 return $this->appName;
129 * Setter for human-readable name
131 * @param $appName The application's human-readable name
134 public final function setAppName ($appName) {
136 $this->appName = (string) $appName;;
140 * Getter for short uni*-like name
142 * @return $shortName The application's short uni*-like name
144 public final function getAppShortName () {
145 return $this->shortName;
149 * Setter for short uni*-like name
151 * @param $shortName The application's short uni*-like name
154 public final function setAppShortName ($shortName) {
156 $this->shortName = (string) $shortName;
160 * 1) Setups application data
164 public function setupApplicationData () {
165 // Set all application data
166 $this->setAppName('Unit tests and more');
167 $this->setAppVersion('0.0.0');
168 $this->setAppShortName('tests');
172 * 2) Does initial stuff before starting the application
176 public function initApplication () {
177 // Get config instance
178 $cfg = FrameworkBootstrap::getConfigurationInstance();
180 // Initialize output system
181 self::createDebugInstance('ApplicationHelper');
184 * This application needs a database connection then simply call init
187 FrameworkBootstrap::initDatabaseInstance();
189 // Register core tests
190 ClassLoader::registerTestsPath('framework/main/tests');
192 // Register own tests
193 ClassLoader::registerTestsPath('application/tests/tests');
196 ClassLoader::scanTestsClasses();
200 * 3) Launches the application
204 public function launchApplication () {
205 // Get request/response instances
206 $requestInstance = FrameworkBootstrap::getRequestInstance();
207 $responseInstance = FrameworkBootstrap::getResponseInstance();
209 // Get the parameter from the request
210 $commandName = $requestInstance->getRequestElement('command');
212 // If it is null then get default command
213 if (is_null($commandName)) {
214 // Get default command
215 $commandName = $responseInstance->determineDefaultCommand();
218 $requestInstance->setRequestElement('command', $commandName);
221 // Get a controller resolver
222 $resolverClass = sprintf(
223 'Org\Mxchange\CoreFramework\Tests\Resolver\Controller\%s',
224 self::convertToClassName(sprintf(
225 '%s_%s_controller_resolver',
226 $this->getAppShortName(),
227 FrameworkBootstrap::getRequestTypeFromSystem()
230 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
232 // Get a controller instance as well
233 $this->setControllerInstance($resolverInstance->resolveController());
235 // Launch the test suite here
236 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
238 // -------------------------- Shutdown phase --------------------------
239 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...');
240 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
241 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
245 * Handle the indexed array of fatal messages and puts them out in an
248 * @param $messageList An array of fatal messages
251 public function handleFatalMessages (array $messageList) {
252 // Walk through all messages
253 foreach ($messageList as $message) {
254 exit(__METHOD__ . ':MSG:' . $message);
259 * Builds the master template's name
261 * @return $masterTemplateName Name of the master template
263 public function buildMasterTemplateName () {
268 * Assigns extra application-depending data
270 * @param $templateInstance An instance of a CompileableTemplate
272 * @todo Nothing to add?
274 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
275 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());