From: Roland Haeder Date: Thu, 29 Jan 2015 20:46:59 +0000 (+0100) Subject: A class implementing ShareableInfo shall now be handled over. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3ca66c867ea6a3ea6b10a805df94c1e4938aece3;p=core.git A class implementing ShareableInfo shall now be handled over. Signed-off-by: Roland Häder --- diff --git a/inc/classes/interfaces/registry/socket/class_RegisterableSocket.php b/inc/classes/interfaces/registry/socket/class_RegisterableSocket.php index 84f3c05c..6e3e2be7 100644 --- a/inc/classes/interfaces/registry/socket/class_RegisterableSocket.php +++ b/inc/classes/interfaces/registry/socket/class_RegisterableSocket.php @@ -26,21 +26,21 @@ interface RegisterableSocket extends Registerable { * Checks whether given socket resource is registered. If $socketResource is * FALSE only the instance will be checked. * - * @param $listenerInstance An instance of a Listenable class + * @param $infoInstance An instance of a ShareableInfo class * @param $socketResource A valid socket resource * @return $isRegistered Whether the given socket resource is registered */ - function isSocketRegistered (Listenable $listenerInstance, $socketResource); + function isSocketRegistered (ShareableInfo $infoInstance, $socketResource); /** * Registeres given socket for listener or throws an exception if it is already registered * - * @param $listenerlInstance An instance of a Listenable class + * @param $infoInstance An instance of a ShareableInfo class * @param $socketResource A valid socket resource * @return void * @throws SocketAlreadyRegisteredException If the given socket is already registered */ - function registerSocket (Listenable $listenerInstance, $socketResource); + function registerSocket (ShareableInfo $infoInstance, $socketResource); /** * Getter for given listener's socket resource diff --git a/inc/classes/main/container/socket/class_SocketContainer.php b/inc/classes/main/container/socket/class_SocketContainer.php index 66900af5..656f81d1 100644 --- a/inc/classes/main/container/socket/class_SocketContainer.php +++ b/inc/classes/main/container/socket/class_SocketContainer.php @@ -36,11 +36,11 @@ class SocketContainer extends BaseContainer implements Registerable { * Creates an instance of this Container class and prepares it for usage * * @param $socketResource A valid socket resource - * @param $listenerInstance A Listenable instance + * @param $infoInstance An instance of a ShareableInfo class * @param $packageData Raw package data * @return $containerInstance An instance of this Container class */ - public static final function createSocketContainer ($socketResource, Listenable $listenerInstance = NULL, array $packageData = array()) { + public static final function createSocketContainer ($socketResource, ShareableInfo $infoInstance = NULL, array $packageData = array()) { // Get a new instance $containerInstance = new SocketContainer(); @@ -51,15 +51,21 @@ class SocketContainer extends BaseContainer implements Registerable { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-CONTAINER[' . __METHOD__ . ':' . __LINE__ . ']:socketResource=' . $socketResource . ',packageData='.print_r($packageData, TRUE)); - // Set the resource ... - $containerInstance->setSocketResource($socketResource); + // Is the info instance set? + if ($infoInstance instanceof ShareableInfo) { + // Get listener from info class + $listenerInstance = $infoInstance->getListenerInstance(); - // Is a listener instance given? - if ($listenerInstance instanceof Listenable) { - // ..., listener instance ... - $containerInstance->setListenerInstance($listenerInstance); + // Is there a listener instance set? + if ($listenerInstance instanceof Listenable) { + // Set it here for later usage + $containerInstance->setListenerInstance($listenerInstance); + } // END - if } // END - if + // Set the resource ... + $containerInstance->setSocketResource($socketResource); + // ... and package data $containerInstance->setPackageData($packageData); @@ -70,19 +76,18 @@ class SocketContainer extends BaseContainer implements Registerable { /** * Checks whether the given Universal Node Locator matches with the one from package data * - * @param $unlInstance An instance of a LocateableNode class - * @return $matches Whether $address matches with the one from package data + * @param $unl A Universal Node Locator + * @return $matches Whether $address matches with the one from package data */ - public final function ifAddressMatches (LocateableNode $unlInstance) { + public final function ifAddressMatches ($unl) { // Get current package data $packageData = $this->getPackageData(); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-CONTAINER: unlInstance=' . print_r($unlInstance, TRUE) . ',packageData=' . print_r($packageData, TRUE)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-CONTAINER: unl=' . $unl . ',packageData=' . print_r($packageData, TRUE)); // So, does both match? - die(__METHOD__ . ': Unfinished.' . PHP_EOL); - $matches = ((isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) && ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] === $unlInstance)); + $matches = ((isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) && ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] === $unl)); // Return result return $matches; @@ -91,8 +96,8 @@ class SocketContainer extends BaseContainer implements Registerable { /** * Checks whether the given socket matches with stored * - * @param $unlInstance An instance of a LocateableNode class - * @return $matches Whether given socket matches + * @param $socketResource A valid socket resource + * @return $matches Whether given socket matches */ public final function ifSocketResourceMatches ($socketResource) { // Debug message