47680fbac63434b64f227aa7ecb68965b417a400
[shipsimu.git] / application / todo / class_ApplicationHelper.php
1 <?php
2 /**
3  * A class holding general data about the application and some methods for
4  * the management including the entry point.
5  *
6  * E.g.:
7  *
8  * index.php?app=my_app
9  *
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.
15  *
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.
19  *
20  * Please remember that this include file is being loaded *before* the class
21  * loader is loading classes from "exceptions", "interfaces" and "main"!
22  *
23  * @author              Roland Haeder <webmaster@ship-simu.org>
24  * @version             0.0.0
25  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, this is free software
26  * @license             GNU GPL 3.0 or any newer version
27  * @link                http://www.ship-simu.org
28  *
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.
33  *
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.
38  *
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/>.
41  */
42 class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication {
43         /**
44          * The version number of this application
45          */
46         private $appVersion = "";
47
48         /**
49          * The human-readable name for this application
50          */
51         private $appName = "";
52
53         /**
54          * The short uni*-like name for this application
55          */
56         private $shortName = "";
57
58         /**
59          * The name of the master template
60          */
61         private $masterTemplate = "todo_main";
62
63         /**
64          * An instance of a controller
65          */
66         private $controllerInstance = null;
67
68         /**
69          * An instance of this class
70          */
71         private static $thisInstance = null;
72
73         /**
74          * Protected constructor
75          *
76          * @return      void
77          */
78         protected function __construct () {
79                 // Call parent constructor
80                 parent::__construct(__CLASS__);
81
82                 // Tidy up a little
83                 $this->removeSystemArray();
84                 $this->removeNumberFormaters();
85         }
86
87         /**
88          * Getter for an instance of this class
89          *
90          * @return      $thisInstance           An instance of this class
91          */
92         public final static function getInstance () {
93                 // Is the instance there?
94                 if (is_null(self::$thisInstance)) {
95                         self::$thisInstance = new ApplicationHelper();
96                 }
97
98                 // Return the instance
99                 return self::$thisInstance;
100         }
101
102         /**
103          * Getter for the version number
104          *
105          * @return      $appVersion             The application's version number
106          */
107         public final function getAppVersion () {
108                 return $this->appVersion;
109         }
110
111         /**
112          * Setter for the version number
113          *
114          * @param       $appVersion             The application's version number
115          * @return      void
116          */
117         public final function setAppVersion ($appVersion) {
118                 // Cast and set it
119                 $appVersion = (string) $appVersion;
120                 $this->appVersion = $appVersion;
121         }
122
123         /**
124          * Getter for human-readable name
125          *
126          * @return      $appName        The application's human-readable name
127          */
128         public final function getAppName () {
129                 return $this->appName;
130         }
131
132         /**
133          * Setter for human-readable name
134          *
135          * @param       $appName        The application's human-readable name
136          * @return      void
137          */
138         public final function setAppName ($appName) {
139                 // Cast and set it
140                 $appName = (string) $appName;
141                 $this->appName = $appName;
142         }
143
144         /**
145          * Getter for short uni*-like name
146          *
147          * @return      $shortName      The application's short uni*-like name
148          */
149         public final function getAppShortName () {
150                 return $this->shortName;
151         }
152
153         /**
154          * Setter for short uni*-like name
155          *
156          * @param       $shortName      The application's short uni*-like name
157          * @return      void
158          */
159         public final function setAppShortName ($shortName) {
160                 // Cast and set it
161                 $shortName = (string) $shortName;
162                 $this->shortName = $shortName;
163         }
164
165         /**
166          * Getter for master template name
167          *
168          * @return      $masterTemplate         Name of the master template
169          */
170         public final function getMasterTemplate () {
171                 return $this->masterTemplate;
172         }
173
174         /**
175          * Launches the todo software
176          *
177          * @return      void
178          */
179         public final function entryPoint () {
180                 // Create a new request object
181                 $requestInstance = ObjectFactory::createObjectByName('HttpRequest');
182
183                 // Default response is HTTP (HTML page) and type is "Web"
184                 $response = "http";
185                 $responseType = "web";
186
187                 // Do we have another response?
188                 if ($requestInstance->isRequestElementSet('response')) {
189                         // Then use it
190                         $response = strtolower($requestInstance->getRequestElement('response'));
191                         $responseType = $response;
192                 } // END - if
193
194                 // ... and a new response object
195                 $responseInstance = ObjectFactory::createObjectByName(ucfirst($response)."Response", array($this));
196
197                 // Remember both in this application
198                 $this->setRequestInstance($requestInstance);
199                 $this->setResponseInstance($responseInstance);
200
201                 // Get the parameter from the request
202                 $commandName = $requestInstance->getRequestElement('page');
203
204                 // If it is null then get default command
205                 if (is_null($commandName)) {
206                         $commandName = $responseInstance->getDefaultCommand();
207                 } // END - if
208
209                 // Get a resolver
210                 $resolverInstance = ObjectFactory::createObjectByName(ucfirst($responseType)."ControllerResolver", array($commandName, $this));
211
212                 // Get a controller instance as well
213                 $this->controllerInstance = $resolverInstance->resolveController();
214
215                 // Handle the request
216                 $this->controllerInstance->handleRequest($requestInstance, $responseInstance);
217         }
218
219         /**
220          * Handle the indexed array of fatal messages and puts them out in an
221          * acceptable fasion
222          *
223          * @param       $messageList    An array of fatal messages
224          * @return      void
225          */
226         public function handleFatalMessages (array $messageList) {
227                 // Walk through all messages
228                 foreach ($messageList as $message) {
229                         print("MSG:".$message."<br />\n");
230                 } // END - if
231         }
232
233         /**
234          * Assigns application-depending data
235          *
236          * @param       $templateInstance       An instance of a template engine
237          * @return      void
238          */
239         public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
240                 // Assign charset
241                 $templateInstance->assignConfigVariable('header_charset');
242         }
243 }
244
245 // [EOF]
246 ?>