$listInstance = RecipientListFactory::createRecipientListInstance();
// We do some rudimentary checks but this might be a bit ugly
- switch ($packageData['recipient']) {
+ switch ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) {
// All upper hubs, these are currently the bootstrap nodes and later on prepended list-nodes
case NetworkPackage::NETWORK_TARGET_UPPER_HUBS:
// Get all bootstrap nodes
// This may be a direct recipient (hub's session id)
default:
- $this->partialStub('Please add code handling recipients ' . $packageData['recipient']);
+ $this->partialStub('Please add code handling recipients ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
break;
} // END - switch
}
$ownAddress = Registry::getRegistry()->getInstance('node')->getAddressPort($this);
// Does it match?
+ // @TODO Numeric or alpha-numeric index?
$matches = ($ownAddress === $packageData[NetworkPackage::INDEX_PACKAGE_RECIPIENT]);
// Return result
$helperInstance->setSocketResource($socketResource);
// Resolve any session ids; 0 = IP, 1 = Port
- $recipientData = explode(':', HubTools::resolveSessionId($packageData['recipient']));
+ $recipientData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
// Set ip/port
$helperInstance->setAddress($recipientData[0]);
const INDEX_PACKAGE_RECIPIENT = 1;
const INDEX_PACKAGE_CONTENT = 2;
+ /**
+ * Named array elements for package data
+ */
+ const PACKAGE_DATA_RECIPIENT = 'recipient';
+ const PACKAGE_DATA_SENDER = 'sender';
+ const PACKAGE_DATA_CONTENT = 'content';
+
/**
* Tags seperator
*/
$this->debugOutput('PACKAGE: Package declared for recipient ' . $currentRecipient);
// Set the recipient
- $packageData['recipient'] = $currentRecipient;
+ $packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient;
// And enqueue it to the writer class
$this->getStackerInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData);
// Now prepare the temporary array and push it on the 'undeclared' stack
$this->getStackerInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array(
- 'sender' => $nodeInstance->getSessionId(),
- 'recipient' => $helperInstance->getRecipientType(),
- 'content' => $content,
+ self::PACKAGE_DATA_SENDER => $nodeInstance->getSessionId(),
+ self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(),
+ self::PACKAGE_DATA_CONTENT => $content,
));
}
*/
private function getProcessedPackagesIndex (array $packageData) {
return (
- $packageData['sender'] . NetworkPackage::PACKAGE_DATA_SEPERATOR .
- $packageData['recipient'] . NetworkPackage::PACKAGE_DATA_SEPERATOR .
- $packageData['content'] . NetworkPackage::PACKAGE_DATA_SEPERATOR
+ $packageData[NetworkPackage::PACKAGE_DATA_SENDER] . NetworkPackage::PACKAGE_DATA_SEPERATOR .
+ $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . NetworkPackage::PACKAGE_DATA_SEPERATOR .
+ $packageData[NetworkPackage::PACKAGE_DATA_CONTENT] . NetworkPackage::PACKAGE_DATA_SEPERATOR
);
}
// This is always a SubRegistry instance
foreach ($registryInstance->getInstanceRegistry() as $subKey=>$containerInstance) {
// This is a SocketContainer instance, so does the recipient match?
- if ($containerInstance->ifAddressMatches($packageData['recipient'])) {
+ if ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) {
// Found one, so get the protocol instance and abort
$protocolInstance = $containerInstance->getProtocolInstance();
break;
* 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.
*/
- $contentData = explode(NetworkPackage::PACKAGE_MASK_SEPERATOR, $packageData['content']);
+ $contentData = explode(NetworkPackage::PACKAGE_MASK_SEPERATOR, $packageData[NetworkPackage::PACKAGE_DATA_CONTENT]);
// Get the tags and store them locally
$this->setTags(explode(NetworkPackage::PACKAGE_TAGS_SEPERATOR, $contentData[NetworkPackage::INDEX_TAGS]));