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