X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fcity%2Fclass_ApplicationHelper.php;h=17bf18b79def945d127a7ccfdb9b44f445254ea0;hb=d100f068798a47a699aa723c0b4bd62b3025c1b6;hp=943b3d8c0a1fbd569701df3cb91676a4142899e4;hpb=a3b7ac33fc3b34b5d9ce58070619e8cbc837c891;p=city.git diff --git a/application/city/class_ApplicationHelper.php b/application/city/class_ApplicationHelper.php index 943b3d8..17bf18b 100644 --- a/application/city/class_ApplicationHelper.php +++ b/application/city/class_ApplicationHelper.php @@ -1,4 +1,16 @@ * @version 0.0 - * @copyright Copyright (c) 2015 City Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 City Developer Team * @license GNU GPL 3.0 or any newer version * * This program is free software: you can redistribute it and/or modify @@ -38,7 +50,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable { +class ApplicationHelper extends BaseApplication implements ManageableApplication, Registerable { /** * The version number of this application */ @@ -144,53 +156,65 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica } /** - * Launches the test suite + * 1) Setups application data * * @return void */ - public final function entryPoint () { - // Set this application in registry - Registry::getRegistry()->addInstance('app', $this); - - // Default response is console - $response = self::getResponseTypeFromSystem(); - $responseType = self::getResponseTypeFromSystem(); - - // Create a new request object - $requestInstance = ObjectFactory::createObjectByName($this->convertToClassName($response) . 'Request'); - - // Remember request instance here - $this->setRequestInstance($requestInstance); + public function setupApplicationData () { + // Set all application data + $this->setAppName('City Growth Simulation'); + $this->setAppVersion('0.0.0'); + $this->setAppShortName('city'); + } - // Do we have another response? - if ($requestInstance->isRequestElementSet('request')) { - // Then use it - $response = strtolower($requestInstance->getRequestElement('request')); - $responseType = $response; - } // END - if + /** + * 2) Does initial stuff before starting the application + * + * @return void + */ + public function initApplication () { + // Initialize output system + ApplicationHelper::createDebugInstance('ApplicationHelper'); - // ... and a new response object - $responseClass = sprintf('%sResponse', $this->convertToClassName($response)); - $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this)); + /* + * This application needs a database connection then simply call init + * method. + */ + FrameworkBootstrap::initDatabaseInstance(); + } - // Remember response instance here - $this->setResponseInstance($responseInstance); + /** + * 3) Launches the application + * + * @return void + */ + public function launchApplication () { + // Get request/response instances + $requestInstance = FrameworkBootstrap::getRequestInstance(); + $responseInstance = FrameworkBootstrap::getResponseInstance(); // Get the parameter from the request - $commandName = $requestInstance->getRequestElement('page'); + $commandName = $requestInstance->getRequestElement('command'); // If it is null then get default command if (is_null($commandName)) { // Get default command - $commandName = $responseInstance->getDefaultCommand(); + $commandName = $responseInstance->determineDefaultCommand(); // Set it in request $requestInstance->setRequestElement('command', $commandName); } // END - if // Get a controller resolver - $resolverClass = $this->convertToClassName($this->getAppShortName() . '_' . $responseType . '_controller_resolver'); - $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName, $this)); + $resolverClass = sprintf( + 'Org\Mxchange\City\Resolver\Controller\%s', + self::convertToClassName(sprintf( + '%s_%s_controller_resolver', + $this->getAppShortName(), + FrameworkBootstrap::getRequestTypeFromSystem() + )) + ); + $resolverInstance = ObjectFactory::createObjectByName($resolverClass, array($commandName)); // Get a controller instance as well $this->setControllerInstance($resolverInstance->resolveController()); @@ -201,21 +225,22 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica // And set it here $this->setLanguageInstance($languageInstance); - // Launch the game here + // Is html request? + if (FrameworkBootstrap::getRequestTypeFromSystem() == 'html') { + // Init web output instance + $this->initWebOutputInstance(); + } + + // Launch the application here $this->getControllerInstance()->handleRequest($requestInstance, $responseInstance); - // -------------------------- Shutdown phase -------------------------- - $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance); - } - - /** - * Assigns extra application-depending data - * - * @param $templateInstance An instance of a CompileableTemplate - * @return void - * @todo Nothing to add? - */ - public function assignExtraTemplateData (CompileableTemplate $templateInstance) { + // Is console request? + if (FrameworkBootstrap::getRequestTypeFromSystem() == 'console') { + // -------------------------- Shutdown phase -------------------------- + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown in progress ...'); + $this->getControllerInstance()->executeShutdownFilters($requestInstance, $responseInstance); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MAIN: Shutdown completed. (This is the last line.)'); + } } /** @@ -240,7 +265,16 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica public function buildMasterTemplateName () { return 'city_main'; } -} -// [EOF] -?> + /** + * Assigns extra application-depending data + * + * @param $templateInstance An instance of a CompileableTemplate + * @return void + * @todo Nothing to add? + */ + public function assignExtraTemplateData (CompileableTemplate $templateInstance) { + $this->partialStub('Unfinished method. templateInstance=' . $templateInstance->__toString()); + } + +}