3 namespace CoreFramework\Helper\Application;
5 // Import framework stuff
6 use CoreFramework\Manager\ManageableApplication;
7 use CoreFramework\Object\BaseFrameworkSystem;
8 use CoreFramework\Factory\ObjectFactory;
9 use CoreFramework\Registry\Registerable;
10 use CoreFramework\Registry\Registry;
11 use CoreFramework\Template\CompileableTemplate;
14 * A class holding general data about the application and some methods for
15 * the management including the entry point.
19 * index.php?app=my_app
21 * You need to create a folder in the folder "application" named "my_app"
22 * (without the quotes) and create a include file called
23 * class_ApplicationHelper.php. You have to write the same class for your
24 * application and implement the same interface called ManageableApplication
25 * because this class include file will be searched for.
27 * It is good when you avoid more GET parameters to keep URLs short and sweet.
28 * But sometimes you need some GET paramerers e.g. for your imprint or info page
29 * or other linked pages which you have to create and state some informations.
31 * Please remember that this include file is being loaded *before* the class
32 * loader is loading classes from "exceptions", "interfaces" and "main"!
34 * @author Roland Haeder <webmaster@shipsimu.org>
36 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
37 * @license GNU GPL 3.0 or any newer version
39 * This program is free software: you can redistribute it and/or modify
40 * it under the terms of the GNU General Public License as published by
41 * the Free Software Foundation, either version 3 of the License, or
42 * (at your option) any later version.
44 * This program is distributed in the hope that it will be useful,
45 * but WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47 * GNU General Public License for more details.
49 * You should have received a copy of the GNU General Public License
50 * along with this program. If not, see <http://www.gnu.org/licenses/>.
52 class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
54 * The version number of this application
56 private $appVersion = '';
59 * The human-readable name for this application
61 private $appName = '';
64 * The short uni*-like name for this application
66 private $shortName = '';
69 * An instance of this class
71 private static $selfInstance = NULL;
78 protected function __construct () {
79 // Call parent constructor
80 parent::__construct(__CLASS__);
84 * Getter for an instance of this class
86 * @return $selfInstance An instance of this class
88 public static final function getSelfInstance () {
89 // Is the instance there?
90 if (is_null(self::$selfInstance)) {
91 self::$selfInstance = new ApplicationHelper();
94 // Return the instance
95 return self::$selfInstance;
99 * Getter for the version number
101 * @return $appVersion The application's version number
103 public final function getAppVersion () {
104 return $this->appVersion;
107 * Setter for the version number
109 * @param $appVersion The application's version number
112 public final function setAppVersion ($appVersion) {
114 $this->appVersion = (string) $appVersion;
118 * Getter for human-readable name
120 * @return $appName The application's human-readable name
122 public final function getAppName () {
123 return $this->appName;
127 * Setter for human-readable name
129 * @param $appName The application's human-readable name
132 public final function setAppName ($appName) {
134 $this->appName = (string) $appName;;
138 * Getter for short uni*-like name
140 * @return $shortName The application's short uni*-like name
142 public final function getAppShortName () {
143 return $this->shortName;
147 * Setter for short uni*-like name
149 * @param $shortName The application's short uni*-like name
152 public final function setAppShortName ($shortName) {
154 $this->shortName = (string) $shortName;
158 * Launches the test suite
162 public final function entryPoint () {
163 // Set this application in registry
164 Registry::getRegistry()->addInstance('app', $this);
166 // Default response is console
167 $response = self::getResponseTypeFromSystem();
168 $responseType = self::getResponseTypeFromSystem();
170 // Create a new request object
171 $requestInstance = ObjectFactory::createObjectByName(sprintf('CoreFramework\Request\%sRequest', self::convertToClassName($response)));
173 // Remember request instance here
174 $this->setRequestInstance($requestInstance);
176 // Do we have another response?
177 if ($requestInstance->isRequestElementSet('request')) {
179 $response = strtolower($requestInstance->getRequestElement('request'));
180 $responseType = $response;
183 // ... and a new response object
184 $responseClass = sprintf('CoreFramework\Response\%sResponse', self::convertToClassName($response));
185 $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this));
187 // Remember response instance here
188 $this->setResponseInstance($responseInstance);
190 // Get the parameter from the request
191 $commandName = $requestInstance->getRequestElement('command');
193 // If it is null then get default command
194 if (is_null($commandName)) {
195 // Get default command
196 $commandName = $responseInstance->determineDefaultCommand();
199 $requestInstance->setRequestElement('command', $commandName);
202 // Get a controller resolver
203 $resolverClass = sprintf(
204 'CoreFramework\Tests\Resolver\Controller\%s',
205 self::convertToClassName(sprintf(
206 '%s_%s_controller_resolver',
207 $this->getAppShortName(),
211 $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this));
213 // Get a controller instance as well
214 $this->setControllerInstance($resolverInstance->resolveController());
216 // Launch the test suite here
217 $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance);
219 // -------------------------- Shutdown phase --------------------------
220 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...');
221 $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance);
222 self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)');
226 * Handle the indexed array of fatal messages and puts them out in an
229 * @param $messageList An array of fatal messages
232 public function handleFatalMessages (array $messageList) {
233 // Walk through all messages
234 foreach ($messageList as $message) {
235 exit(__METHOD__ . ':MSG:' . $message);
240 * Builds the master template's name
242 * @return $masterTemplateName Name of the master template
244 public function buildMasterTemplateName () {
249 * Assigns extra application-depending data
251 * @param $templateInstance An instance of a CompileableTemplate
253 * @todo Nothing to add?
255 public function assignExtraTemplateData (CompileableTemplate $templateInstance) {
256 $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString());