From b0b8a33da8250dd9eb738df6e4be4e5aaabb9ca7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 23 Jun 2013 19:18:09 +0000 Subject: [PATCH] Added assert() calls to make sure the package is valid --- .../package/class_PackageRecipientDiscovery.php | 1 + .../hub/main/package/class_NetworkPackage.php | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php index ce5d075a7..ae48aa47b 100644 --- a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php +++ b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php @@ -60,6 +60,7 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable */ public function discoverRecipients (array $packageData) { // This must be available + //* DEBUG: */ print $this->__toString() . ': packageData=' . print_r($packageData, TRUE); assert(isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); // First try out the direct recipient (session id) diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 820288276..c050b3e1c 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -408,6 +408,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * @return void */ private function declareRawPackageData (array $packageData) { + // Make sure the required field is there + assert(isset($packageData[self::PACKAGE_DATA_RECIPIENT])); + /* * We need to disover every recipient, just in case we have a * multi-recipient entry like 'upper' is. 'all' may be a not so good @@ -697,13 +700,10 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * Now there are for sure packages to deliver, so start with the first * one. */ - $packageData = $this->getStackerInstance()->getNamed(self::STACKER_NAME_UNDECLARED); + $packageData = $this->getStackerInstance()->popNamed(self::STACKER_NAME_UNDECLARED); // Declare the raw package data for delivery $this->declareRawPackageData($packageData); - - // And remove it finally - $this->getStackerInstance()->popNamed(self::STACKER_NAME_UNDECLARED); } /** @@ -724,6 +724,10 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Get the package $packageData = $this->getStackerInstance()->getNamed(self::STACKER_NAME_DECLARED); + // Assert on it + assert($packageData[self::PACKAGE_DATA_RECIPIENT]); + + // Try to deliver the package try { // And try to send it $this->deliverRawPackageData($packageData); -- 2.39.5