3 namespace CoreFramework\Helper\Application;
5 // Import framework stuff
6 use CoreFramework\Manager\ManageableApplication;
7 use CoreFramework\Object\BaseFrameworkSystem;
8 use CoreFramework\Registry\Registerable;
9 use CoreFramework\Registry\Generic\Registry;
10 use CoreFramework\Template\CompileableTemplate;
13 * A class holding general data about the application and some methods for
14 * the management including the entry point.
18 * index.php?app=my_app
20 * You need to create a folder in the folder "application" named "my_app"
21 * (without the quotes) and create a include file called
22 * class_ApplicationHelper.php. You have to write the same class for your
23 * application and implement the same interface called ManageableApplication
24 * because this class include file will be searched for.
26 * It is good when you avoid more GET parameters to keep URLs short and sweet.
27 * But sometimes you need some GET paramerers e.g. for your imprint or info page
28 * or other linked pages which you have to create and state some informations.
30 * Please remember that this include file is being loaded *before* the class
31 * loader is loading classes from "exceptions", "interfaces" and "main"!
33 * @author Roland Haeder <webmaster@shipsimu.org>
35 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
36 * @license GNU GPL 3.0 or any newer version
38 * This program is free software: you can redistribute it and/or modify
39 * it under the terms of the GNU General Public License as published by
40 * the Free Software Foundation, either version 3 of the License, or
41 * (at your option) any later version.
43 * This program is distributed in the hope that it will be useful,
44 * but WITHOUT ANY WARRANTY; without even the implied warranty of
45 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 * GNU General Public License for more details.
48 * You should have received a copy of the GNU General Public License
49 * along with this program. If not, see <http://www.gnu.org/licenses/>.
51 class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
53 * The version number of this application
55 private $appVersion = '';
58 * The human-readable name for this application
60 private $appName = '';
63 * The short uni*-like name for this application
65 private $shortName = '';
68 * An instance of this class
70 private static $selfInstance = NULL;
77 protected function __construct () {
78 // Call parent constructor
79 parent::__construct(__CLASS__);
83 * Getter for an instance of this class
85 * @return $selfInstance An instance of this class
87 public static final function getSelfInstance () {
88 // Is the instance there?
89 if (is_null(self::$selfInstance)) {
90 self::$selfInstance = new ApplicationHelper();
93 // Return the instance
94 return self::$selfInstance;
98 * Getter for the version number
100 * @return $appVersion The application's version number
102 public final function getAppVersion () {
103 return $this->appVersion;
106 * Setter for the version number
108 * @param $appVersion The application's version number
111 public final function setAppVersion ($appVersion) {
113 $this->appVersion = (string) $appVersion;
117 * Getter for human-readable name
119 * @return $appName The application's human-readable name
121 public final function getAppName () {
122 return $this->appName;
126 * Setter for human-readable name
128 * @param $appName The application's human-readable name
131 public final function setAppName ($appName) {
133 $this->appName = (string) $appName;;
137 * Getter for short uni*-like name
139 * @return $shortName The application's short uni*-like name
141 public final function getAppShortName () {
142 return $this->shortName;
146 * Setter for short uni*-like name
148 * @param $shortName The application's short uni*-like name
151 public final function setAppShortName ($shortName) {
153 $this->shortName = (string) $shortName;
157 * Launches the test suite
161 public final function entryPoint () {
162 // Set this application in registry
163 Registry::getRegistry()->addInstance('app', $this);
165 // Default response is console
166 $response = self::getResponseTypeFromSystem();
167 $responseType = self::getResponseTypeFromSystem();
169 // Create a new request object
170 $requestInstance = ObjectFactory::createObjectByName(self::convertToClassName($response) . 'Request');
172 // Remember request instance here
173 $this->setRequestInstance($requestInstance);
175 // Do we have another response?
176 if ($requestInstance->isRequestElementSet('request')) {
178 $response = strtolower($requestInstance->getRequestElement('request'));
179 $responseType = $response;
182 // ... and a new response object
183 $responseClass = sprintf('%sResponse', self::convertToClassName($response));
184 $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
186 // Remember response instance here
187 $this->setResponseInstance($responseInstance);
189 // Get the parameter from the request
190 $commandName = $requestInstance->getRequestElement('command');
192 // If it is null then get default command
193 if (is_null($commandName)) {
194 // Get default command
195 $commandName = $responseInstance->determineDefaultCommand();
198 $requestInstance->setRequestElement('command', $commandName);
201 // Get a controller resolver
202 $resolverClass = self::convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver');
203 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
205 // Get a controller instance as well
206 $this->setControllerInstance($resolverInstance->resolveController());
208 // Launch the test suite here
209 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
211 // -------------------------- Shutdown phase --------------------------
212 // Shutting down the hub by saying "good bye" to all connected peers
213 // and other hubs, flushing all queues and caches.
214 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown in progress, main loop exited.');
215 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
216 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
220 * Handle the indexed array of fatal messages and puts them out in an
223 * @param $messageList An array of fatal messages
226 public function handleFatalMessages (array $messageList) {
227 // Walk through all messages
228 foreach ($messageList as $message) {
229 exit(__METHOD__ . ':MSG:' . $message);
234 * Builds the master template's name
236 * @return $masterTemplateName Name of the master template
238 public function buildMasterTemplateName () {
243 * Assigns extra application-depending data
245 * @param $templateInstance An instance of a CompileableTemplate
247 * @todo Nothing to add?
249 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
250 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());