Used self::createDebugInstance(__CLASS__)->debugOutput() instead of $fooInstance...
[core.git] / inc / classes / main / container / socket / class_SocketContainer.php
index 3794084971b5938fa5bf68e4e9c814032dc9738c..445a90f09be4fb6b55505bf80f11b34a2daafefb 100644 (file)
@@ -40,10 +40,17 @@ class SocketContainer extends BaseContainer implements Registerable {
         * @param       $packageData            Raw package data
         * @return      $containerInstance      An instance of this Container class
         */
-       public static final function createSocketContainer ($socketResource, ProtocolHandler $protocolInstance = NULL, array $packageData) {
+       public static final function createSocketContainer ($socketResource, ProtocolHandler $protocolInstance = NULL, array $packageData = array()) {
                // Get a new instance
                $containerInstance = new SocketContainer();
 
+               // Remove unneeded entries
+               unset($packageData[NetworkPackage::PACKAGE_DATA_CONTENT]);
+               unset($packageData[NetworkPackage::PACKAGE_DATA_SIGNATURE]);
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__ . ':socketResource=' . $socketResource . ',packageData='.print_r($packageData,true));
+
                // Set the resource ...
                $containerInstance->setSocketResource($socketResource);
 
@@ -65,10 +72,30 @@ class SocketContainer extends BaseContainer implements Registerable {
         */
        public final function ifAddressMatches ($addressPort) {
                // Get current package data
-               $data = $this->getPackageData();
+               $packageData = $this->getPackageData();
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-CONTAINER: addressPort=' . $addressPort . ',packageData=' . print_r($packageData, true));
+
+               // So, does both match?
+               $matches = ((isset($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) && ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] === $addressPort));
+
+               // Return result
+               return $matches;
+       }
+
+       /**
+        * Checks whether the given socket matches with stored
+        *
+        * @param       $addressPort    The address:port (IP to check
+        * @return      $matches                Whether given socket matches
+        */
+       public final function ifSocketResourceMatches ($socketResource) {
+               // Debug message
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-CONTAINER: socketResource[' . gettype($socketResource) . ']=' .$socketResource . ',storedResource[' . gettype($this->getSocketResource()) . ']=' . $this->getSocketResource());
 
                // So, does both match?
-               $matches = ((isset($data['recipient'])) && ($data['recipient'] === $addressPort));
+               $matches = ((is_resource($socketResource)) && ($socketResource === $this->getSocketResource()));
 
                // Return result
                return $matches;