X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fselector%2Fclass_ApplicationHelper.php;h=44d77cb62972304e3c9651a7eb0a02e86fa4cdb4;hb=1079ab2b4b8ee62cb5e434b5ee3d04bd7369f954;hp=1617173e0457e1b90a8dd83ec8008a28add5851c;hpb=1655bfb47ca0dd174e374d70d1aaad4293346379;p=shipsimu.git diff --git a/application/selector/class_ApplicationHelper.php b/application/selector/class_ApplicationHelper.php index 1617173..44d77cb 100644 --- a/application/selector/class_ApplicationHelper.php +++ b/application/selector/class_ApplicationHelper.php @@ -63,7 +63,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication /** * An instance of this class */ - private static $thisInstance = null; + private static $selfInstance = null; /** * Protected constructor @@ -78,16 +78,16 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication /** * Getter for an instance of this class * - * @return $thisInstance An instance of this class + * @return $selfInstance An instance of this class */ - public final static function getInstance () { + public final static function getSelfInstance () { // Is the instance there? - if (is_null(self::$thisInstance)) { - self::$thisInstance = new ApplicationHelper(); - } + if (is_null(self::$selfInstance)) { + self::$selfInstance = new ApplicationHelper(); + } // END - if // Return the instance - return self::$thisInstance; + return self::$selfInstance; } /** @@ -160,7 +160,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication */ public function buildMasterTemplateName () { // Get short name and add suffix - $masterTemplateName = str_replace("-", "", $this->getAppShortName()) . "_main"; + $masterTemplateName = str_replace('-', '', $this->getAppShortName()) . '_main'; // Return it return $masterTemplateName; @@ -172,12 +172,22 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication * @return void */ public final function entryPoint () { + // Set this application in registry + Registry::getRegistry()->addInstance('app', $this); + + // Analyze the environment for type of response/request + $type = ConsoleTools::analyzeEnvironmentForType(); + $classType = ConsoleTools::analyzeEnvironmentForClassType(); + // Create a new request object - $requestInstance = ObjectFactory::createObjectByName('HttpRequest'); + $requestInstance = ObjectFactory::createObjectByName(ucfirst($type) . 'Request'); + + // Remember request instance here + $this->setRequestInstance($requestInstance); - // Default response is HTTP (HTML page) and type is "Web" - $response = "http"; - $responseType = "web"; + // Default response is HTTP (HTML page) and type is 'Web' + $response = $type; + $responseType = $classType; // Do we have another response? if ($requestInstance->isRequestElementSet('request')) { @@ -190,8 +200,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication $responseClass = sprintf("%sResponse", $this->convertToClassName($response)); $responseInstance = ObjectFactory::createObjectByName($responseClass, array($this)); - // Remember both in this application - $this->setRequestInstance($requestInstance); + // Remember response instance here $this->setResponseInstance($responseInstance); // Get the parameter from the request @@ -199,7 +208,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication // If it is null then get default command if (is_null($commandName)) { - // Get default command + // Get the default command $commandName = $responseInstance->getDefaultCommand(); // Set it in request @@ -213,6 +222,12 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication // Get a controller instance as well $this->controllerInstance = $resolverInstance->resolveController(); + // Get a web output class + $outputInstance = ObjectFactory::createObjectByConfiguredName('output_class', array($this)); + + // Set it in this application + $this->setWebOutputInstance($outputInstance); + // Handle the request $this->controllerInstance->handleRequest($requestInstance, $responseInstance); } @@ -227,7 +242,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication public function handleFatalMessages (array $messageList) { // Walk through all messages foreach ($messageList as $message) { - print("MSG:".$message."
\n"); + print("MSG:" . $message . "
\n"); } // END - if }