From: Roland Häder Date: Thu, 29 Oct 2020 18:31:07 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a1f081c7e224b121d482f232581baabef1a7bb9d;p=hub.git Continued: - make sure $sessionId is set. If not, this indicates that PackageData::setSessionId() was not invoked. Signed-off-by: Roland Häder --- diff --git a/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php index 0fc3de48d..e2f7ceb01 100644 --- a/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -19,6 +19,9 @@ use Org\Mxchange\CoreFramework\Handler\DataSet\HandleableDataSet; use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\Result\Search\SearchableResult; +// Import SPL stuff +use \InvalidArgumentException; + /** * A database wrapper for distributed hash tables * @@ -307,10 +310,17 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp * * @param $sessionId Session id to lookup * @return $resultInstance An instance of a SearchableResult class + * @throws InvalidArgumentException If parameter $sessionId is not valid */ public function findNodeLocalBySessionId ($sessionId) { + // Validate parameter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: sessionId=%s - CALLED!', $sessionId)); + if (empty($sessionId)) { + // Cannot be empty + throw new InvalidArgumentException('Parameter "sessionId" is empty.'); + } + // Get search criteria - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: sessionId=' . $sessionId . ' - CALLED!'); $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Search for session id and limit it to one entry diff --git a/application/hub/classes/dht/node/class_NodeDhtFacade.php b/application/hub/classes/dht/node/class_NodeDhtFacade.php index 741db76e9..c2e992f3b 100644 --- a/application/hub/classes/dht/node/class_NodeDhtFacade.php +++ b/application/hub/classes/dht/node/class_NodeDhtFacade.php @@ -17,6 +17,9 @@ use Org\Mxchange\CoreFramework\Handler\DataSet\HandleableDataSet; use Org\Mxchange\CoreFramework\Registry\Registerable; use Org\Mxchange\CoreFramework\Result\Search\SearchableResult; +// Import SPL stuff +use \InvalidArgumentException; + /** * A Node DHT facade class * @@ -162,8 +165,14 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { * @return $nodeData Node-data array */ public function findNodeLocalBySessionId ($sessionId) { - // Default is empty data array + // Validate parameter /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: sessionId=%s - CALLED!', $sessionId)); + if (empty($sessionId)) { + // Cannot be empty + throw new InvalidArgumentException('Parameter "sessionId" is empty.'); + } + + // Default is empty data array $nodeData = array(); /* diff --git a/application/hub/interfaces/database/frontend/class_NodeDhtWrapper.php b/application/hub/interfaces/database/frontend/class_NodeDhtWrapper.php index 2949a8b25..e73f9720f 100644 --- a/application/hub/interfaces/database/frontend/class_NodeDhtWrapper.php +++ b/application/hub/interfaces/database/frontend/class_NodeDhtWrapper.php @@ -70,6 +70,7 @@ interface NodeDhtWrapper extends DatabaseWrapper { * * @param $sessionId Session id to lookup * @return $resultInstance An instance of a SearchableResult class + * @throws InvalidArgumentException If parameter $sessionId is not valid */ function findNodeLocalBySessionId ($sessionId); diff --git a/application/hub/interfaces/distributable/node/class_DistributableNode.php b/application/hub/interfaces/distributable/node/class_DistributableNode.php index 0699f318c..b1fc19791 100644 --- a/application/hub/interfaces/distributable/node/class_DistributableNode.php +++ b/application/hub/interfaces/distributable/node/class_DistributableNode.php @@ -38,6 +38,7 @@ interface DistributableNode extends Distributable { * * @param $sessionId Session id to lookup * @return $nodeData Node-data array + * @throws InvalidArgumentException If parameter $sessionId is not valid */ function findNodeLocalBySessionId ($sessionId);