3 namespace CoreFramework\Helper\Application;
5 // Import framework stuff
6 use CoreFramework\Registry\Registerable;
9 * A class holding general data about the application and some methods for
10 * the management including the entry point.
14 * index.php?app=my_app
16 * You need to create a folder in the folder "application" named "my_app"
17 * (without the quotes) and create a include file called
18 * class_ApplicationHelper.php. You have to write the same class for your
19 * application and implement the same interface called ManageableApplication
20 * because this class include file will be searched for.
22 * It is good when you avoid more GET parameters to keep URLs short and sweet.
23 * But sometimes you need some GET paramerers e.g. for your imprint or info page
24 * or other linked pages which you have to create and state some informations.
26 * Please remember that this include file is being loaded *before* the class
27 * loader is loading classes from "exceptions", "interfaces" and "main"!
29 * @author Roland Haeder <webmaster@shipsimu.org>
31 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
32 * @license GNU GPL 3.0 or any newer version
34 * This program is free software: you can redistribute it and/or modify
35 * it under the terms of the GNU General Public License as published by
36 * the Free Software Foundation, either version 3 of the License, or
37 * (at your option) any later version.
39 * This program is distributed in the hope that it will be useful,
40 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 * GNU General Public License for more details.
44 * You should have received a copy of the GNU General Public License
45 * along with this program. If not, see <http://www.gnu.org/licenses/>.
47 class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
49 * The version number of this application
51 private $appVersion = '';
54 * The human-readable name for this application
56 private $appName = '';
59 * The short uni*-like name for this application
61 private $shortName = '';
64 * An instance of this class
66 private static $selfInstance = NULL;
73 protected function __construct () {
74 // Call parent constructor
75 parent::__construct(__CLASS__);
79 * Getter for an instance of this class
81 * @return $selfInstance An instance of this class
83 public static final function getSelfInstance () {
84 // Is the instance there?
85 if (is_null(self::$selfInstance)) {
86 self::$selfInstance = new ApplicationHelper();
89 // Return the instance
90 return self::$selfInstance;
94 * Getter for the version number
96 * @return $appVersion The application's version number
98 public final function getAppVersion () {
99 return $this->appVersion;
102 * Setter for the version number
104 * @param $appVersion The application's version number
107 public final function setAppVersion ($appVersion) {
109 $this->appVersion = (string) $appVersion;
113 * Getter for human-readable name
115 * @return $appName The application's human-readable name
117 public final function getAppName () {
118 return $this->appName;
122 * Setter for human-readable name
124 * @param $appName The application's human-readable name
127 public final function setAppName ($appName) {
129 $this->appName = (string) $appName;;
133 * Getter for short uni*-like name
135 * @return $shortName The application's short uni*-like name
137 public final function getAppShortName () {
138 return $this->shortName;
142 * Setter for short uni*-like name
144 * @param $shortName The application's short uni*-like name
147 public final function setAppShortName ($shortName) {
149 $this->shortName = (string) $shortName;
153 * Launches the test suite
157 public final function entryPoint () {
158 // Set this application in registry
159 Registry::getRegistry()->addInstance('app', $this);
161 // Default response is console
162 $response = self::getResponseTypeFromSystem();
163 $responseType = self::getResponseTypeFromSystem();
165 // Create a new request object
166 $requestInstance = ObjectFactory::createObjectByName(self::convertToClassName($response) . 'Request');
168 // Remember request instance here
169 $this->setRequestInstance($requestInstance);
171 // Do we have another response?
172 if ($requestInstance->isRequestElementSet('request')) {
174 $response = strtolower($requestInstance->getRequestElement('request'));
175 $responseType = $response;
178 // ... and a new response object
179 $responseClass = sprintf('%sResponse', self::convertToClassName($response));
180 $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
182 // Remember response instance here
183 $this->setResponseInstance($responseInstance);
185 // Get the parameter from the request
186 $commandName = $requestInstance->getRequestElement('command');
188 // If it is null then get default command
189 if (is_null($commandName)) {
190 // Get default command
191 $commandName = $responseInstance->determineDefaultCommand();
194 $requestInstance->setRequestElement('command', $commandName);
197 // Get a controller resolver
198 $resolverClass = self::convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver');
199 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
201 // Get a controller instance as well
202 $this->setControllerInstance($resolverInstance->resolveController());
204 // Launch the test suite here
205 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
207 // -------------------------- Shutdown phase --------------------------
208 // Shutting down the hub by saying "good bye" to all connected peers
209 // and other hubs, flushing all queues and caches.
210 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown in progress, main loop exited.');
211 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
212 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
216 * Handle the indexed array of fatal messages and puts them out in an
219 * @param $messageList An array of fatal messages
222 public function handleFatalMessages (array $messageList) {
223 // Walk through all messages
224 foreach ($messageList as $message) {
225 exit(__METHOD__ . ':MSG:' . $message);
230 * Builds the master template's name
232 * @return $masterTemplateName Name of the master template
234 public function buildMasterTemplateName () {
239 * Assigns extra application-depending data
241 * @param $templateInstance An instance of a CompileableTemplate
243 * @todo Nothing to add?
245 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
246 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());