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\Template\CompileableTemplate;
12 * A class holding general data about the application and some methods for
13 * the management including the entry point.
17 * index.php?app=my_app
19 * You need to create a folder in the folder "application" named "my_app"
20 * (without the quotes) and create a include file called
21 * class_ApplicationHelper.php. You have to write the same class for your
22 * application and implement the same interface called ManageableApplication
23 * because this class include file will be searched for.
25 * It is good when you avoid more GET parameters to keep URLs short and sweet.
26 * But sometimes you need some GET paramerers e.g. for your imprint or info page
27 * or other linked pages which you have to create and state some informations.
29 * Please remember that this include file is being loaded *before* the class
30 * loader is loading classes from "exceptions", "interfaces" and "main"!
32 * @author Roland Haeder <webmaster@shipsimu.org>
34 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
35 * @license GNU GPL 3.0 or any newer version
37 * This program is free software: you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation, either version 3 of the License, or
40 * (at your option) any later version.
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
47 * You should have received a copy of the GNU General Public License
48 * along with this program. If not, see <http://www.gnu.org/licenses/>.
50 class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
52 * The version number of this application
54 private $appVersion = '';
57 * The human-readable name for this application
59 private $appName = '';
62 * The short uni*-like name for this application
64 private $shortName = '';
67 * An instance of this class
69 private static $selfInstance = NULL;
76 protected function __construct () {
77 // Call parent constructor
78 parent::__construct(__CLASS__);
82 * Getter for an instance of this class
84 * @return $selfInstance An instance of this class
86 public static final function getSelfInstance () {
87 // Is the instance there?
88 if (is_null(self::$selfInstance)) {
89 self::$selfInstance = new ApplicationHelper();
92 // Return the instance
93 return self::$selfInstance;
97 * Getter for the version number
99 * @return $appVersion The application's version number
101 public final function getAppVersion () {
102 return $this->appVersion;
105 * Setter for the version number
107 * @param $appVersion The application's version number
110 public final function setAppVersion ($appVersion) {
112 $this->appVersion = (string) $appVersion;
116 * Getter for human-readable name
118 * @return $appName The application's human-readable name
120 public final function getAppName () {
121 return $this->appName;
125 * Setter for human-readable name
127 * @param $appName The application's human-readable name
130 public final function setAppName ($appName) {
132 $this->appName = (string) $appName;;
136 * Getter for short uni*-like name
138 * @return $shortName The application's short uni*-like name
140 public final function getAppShortName () {
141 return $this->shortName;
145 * Setter for short uni*-like name
147 * @param $shortName The application's short uni*-like name
150 public final function setAppShortName ($shortName) {
152 $this->shortName = (string) $shortName;
156 * Launches the test suite
160 public final function entryPoint () {
161 // Set this application in registry
162 Registry::getRegistry()->addInstance('app', $this);
164 // Default response is console
165 $response = self::getResponseTypeFromSystem();
166 $responseType = self::getResponseTypeFromSystem();
168 // Create a new request object
169 $requestInstance = ObjectFactory::createObjectByName(self::convertToClassName($response) . 'Request');
171 // Remember request instance here
172 $this->setRequestInstance($requestInstance);
174 // Do we have another response?
175 if ($requestInstance->isRequestElementSet('request')) {
177 $response = strtolower($requestInstance->getRequestElement('request'));
178 $responseType = $response;
181 // ... and a new response object
182 $responseClass = sprintf('%sResponse', self::convertToClassName($response));
183 $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
185 // Remember response instance here
186 $this->setResponseInstance($responseInstance);
188 // Get the parameter from the request
189 $commandName = $requestInstance->getRequestElement('command');
191 // If it is null then get default command
192 if (is_null($commandName)) {
193 // Get default command
194 $commandName = $responseInstance->determineDefaultCommand();
197 $requestInstance->setRequestElement('command', $commandName);
200 // Get a controller resolver
201 $resolverClass = self::convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver');
202 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
204 // Get a controller instance as well
205 $this->setControllerInstance($resolverInstance->resolveController());
207 // Launch the test suite here
208 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
210 // -------------------------- Shutdown phase --------------------------
211 // Shutting down the hub by saying "good bye" to all connected peers
212 // and other hubs, flushing all queues and caches.
213 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown in progress, main loop exited.');
214 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
215 self::createDebugInstance(__CLASS__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
219 * Handle the indexed array of fatal messages and puts them out in an
222 * @param $messageList An array of fatal messages
225 public function handleFatalMessages (array $messageList) {
226 // Walk through all messages
227 foreach ($messageList as $message) {
228 exit(__METHOD__ . ':MSG:' . $message);
233 * Builds the master template's name
235 * @return $masterTemplateName Name of the master template
237 public function buildMasterTemplateName () {
242 * Assigns extra application-depending data
244 * @param $templateInstance An instance of a CompileableTemplate
246 * @todo Nothing to add?
248 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
249 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());