3 * A class holding general data about the application and some methods for
4 * the management including the entry point.
10 * You need to create a folder in the folder "application" named "my_app"
11 * (without the quotes) and create a include file called
12 * class_ApplicationHelper.php. You have to write the same class for your
13 * application and implement the same interface called ManageableApplication
14 * because this class include file will be searched for.
16 * It is good when you avoid more GET parameters to keep URLs short and sweet.
17 * But sometimes you need some GET paramerers e.g. for your imprint or info page
18 * or other linked pages which you have to create and state some informations.
20 * Please remember that this include file is being loaded *before* the class
21 * loader is loading classes from "exceptions", "interfaces" and "main"!
23 * @author Roland Haeder <webmaster@shipsimu.org>
25 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Installation-Wizard Developer Team
26 * @license GNU GPL 3.0 or any newer version
27 * @link http://www.shipsimu.org
29 * This program is free software: you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation, either version 3 of the License, or
32 * (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program. If not, see <http://www.gnu.org/licenses/>.
42 class ApplicationHelper extends BaseApplication implements ManageableApplication, Registerable {
44 * The version number of this application
46 private $appVersion = '';
49 * The human-readable name for this application
51 private $appName = '';
54 * The short uni*-like name for this application
56 private $shortName = '';
59 * An instance of a controller
61 private $controllerInstance = null;
64 * An instance of this class
66 private static $selfInstance = null;
69 * Protected constructor
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;
103 * Setter for the version number
105 * @param $appVersion The application's version number
108 public final function setAppVersion ($appVersion) {
110 $appVersion = (string) $appVersion;
111 $this->appVersion = $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 $appName = (string) $appName;
132 $this->appName = $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 $shortName = (string) $shortName;
153 $this->shortName = $shortName;
157 * Builds the master template's name
159 * @return $masterTemplateName Name of the master template
161 public function buildMasterTemplateName () {
162 // Get short name and add suffix
163 $masterTemplateName = str_replace('-', '', $this->getAppShortName()) . '_main';
166 return $masterTemplateName;
170 * Launches the admin area
174 public final function entryPoint () {
175 // Set this application in registry
176 Registry::getRegistry()->addInstance('app', $this);
178 // Create a new request object
179 $requestInstance = ObjectFactory::createObjectByName('HttpRequest');
181 // Remember request instance here
182 $this->setRequestInstance($requestInstance);
184 // Default response is HTTP (HTML page) and type is "Web"
185 $response = $this->getResponseTypeFromSystem();
186 $responseType = $this->getResponseTypeFromSystem();
188 // Do we have another response?
189 if ($requestInstance->isRequestElementSet('request')) {
191 $response = strtolower($requestInstance->getRequestElement('request'));
192 $responseType = $response;
195 // ... and a new response object
196 $responseClass = sprintf('%sResponse', self::convertToClassName($response));
197 $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
199 // Remember response instance here
200 $this->setResponseInstance($responseInstance);
202 // Get the parameter from the request
203 $commandName = $requestInstance->getRequestElement('command');
205 // If it is null then get default command
206 if (is_null($commandName)) {
207 // Get default command
208 $commandName = $responseInstance->getDefaultCommand();
211 $requestInstance->setRequestElement('command', $commandName);
214 // Get a controller resolver
215 $resolverClass = self::convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver');
216 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
218 // Get a controller instance as well
219 $this->controllerInstance = $resolverInstance->resolveController();
221 // Get a web output class
222 $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($this));
224 // Set it in this application
225 $this->setWebOutputInstance($outputInstance);
227 // Handle the request
228 $this->controllerInstance->handleRequest($requestInstance, $responseInstance);
232 * Handle the indexed array of fatal messages and puts them out in an
235 * @param $messageList An array of fatal messages
238 public function handleFatalMessages (array $messageList) {
239 // Walk through all messages
240 foreach ($messageList as $message) {
241 print("MSG:".$message."<br />\n");
246 * Assigns application-depending data
248 * @param $templateInstance An instance of a template engine
251 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
253 $templateInstance->assignConfigVariable('header_charset');