]> git.mxchange.org Git - city.git/blob - application/city/class_ApplicationHelper.php
Continued:
[city.git] / application / city / class_ApplicationHelper.php
1 <?php
2 // Must be this namespace, else the launcher cannot find the class.
3 namespace Org\Mxchange\CoreFramework\Helper\Application;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
9 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
10 use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
11 use Org\Mxchange\CoreFramework\Registry\Registerable;
12 use Org\Mxchange\CoreFramework\Registry\Registry;
13 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
14
15 /**
16  * A class holding general data about the application and some methods for
17  * the management including the entry point.
18  *
19  * E.g.:
20  *
21  * index.php?app=my_app
22  *
23  * You need to create a folder in the folder "application" named "my_app"
24  * (without the quotes) and create a include file called
25  * class_ApplicationHelper.php. You have to write the same class for your
26  * application and implement the same interface called ManageableApplication
27  * because this class include file will be searched for.
28  *
29  * It is good when you avoid more GET parameters to keep URLs short and sweet.
30  * But sometimes you need some GET paramerers e.g. for your imprint or info page
31  * or other linked pages which you have to create and state some informations.
32  *
33  * Please remember that this include file is being loaded *before* the class
34  * loader is loading classes from "exceptions", "interfaces" and "main"!
35  *
36  * @author              Roland Haeder <webmaster@shipsimu.org>
37  * @version             0.0
38  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 City Developer Team
39  * @license             GNU GPL 3.0 or any newer version
40  *
41  * This program is free software: you can redistribute it and/or modify
42  * it under the terms of the GNU General Public License as published by
43  * the Free Software Foundation, either version 3 of the License, or
44  * (at your option) any later version.
45  *
46  * This program is distributed in the hope that it will be useful,
47  * but WITHOUT ANY WARRANTY; without even the implied warranty of
48  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
49  * GNU General Public License for more details.
50  *
51  * You should have received a copy of the GNU General Public License
52  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
53  */
54 class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
55         /**
56          * The version number of this application
57          */
58         private $appVersion = '';
59
60         /**
61          * The human-readable name for this application
62          */
63         private $appName = '';
64
65         /**
66          * The short uni*-like name for this application
67          */
68         private $shortName = '';
69
70         /**
71          * An instance of this class
72          */
73         private static $selfInstance = NULL;
74
75         /**
76          * Private constructor
77          *
78          * @return      void
79          */
80         protected function __construct () {
81                 // Call parent constructor
82                 parent::__construct(__CLASS__);
83         }
84
85         /**
86          * Getter for an instance of this class
87          *
88          * @return      $selfInstance   An instance of this class
89          */
90         public static final function getSelfInstance () {
91                 // Is the instance there?
92                 if (is_null(self::$selfInstance)) {
93                         self::$selfInstance = new ApplicationHelper();
94                 } // END - if
95
96                 // Return the instance
97                 return self::$selfInstance;
98         }
99
100         /**
101          * Getter for the version number
102          *
103          * @return      $appVersion     The application's version number
104          */
105         public final function getAppVersion () {
106                 return $this->appVersion;
107         }
108         /**
109          * Setter for the version number
110          *
111          * @param       $appVersion     The application's version number
112          * @return      void
113          */
114         public final function setAppVersion ($appVersion) {
115                 // Cast and set it
116                 $this->appVersion = (string) $appVersion;
117         }
118
119         /**
120          * Getter for human-readable name
121          *
122          * @return      $appName        The application's human-readable name
123          */
124         public final function getAppName () {
125                 return $this->appName;
126         }
127
128         /**
129          * Setter for human-readable name
130          *
131          * @param       $appName        The application's human-readable name
132          * @return      void
133          */
134         public final function setAppName ($appName) {
135                 // Cast and set it
136                 $this->appName = (string) $appName;;
137         }
138
139         /**
140          * Getter for short uni*-like name
141          *
142          * @return      $shortName      The application's short uni*-like name
143          */
144         public final function getAppShortName () {
145                 return $this->shortName;
146         }
147
148         /**
149          * Setter for short uni*-like name
150          *
151          * @param       $shortName      The application's short uni*-like name
152          * @return      void
153          */
154         public final function setAppShortName ($shortName) {
155                 // Cast and set it
156                 $this->shortName = (string) $shortName;
157         }
158
159         /**
160          * 1) Setups application data
161          *
162          * @return      void
163          */
164         public function setupApplicationData () {
165                 // Set all application data
166                 $this->setAppName('City Growth Simulation');
167                 $this->setAppVersion('0.0.0');
168                 $this->setAppShortName('city');
169         }
170
171         /**
172          * 2) Does initial stuff before starting the application
173          *
174          * @return      void
175          */
176         public function initApplication () {
177                 // Initialize output system
178                 ApplicationHelper::createDebugInstance('ApplicationHelper');
179
180                 /*
181                  * This application needs a database connection then simply call init
182                  * method.
183                  */
184                 FrameworkBootstrap::initDatabaseInstance();
185         }
186
187         /**
188          * 3) Launches the application
189          *
190          * @return      void
191          */
192         public function launchApplication () {
193                 // Get request/response instances
194                 $requestInstance  = FrameworkBootstrap::getRequestInstance();
195                 $responseInstance = FrameworkBootstrap::getResponseInstance();
196
197                 // Get the parameter from the request
198                 $commandName = $requestInstance->getRequestElement('command');
199
200                 // If it is null then get default command
201                 if (is_null($commandName)) {
202                         // Get default command
203                         $commandName = $responseInstance->determineDefaultCommand();
204
205                         // Set it in request
206                         $requestInstance->setRequestElement('command', $commandName);
207                 } // END - if
208
209                 // Get a controller resolver
210                 $resolverClass = sprintf(
211                         'Org\Mxchange\City\Resolver\Controller\%s',
212                         self::convertToClassName(sprintf(
213                                 '%s_%s_controller_resolver',
214                                 $this->getAppShortName(),
215                                 FrameworkBootstrap::getRequestTypeFromSystem()
216                         ))
217                 );
218                 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
219
220                 // Get a controller instance as well
221                 $this->setControllerInstance($resolverInstance->resolveController());
222
223                 // Launch the test suite here
224                 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
225
226                 // -------------------------- Shutdown phase --------------------------
227                 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...');
228                 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
229                 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
230         }
231
232         /**
233          * Handle the indexed array of fatal messages and puts them out in an
234          * acceptable fasion
235          *
236          * @param       $messageList    An array of fatal messages
237          * @return      void
238          */
239         public function handleFatalMessages (array $messageList) {
240                 // Walk through all messages
241                 foreach ($messageList as $message) {
242                         exit(__METHOD__ . ':MSG:' . $message);
243                 } // END - foreach
244         }
245
246         /**
247          * Builds the master template's name
248          *
249          * @return      $masterTemplateName             Name of the master template
250          */
251         public function buildMasterTemplateName () {
252                 return 'city_main';
253         }
254
255         /**
256          * Assigns extra application-depending data
257          *
258          * @param       $templateInstance       An instance of a CompileableTemplate
259          * @return      void
260          * @todo        Nothing to add?
261          */
262         public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
263                 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());
264         }
265
266 }