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;
13 use Org\Mxchange\CoreFramework\Utils\Strings\StringUtils;
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 - 2022 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 BaseApplication implements ManageableApplication, Registerable {
60 private function __construct () {
61 // Call parent constructor
62 parent::__construct(__CLASS__);
66 * Getter for an instance of this class
68 * @return $selfInstance An instance of this class
70 public static final function getSelfInstance () {
71 // Is the instance there?
72 if (is_null(self::getApplicationInstance())) {
74 self::setApplicationInstance(new ApplicationHelper());
77 // Return the instance
78 return self::getApplicationInstance();
82 * 1) Setups application data
86 public function setupApplicationData () {
87 // Set all application data
88 $this->setAppName('Unit tests and more');
89 $this->setAppVersion('0.0.0');
90 $this->setAppShortName('tests');
94 * 2) Does initial stuff before starting the application
98 public function initApplication () {
99 // Get config instance
100 $cfg = FrameworkBootstrap::getConfigurationInstance();
102 // Initialize output system
103 self::createDebugInstance('ApplicationHelper');
106 * This application needs a database connection then simply call init
109 FrameworkBootstrap::initDatabaseInstance();
111 // Register core tests
112 ClassLoader::registerTestsPath('framework/main/tests');
115 ClassLoader::scanTestsClasses();
119 * 3) Launches the application
123 public function launchApplication () {
124 // Get request/response instances
125 $requestInstance = FrameworkBootstrap::getRequestInstance();
126 $responseInstance = FrameworkBootstrap::getResponseInstance();
128 // Get the parameter from the request
129 $commandName = $requestInstance->getRequestElement('command');
131 // If it is null then get default command
132 if (is_null($commandName)) {
133 // Get default command
134 $commandName = $responseInstance->determineDefaultCommand();
137 $requestInstance->setRequestElement('command', $commandName);
140 // Configuration entry key
141 $configEntry = sprintf(
142 '%s_%s_controller_resolver_class',
143 $this->getAppShortName(),
144 FrameworkBootstrap::getRequestTypeFromSystem()
147 // Get a controller resolver instance
148 $resolverInstance = ObjectFactory::createObjectByConfiguredName($configEntry, [
152 // Get a controller instance as well
153 $this->setControllerInstance($resolverInstance->resolveController());
155 // Launch the test suite here
156 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
158 // -------------------------- Shutdown phase --------------------------
159 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...');
160 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
161 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
165 * Handle the indexed array of fatal messages and puts them out in an
168 * @param $messageList An array of fatal messages
171 public function handleFatalMessages (array $messageList) {
172 // Walk through all messages
173 foreach ($messageList as $message) {
174 exit(__METHOD__ . ':MSG:' . $message);
179 * Builds the master template's name
181 * @return $masterTemplateName Name of the master template
183 public function buildMasterTemplateName () {
188 * Assigns extra application-depending data
190 * @param $templateInstance An instance of a CompileableTemplate class
192 * @todo Nothing to add?
194 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
195 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());