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\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 - 2020 Core 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 {
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('Unit tests and more');
166 $this->setAppVersion('0.0.0');
167 $this->setAppShortName('tests');
171 * 2) Does initial stuff before starting the application
175 public function initApplication () {
176 // Get config instance
177 $cfg = FrameworkBootstrap::getConfigurationInstance();
179 // Initialize output system
180 self::createDebugInstance('ApplicationHelper');
183 * This application needs a database connection then simply call init
186 FrameworkBootstrap::initDatabaseInstance();
188 // Register core tests
189 ClassLoader::registerTestsPath('framework/main/tests');
191 // Register own tests
192 ClassLoader::registerTestsPath('application/tests/tests');
195 ClassLoader::scanTestsClasses();
199 * 3) Launches the application
203 public function launchApplication () {
204 // Get request/response instances
205 $requestInstance = FrameworkBootstrap::getRequestInstance();
206 $responseInstance = FrameworkBootstrap::getResponseInstance();
208 // Get the parameter from the request
209 $commandName = $requestInstance->getRequestElement('command');
211 // If it is null then get default command
212 if (is_null($commandName)) {
213 // Get default command
214 $commandName = $responseInstance->determineDefaultCommand();
217 $requestInstance->setRequestElement('command', $commandName);
220 // Get a controller resolver
221 $resolverClass = sprintf(
222 'Org\Mxchange\CoreFramework\Tests\Resolver\Controller\%s',
223 self::convertToClassName(sprintf(
224 '%s_%s_controller_resolver',
225 $this->getAppShortName(),
226 FrameworkBootstrap::getRequestTypeFromSystem()
229 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName));
231 // Get a controller instance as well
232 $this->setControllerInstance($resolverInstance->resolveController());
234 // Launch the test suite here
235 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
237 // -------------------------- Shutdown phase --------------------------
238 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...');
239 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
240 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
244 * Handle the indexed array of fatal messages and puts them out in an
247 * @param $messageList An array of fatal messages
250 public function handleFatalMessages (array $messageList) {
251 // Walk through all messages
252 foreach ($messageList as $message) {
253 exit(__METHOD__ . ':MSG:' . $message);
258 * Builds the master template's name
260 * @return $masterTemplateName Name of the master template
262 public function buildMasterTemplateName () {
267 * Assigns extra application-depending data
269 * @param $templateInstance An instance of a CompileableTemplate
271 * @todo Nothing to add?
273 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
274 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());