3 namespace CoreFramework\Helper\Application;
5 // Import framework stuff
6 use CoreFramework\Manager\ManageableApplication;
7 use CoreFramework\Object\BaseFrameworkSystem;
8 use CoreFramework\Registry\Registerable;
11 * A class holding general data about the application and some methods for
12 * the management including the entry point.
16 * index.php?app=my_app
18 * You need to create a folder in the folder "application" named "my_app"
19 * (without the quotes) and create a include file called
20 * class_ApplicationHelper.php. You have to write the same class for your
21 * application and implement the same interface called ManageableApplication
22 * because this class include file will be searched for.
24 * It is good when you avoid more GET parameters to keep URLs short and sweet.
25 * But sometimes you need some GET paramerers e.g. for your imprint or info page
26 * or other linked pages which you have to create and state some informations.
28 * Please remember that this include file is being loaded *before* the class
29 * loader is loading classes from "exceptions", "interfaces" and "main"!
31 * @author Roland Haeder <webmaster@shipsimu.org>
33 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
34 * @license GNU GPL 3.0 or any newer version
36 * This program is free software: you can redistribute it and/or modify
37 * it under the terms of the GNU General Public License as published by
38 * the Free Software Foundation, either version 3 of the License, or
39 * (at your option) any later version.
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Public License for more details.
46 * You should have received a copy of the GNU General Public License
47 * along with this program. If not, see <http://www.gnu.org/licenses/>.
49 class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
51 * The version number of this application
53 private $appVersion = '';
56 * The human-readable name for this application
58 private $appName = '';
61 * The short uni*-like name for this application
63 private $shortName = '';
66 * An instance of this class
68 private static $selfInstance = NULL;
75 protected function __construct () {
76 // Call parent constructor
77 parent::__construct(__CLASS__);
81 * Getter for an instance of this class
83 * @return $selfInstance An instance of this class
85 public static final function getSelfInstance () {
86 // Is the instance there?
87 if (is_null(self::$selfInstance)) {
88 self::$selfInstance = new ApplicationHelper();
91 // Return the instance
92 return self::$selfInstance;
96 * Getter for the version number
98 * @return $appVersion The application's version number
100 public final function getAppVersion () {
101 return $this->appVersion;
104 * Setter for the version number
106 * @param $appVersion The application's version number
109 public final function setAppVersion ($appVersion) {
111 $this->appVersion = (string) $appVersion;
115 * Getter for human-readable name
117 * @return $appName The application's human-readable name
119 public final function getAppName () {
120 return $this->appName;
124 * Setter for human-readable name
126 * @param $appName The application's human-readable name
129 public final function setAppName ($appName) {
131 $this->appName = (string) $appName;;
135 * Getter for short uni*-like name
137 * @return $shortName The application's short uni*-like name
139 public final function getAppShortName () {
140 return $this->shortName;
144 * Setter for short uni*-like name
146 * @param $shortName The application's short uni*-like name
149 public final function setAppShortName ($shortName) {
151 $this->shortName = (string) $shortName;
155 * Launches the test suite
159 public final function entryPoint () {
160 // Set this application in registry
161 Registry::getRegistry()->addInstance('app', $this);
163 // Default response is console
164 $response = self::getResponseTypeFromSystem();
165 $responseType = self::getResponseTypeFromSystem();
167 // Create a new request object
168 $requestInstance = ObjectFactory::createObjectByName(self::convertToClassName($response) . 'Request');
170 // Remember request instance here
171 $this->setRequestInstance($requestInstance);
173 // Do we have another response?
174 if ($requestInstance->isRequestElementSet('request')) {
176 $response = strtolower($requestInstance->getRequestElement('request'));
177 $responseType = $response;
180 // ... and a new response object
181 $responseClass = sprintf('%sResponse', self::convertToClassName($response));
182 $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
184 // Remember response instance here
185 $this->setResponseInstance($responseInstance);
187 // Get the parameter from the request
188 $commandName = $requestInstance->getRequestElement('command');
190 // If it is null then get default command
191 if (is_null($commandName)) {
192 // Get default command
193 $commandName = $responseInstance->determineDefaultCommand();
196 $requestInstance->setRequestElement('command', $commandName);
199 // Get a controller resolver
200 $resolverClass = self::convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver');
201 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
203 // Get a controller instance as well
204 $this->setControllerInstance($resolverInstance->resolveController());
206 // Launch the test suite here
207 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
209 // -------------------------- Shutdown phase --------------------------
210 // Shutting down the hub by saying "good bye" to all connected peers
211 // and other hubs, flushing all queues and caches.
212 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown in progress, main loop exited.');
213 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
214 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
218 * Handle the indexed array of fatal messages and puts them out in an
221 * @param $messageList An array of fatal messages
224 public function handleFatalMessages (array $messageList) {
225 // Walk through all messages
226 foreach ($messageList as $message) {
227 exit(__METHOD__ . ':MSG:' . $message);
232 * Builds the master template's name
234 * @return $masterTemplateName Name of the master template
236 public function buildMasterTemplateName () {
241 * Assigns extra application-depending data
243 * @param $templateInstance An instance of a CompileableTemplate
245 * @todo Nothing to add?
247 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
248 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());