]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/response/class_BaseResponse.php
Sometimes 'page' is wanted, sometimes 'command' but basicly both want a command
[core.git] / inc / classes / main / response / class_BaseResponse.php
index a2d0e302bd840d3d97e001bfcd17af123b41d0d9..0becb5820df511bc9dff1c1a74a974b4d4b32f8d 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * A generic request class
  *
 /**
  * A generic request class
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.org
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -50,6 +50,11 @@ class BaseResponse extends BaseFrameworkSystem {
         */
        private $templateInstance = NULL;
 
         */
        private $templateInstance = NULL;
 
+       /**
+        * Response type
+        */
+       private $responseType = 'invalid';
+
        /**
         * Protected constructor
         *
        /**
         * Protected constructor
         *
@@ -111,6 +116,26 @@ class BaseResponse extends BaseFrameworkSystem {
                $this->responseBody = $output;
        }
 
                $this->responseBody = $output;
        }
 
+       /**
+        * Setter for response type
+        *
+        * @param       $responseType   Response type
+        * @return      void
+        */
+       protected final function setResponseType ($responseType) {
+               $this->responseType = $responseType;
+       }
+
+       /**
+        * Getter for response type
+        *
+        * @param       $responseType   Response type
+        * @return      void
+        */
+       public final function getResponseType () {
+               return $this->responseType;
+       }
+
        /**
         * Adds a fatal message id to the response. The added messages can then be
         * processed and outputed to the world
        /**
         * Adds a fatal message id to the response. The added messages can then be
         * processed and outputed to the world
@@ -131,7 +156,7 @@ class BaseResponse extends BaseFrameworkSystem {
         */
        public final function addFatalMessagePlain ($message) {
                // Adds the resolved message id to the fatal message list
         */
        public final function addFatalMessagePlain ($message) {
                // Adds the resolved message id to the fatal message list
-               $this->pushValueToGenericArrayElement('fatal_messages', 'generic', 'message', $message);
+               $this->pushValueToGenericArrayKey('fatal_messages', 'generic', 'message', $message);
        }
 
        /**
        }
 
        /**
@@ -181,7 +206,7 @@ class BaseResponse extends BaseFrameworkSystem {
                }
 
                // Are there some error messages?
                }
 
                // Are there some error messages?
-               if ($this->countGenericArrayElements('fatal_messages', 'generic', 'message') == 0) {
+               if ((!$this->isValidGenericArrayKey('fatal_messages', 'generic', 'message')) || ($this->countGenericArrayElements('fatal_messages', 'generic', 'message') == 0)) {
                        // Flush the output to the world
                        $this->getWebOutputInstance()->output($this->responseBody);
                } else {
                        // Flush the output to the world
                        $this->getWebOutputInstance()->output($this->responseBody);
                } else {
@@ -196,6 +221,28 @@ class BaseResponse extends BaseFrameworkSystem {
                $this->setResponseBody('');
                $this->resetResponseHeaders();
        }
                $this->setResponseBody('');
                $this->resetResponseHeaders();
        }
+
+       /**
+        * "Getter" for default command
+        *
+        * @return      $defaultCommand         Default command for this response
+        */
+       public function determineDefaultCommand () {
+               // Get application instance
+               $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+               // Generate config key
+               $configKey = sprintf('default_%s_%s_command',
+                       $applicationInstance->getAppShortName(),
+                       $this->getResponseType()
+               );
+
+               // Get default command response
+               $defaultCommand = $this->getConfigInstance()->getConfigEntry($configKey);
+
+               // Return it
+               return $defaultCommand;
+       }
 }
 
 // [EOF]
 }
 
 // [EOF]