Just a space removed
[shipsimu.git] / application / ship-simu / 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 = "shipsimu_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          * Protected constructor
74          *
75          * @return      void
76          */
77         protected function __construct () {
78                 // Call parent constructor
79                 parent::__construct(__CLASS__);
80
81                 // Set description
82                 $this->setObjectDescription("Application-Helper");
83
84                 // Create an unique ID
85                 $this->generateUniqueId();
86
87                 // Tidy up a little
88                 $this->removeSystemArray();
89         }
90
91         /**
92          * Getter for an instance of this class
93          *
94          * @return      $thisInstance           An instance of this class
95          */
96         public final static function getInstance () {
97                 // Is the instance there?
98                 if (is_null(self::$thisInstance)) {
99                         self::$thisInstance = new ApplicationHelper();
100                 }
101
102                 // Return the instance
103                 return self::$thisInstance;
104         }
105
106         /**
107          * Getter for the version number
108          *
109          * @return      $appVersion             The application's version number
110          */
111         public final function getAppVersion () {
112                 return $this->appVersion;
113         }
114
115         /**
116          * Setter for the version number
117          *
118          * @param       $appVersion             The application's version number
119          * @return      void
120          */
121         public final function setAppVersion ($appVersion) {
122                 // Cast and set it
123                 $appVersion = (string) $appVersion;
124                 $this->appVersion = $appVersion;
125         }
126
127         /**
128          * Getter for human-readable name
129          *
130          * @return      $appName        The application's human-readable name
131          */
132         public final function getAppName () {
133                 return $this->appName;
134         }
135
136         /**
137          * Setter for human-readable name
138          *
139          * @param       $appName        The application's human-readable name
140          * @return      void
141          */
142         public final function setAppName ($appName) {
143                 // Cast and set it
144                 $appName = (string) $appName;
145                 $this->appName = $appName;
146         }
147
148         /**
149          * Getter for short uni*-like name
150          *
151          * @return      $shortName      The application's short uni*-like name
152          */
153         public final function getAppShortName () {
154                 return $this->shortName;
155         }
156
157         /**
158          * Setter for short uni*-like name
159          *
160          * @param       $shortName      The application's short uni*-like name
161          * @return      void
162          */
163         public final function setAppShortName ($shortName) {
164                 // Cast and set it
165                 $shortName = (string) $shortName;
166                 $this->shortName = $shortName;
167         }
168
169         /**
170          * Getter for master template name
171          *
172          * @return      $masterTemplate         Name of the master template
173          */
174         public final function getMasterTemplate () {
175                 return $this->masterTemplate;
176         }
177
178         /**
179          * Launches the ship-simulator game
180          *
181          * @return      void
182          */
183         public final function entryPoint () {
184                 // Create a new request object
185                 $requestInstance = ObjectFactory::createObjectByName('HttpRequest');
186
187                 // ... and a new response object
188                 $responseInstance = HttpResponse::createHttpResponse($this);
189
190                 // Get command parameter
191                 $commandPara = $this->getConfigInstance()->readConfig('command_parameter');
192
193                 // Get the parameter from the request
194                 $commandName = $requestInstance->getRequestElement($commandPara);
195
196                 // If it is null then get default command
197                 if (is_null($commandName)) {
198                         $commandName = $this->getConfigInstance()->readConfig('default_command');
199                 }
200
201                 // Get a resolver
202                 $resolverInstance = WebControllerResolver::createWebControllerResolver($commandName, $this);
203
204                 // Get a controller instance as well
205                 $this->controllerInstance = $resolverInstance->resolveCommandController();
206
207                 // Handle the request
208                 $this->controllerInstance->handleRequest($requestInstance, $responseInstance);
209         }
210
211         /**
212          * Handle the indexed array of fatal messages and puts them out in an
213          * acceptable fasion
214          *
215          * @param       $messageList    An array of fatal messages
216          * @return      void
217          */
218         public function handleFatalMessages (array $messageList) {
219                 // Walk through all messages
220                 foreach ($messageList as $message) {
221                         print("MSG:".$message."<br />\n");
222                 }
223         }
224 }
225
226 // [EOF]
227 ?>