A class implementing ShareableInfo shall now be handled over.
authorRoland Haeder <roland@mxchange.org>
Thu, 29 Jan 2015 20:46:59 +0000 (21:46 +0100)
committerRoland Haeder <roland@mxchange.org>
Thu, 29 Jan 2015 20:46:59 +0000 (21:46 +0100)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/classes/interfaces/registry/socket/class_RegisterableSocket.php
inc/classes/main/container/socket/class_SocketContainer.php

index 84f3c05ceeb056bd807ec59e14558732c9d385ed..6e3e2be72b888b135e7b42325e113176b9351f96 100644 (file)
@@ -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
index 66900af5309622e903930f3def7bfa987af2ae7a..656f81d12813d17cc6121e729bcd0bb7a608f099 100644 (file)
@@ -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