X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Fhub%2Fmain%2Fhandler%2Fmessage-types%2Fclass_BaseMessageHandler.php;h=4763b03cdf7e14f3a54df533047745cd62e0919e;hb=4c4dbb818c6da362302cd02a601cce0c78413bfb;hp=5b93828568b600de49b132fe88579a7b5f615b70;hpb=f8fb89d6b4f9b4bfbd5498f784043542ea23ec88;p=hub.git diff --git a/application/hub/main/handler/message-types/class_BaseMessageHandler.php b/application/hub/main/handler/message-types/class_BaseMessageHandler.php index 5b9382856..4763b03cd 100644 --- a/application/hub/main/handler/message-types/class_BaseMessageHandler.php +++ b/application/hub/main/handler/message-types/class_BaseMessageHandler.php @@ -1,6 +1,7 @@ * @version 0.0.0 @@ -21,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class BaseMessageHandler extends BaseHandler { +abstract class BaseMessageHandler extends BaseHandler { /** * Array with search criteria elements */ @@ -32,6 +33,17 @@ class BaseMessageHandler extends BaseHandler { */ protected $messageDataElements = array(); + /** + * Array for translating message data elements (other node's data mostly) + * into configuration elements. + */ + protected $messageToConfig = array(); + + /** + * Last exception instance from database layer or NULL (default) + */ + private $lastException = NULL; + /** * Protected constructor * @@ -50,6 +62,34 @@ class BaseMessageHandler extends BaseHandler { ); } + /** + * Getter for last exception + * + * @return $lastException Last thrown exception + */ + protected final function getLastException () { + return $this->lastException; + } + + /** + * "Getter" for a translated last exception as a status code + * + * @return $statusCode Translated status code from last exception + */ + protected function getTranslatedStatusFromLastException () { + // Default is all fine + $statusCode = self::MESSAGE_STATUS_CODE_OKAY; + + // Is the last exception not NULL? + if ($this->lastException instanceof FrameworkException) { + // "Determine" the right status code (may differ from exception to exception) + $this->debugInstance('lastException=' . $this->lastException->__toString() . ',message=' . $this->lastException->getMessage() . ' is not finished!'); + } // END - if + + // Return the status code + return $statusCode; + } + /** * Registers an other node with this node by given message data. The * following data must always be present: @@ -88,6 +128,9 @@ class BaseMessageHandler extends BaseHandler { // Nothing found, so register it $wrapperInstance->registerNodeByMessageData($messageData, $this); } + + // Save last exception + $this->lastException = $wrapperInstance->getLastException(); } /** @@ -104,6 +147,12 @@ class BaseMessageHandler extends BaseHandler { // Load descriptor XML $helperInstance->loadDescriptorXml(); + /* + * Set missing (temporary) configuration data, mostly it needs to be + * copied from message data array. + */ + $this->initMessageConfigurationData($messageData); + // Compile any configuration variables $helperInstance->getTemplateInstance()->compileConfigInVariables(); @@ -112,7 +161,29 @@ class BaseMessageHandler extends BaseHandler { // Deliver the package $helperInstance->sendPackage($nodeInstance); + + /* + * Remove temporary configuration + */ + $this->removeMessageConfigurationData($messageData); } + + /** + * Initializes configuration data from given message data array + * + * @param $messageData An array with all message data + * @return void + */ + abstract protected function initMessageConfigurationData (array $messageData); + + /** + * Removes configuration data with given message data array from global + * configuration + * + * @param $messageData An array with all message data + * @return void + */ + abstract protected function removeMessageConfigurationData (array $messageData); } // [EOF]