*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
*
const EXCEPTION_INVALID_TAG = 0x160;
/**
- * Last found protocol
+ * Last found protocol instance
*/
- private $lastProtocol = 'invalid';
+ private $lastProtocol = NULL;
/**
* Last found recipient type
*/
private function initObjectRegistry () {
// Output debug message
- self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __LINE__ . ']: Initializing object registry - START');
+ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Initializing object registry - START');
// Get the application instance
$applicationInstance = Registry::getRegistry()->getInstance('app');
$this->getTemplateInstance()->renderXmlContent();
// Output debug message
- self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __LINE__ . ']: Initializing object registry - FINISHED');
+ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Initializing object registry - FINISHED');
}
/**
* @return void
*/
private function extractTagsFromPackageData (array $packageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: packageData=' . print_r($packageData, TRUE));
+
/*
* We take a look at the tags (in most cases only one is needed) so
* first we need the content data splitted up into all it's parts.
* shared over the whole hub-network. So if the "tag" (let's better say
* object type) isn't found in that XML the package won't be distributed.
*
+ * @param $packageData Raw package data
* @return void
* @throws InvalidTagException If a provided tag from the package data is invalid
*/
- private function verifyAllTags () {
+ private function verifyAllTags (array $packageData) {
// Get the registry
$objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance();
// "Walk" over all tags
foreach ($this->getTags() as $tag) {
// Debug output
- self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __LINE__ . ']: Validating tag ' . $tag . ' ...');
+ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: Validating tag ' . $tag . ' ...');
// Get an array from this tag
$entry = $objectRegistryInstance->getArrayFromKey(XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_NAME, $tag);
- // If the array is empty, the entry is invalid!
- if ((count($entry) == 0) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_PROTOCOL])) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE]))) {
+ /*
+ * If it is no array or the array is empty or an entry is missing
+ * the entry is invalid.
+ */
+ if ((!is_array($entry)) || (count($entry) == 0) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_PROTOCOL])) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE]))) {
// Invalid entry found
throw new InvalidTagException(array($this, $tag), self::EXCEPTION_INVALID_TAG);
} // END - if
// Now save the last discovered protocol/recipient type
- $this->lastProtocol = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_PROTOCOL];
+ $this->lastProtocol = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
$this->lastRecipientType = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE];
} // END - foreach
}
* Chooses the right protocol from given package data
*
* @param $packageData Raw package data
- * @return $protocolName Name of the choosen procotol
+ * @return $lastProtocol An instance of the last used HandleableProtocol class
*/
public function chooseProtocolFromPackageData (array $packageData) {
// Extract the tags
$this->extractTagsFromPackageData($packageData);
// Now we need to verify every single tag
- $this->verifyAllTags();
-
- // Use the last found protocol for transmission
- $protocolName = $this->lastProtocol;
+ $this->verifyAllTags($packageData);
- // Return it
- return $protocolName;
+ // Return the last (and only) found protocol (e.g. 'tcp' is very usual)
+ return $this->lastProtocol;
}
/**
$this->extractTagsFromPackageData($packageData);
// Now we need to verify every single tag
- $this->verifyAllTags();
+ $this->verifyAllTags($packageData);
// Now simply check it out
$accepts = (($this->lastRecipientType == $listenerInstance->getListenerType()) && ($listenerInstance->getListenerType() != 'invalid'));