3 namespace CoreFramework\Helper\Application;
5 // Import framework stuff
6 use CoreFramework\Object\BaseFrameworkSystem;
7 use CoreFramework\Registry\Registerable;
10 * A class holding general data about the application and some methods for
11 * the management including the entry point.
15 * index.php?app=my_app
17 * You need to create a folder in the folder "application" named "my_app"
18 * (without the quotes) and create a include file called
19 * class_ApplicationHelper.php. You have to write the same class for your
20 * application and implement the same interface called ManageableApplication
21 * because this class include file will be searched for.
23 * It is good when you avoid more GET parameters to keep URLs short and sweet.
24 * But sometimes you need some GET paramerers e.g. for your imprint or info page
25 * or other linked pages which you have to create and state some informations.
27 * Please remember that this include file is being loaded *before* the class
28 * loader is loading classes from "exceptions", "interfaces" and "main"!
30 * @author Roland Haeder <webmaster@shipsimu.org>
32 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
33 * @license GNU GPL 3.0 or any newer version
35 * This program is free software: you can redistribute it and/or modify
36 * it under the terms of the GNU General Public License as published by
37 * the Free Software Foundation, either version 3 of the License, or
38 * (at your option) any later version.
40 * This program is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 * GNU General Public License for more details.
45 * You should have received a copy of the GNU General Public License
46 * along with this program. If not, see <http://www.gnu.org/licenses/>.
48 class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
50 * The version number of this application
52 private $appVersion = '';
55 * The human-readable name for this application
57 private $appName = '';
60 * The short uni*-like name for this application
62 private $shortName = '';
65 * An instance of this class
67 private static $selfInstance = NULL;
74 protected function __construct () {
75 // Call parent constructor
76 parent::__construct(__CLASS__);
80 * Getter for an instance of this class
82 * @return $selfInstance An instance of this class
84 public static final function getSelfInstance () {
85 // Is the instance there?
86 if (is_null(self::$selfInstance)) {
87 self::$selfInstance = new ApplicationHelper();
90 // Return the instance
91 return self::$selfInstance;
95 * Getter for the version number
97 * @return $appVersion The application's version number
99 public final function getAppVersion () {
100 return $this->appVersion;
103 * Setter for the version number
105 * @param $appVersion The application's version number
108 public final function setAppVersion ($appVersion) {
110 $this->appVersion = (string) $appVersion;
114 * Getter for human-readable name
116 * @return $appName The application's human-readable name
118 public final function getAppName () {
119 return $this->appName;
123 * Setter for human-readable name
125 * @param $appName The application's human-readable name
128 public final function setAppName ($appName) {
130 $this->appName = (string) $appName;;
134 * Getter for short uni*-like name
136 * @return $shortName The application's short uni*-like name
138 public final function getAppShortName () {
139 return $this->shortName;
143 * Setter for short uni*-like name
145 * @param $shortName The application's short uni*-like name
148 public final function setAppShortName ($shortName) {
150 $this->shortName = (string) $shortName;
154 * Launches the test suite
158 public final function entryPoint () {
159 // Set this application in registry
160 Registry::getRegistry()->addInstance('app', $this);
162 // Default response is console
163 $response = self::getResponseTypeFromSystem();
164 $responseType = self::getResponseTypeFromSystem();
166 // Create a new request object
167 $requestInstance = ObjectFactory::createObjectByName(self::convertToClassName($response) . 'Request');
169 // Remember request instance here
170 $this->setRequestInstance($requestInstance);
172 // Do we have another response?
173 if ($requestInstance->isRequestElementSet('request')) {
175 $response = strtolower($requestInstance->getRequestElement('request'));
176 $responseType = $response;
179 // ... and a new response object
180 $responseClass = sprintf('%sResponse', self::convertToClassName($response));
181 $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
183 // Remember response instance here
184 $this->setResponseInstance($responseInstance);
186 // Get the parameter from the request
187 $commandName = $requestInstance->getRequestElement('command');
189 // If it is null then get default command
190 if (is_null($commandName)) {
191 // Get default command
192 $commandName = $responseInstance->determineDefaultCommand();
195 $requestInstance->setRequestElement('command', $commandName);
198 // Get a controller resolver
199 $resolverClass = self::convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver');
200 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
202 // Get a controller instance as well
203 $this->setControllerInstance($resolverInstance->resolveController());
205 // Launch the test suite here
206 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
208 // -------------------------- Shutdown phase --------------------------
209 // Shutting down the hub by saying "good bye" to all connected peers
210 // and other hubs, flushing all queues and caches.
211 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown in progress, main loop exited.');
212 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
213 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
217 * Handle the indexed array of fatal messages and puts them out in an
220 * @param $messageList An array of fatal messages
223 public function handleFatalMessages (array $messageList) {
224 // Walk through all messages
225 foreach ($messageList as $message) {
226 exit(__METHOD__ . ':MSG:' . $message);
231 * Builds the master template's name
233 * @return $masterTemplateName Name of the master template
235 public function buildMasterTemplateName () {
240 * Assigns extra application-depending data
242 * @param $templateInstance An instance of a CompileableTemplate
244 * @todo Nothing to add?
246 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
247 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());