2 // Must be this namespace, else the launcher cannot find the class.
3 namespace CoreFramework\Helper\Application;
5 // Import framework stuff
6 use CoreFramework\Bootstrap\FrameworkBootstrap;
7 use CoreFramework\Configuration\FrameworkConfiguration;
8 use CoreFramework\Factory\ObjectFactory;
9 use CoreFramework\Loader\ClassLoader;
10 use CoreFramework\Manager\ManageableApplication;
11 use CoreFramework\Object\BaseFrameworkSystem;
12 use CoreFramework\Registry\Registerable;
13 use CoreFramework\Registry\Registry;
14 use CoreFramework\Template\CompileableTemplate;
17 * A class holding general data about the application and some methods for
18 * the management including the entry point.
22 * index.php?app=my_app
24 * You need to create a folder in the folder "application" named "my_app"
25 * (without the quotes) and create a include file called
26 * class_ApplicationHelper.php. You have to write the same class for your
27 * application and implement the same interface called ManageableApplication
28 * because this class include file will be searched for.
30 * It is good when you avoid more GET parameters to keep URLs short and sweet.
31 * But sometimes you need some GET paramerers e.g. for your imprint or info page
32 * or other linked pages which you have to create and state some informations.
34 * Please remember that this include file is being loaded *before* the class
35 * loader is loading classes from "exceptions", "interfaces" and "main"!
37 * @author Roland Haeder <webmaster@shipsimu.org>
39 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
40 * @license GNU GPL 3.0 or any newer version
42 * This program is free software: you can redistribute it and/or modify
43 * it under the terms of the GNU General Public License as published by
44 * the Free Software Foundation, either version 3 of the License, or
45 * (at your option) any later version.
47 * This program is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50 * GNU General Public License for more details.
52 * You should have received a copy of the GNU General Public License
53 * along with this program. If not, see <http://www.gnu.org/licenses/>.
55 class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
57 * The version number of this application
59 private $appVersion = '';
62 * The human-readable name for this application
64 private $appName = '';
67 * The short uni*-like name for this application
69 private $shortName = '';
72 * An instance of this class
74 private static $selfInstance = NULL;
81 protected function __construct () {
82 // Call parent constructor
83 parent::__construct(__CLASS__);
87 * Getter for an instance of this class
89 * @return $selfInstance An instance of this class
91 public static final function getSelfInstance () {
92 // Is the instance there?
93 if (is_null(self::$selfInstance)) {
94 self::$selfInstance = new ApplicationHelper();
97 // Return the instance
98 return self::$selfInstance;
102 * Getter for the version number
104 * @return $appVersion The application's version number
106 public final function getAppVersion () {
107 return $this->appVersion;
110 * Setter for the version number
112 * @param $appVersion The application's version number
115 public final function setAppVersion ($appVersion) {
117 $this->appVersion = (string) $appVersion;
121 * Getter for human-readable name
123 * @return $appName The application's human-readable name
125 public final function getAppName () {
126 return $this->appName;
130 * Setter for human-readable name
132 * @param $appName The application's human-readable name
135 public final function setAppName ($appName) {
137 $this->appName = (string) $appName;;
141 * Getter for short uni*-like name
143 * @return $shortName The application's short uni*-like name
145 public final function getAppShortName () {
146 return $this->shortName;
150 * Setter for short uni*-like name
152 * @param $shortName The application's short uni*-like name
155 public final function setAppShortName ($shortName) {
157 $this->shortName = (string) $shortName;
161 * 1) Setups application data
165 public function setupApplicationData () {
166 // Set all application data
167 $this->setAppName('Unit tests and more');
168 $this->setAppVersion('0.0.0');
169 $this->setAppShortName('tests');
173 * 2) Does initial stuff before starting the application
177 public function initApplication () {
178 // Get config instance
179 $cfg = FrameworkConfiguration::getSelfInstance();
181 // Initialize output system
182 self::createDebugInstance('ApplicationHelper');
185 * This application needs a database connection then simply call init
188 FrameworkBootstrap::initDatabaseInstance();
190 // Register core tests
191 ClassLoader::registerTestsPath('framework/main/tests');
193 // Register own tests
194 ClassLoader::registerTestsPath('application/tests/tests');
197 ClassLoader::scanTestsClasses();
201 * 3) Launches the application
205 public function launchApplication () {
206 // Get request/response instances
207 $requestInstance = FrameworkBootstrap::getRequestInstance();
208 $responseInstance = FrameworkBootstrap::getResponseInstance();
210 // Get the parameter from the request
211 $commandName = $requestInstance->getRequestElement('command');
213 // If it is null then get default command
214 if (is_null($commandName)) {
215 // Get default command
216 $commandName = $responseInstance->determineDefaultCommand();
219 $requestInstance->setRequestElement('command', $commandName);
222 // Get a controller resolver
223 $resolverClass = sprintf(
224 'CoreFramework\Tests\Resolver\Controller\%s',
225 self::convertToClassName(sprintf(
226 '%s_%s_controller_resolver',
227 $this->getAppShortName(),
228 FrameworkBootstrap::getRequestTypeFromSystem()
231 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
233 // Get a controller instance as well
234 $this->setControllerInstance($resolverInstance->resolveController());
236 // Launch the test suite here
237 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
239 // -------------------------- Shutdown phase --------------------------
240 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...');
241 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
242 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
246 * Handle the indexed array of fatal messages and puts them out in an
249 * @param $messageList An array of fatal messages
252 public function handleFatalMessages (array $messageList) {
253 // Walk through all messages
254 foreach ($messageList as $message) {
255 exit(__METHOD__ . ':MSG:' . $message);
260 * Builds the master template's name
262 * @return $masterTemplateName Name of the master template
264 public function buildMasterTemplateName () {
269 * Assigns extra application-depending data
271 * @param $templateInstance An instance of a CompileableTemplate
273 * @todo Nothing to add?
275 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
276 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());