]> git.mxchange.org Git - core.git/blobdiff - inc/classes/main/container/socket/class_SocketContainer.php
'public static final' is correct
[core.git] / inc / classes / main / container / socket / class_SocketContainer.php
index eff4ca18d7878d61a04cfa10a55ef55f1a47a462..72e83acbdd2bd4e4a751582761f400e1c83ecd8a 100644 (file)
@@ -36,18 +36,43 @@ 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       $protocolInstance       A ProtocolHandler instance
+        * @param       $packageData            Raw package data
         * @return      $containerInstance      An instance of this Container class
         */
-       public final static function createSocketContainer ($socketResource) {
+       public static final function createSocketContainer ($socketResource, ProtocolHandler $protocolInstance, array $packageData) {
                // Get a new instance
                $containerInstance = new SocketContainer();
 
-               // Set the resource
+               // Set the resource ...
                $containerInstance->setSocketResource($socketResource);
 
+               // ..., protocol instance ...
+               $containerInstance->setProtocolInstance($protocolInstance);
+
+               // ... and package data
+               $containerInstance->setPackageData($packageData);
+
                // Return the prepared instance
                return $containerInstance;
        }
+
+       /**
+        * Checks wether the given address (IP) matches with the one from the socket resource
+        *
+        * @param       $addressPort    The address:port (IP to check
+        * @return      $matches                Wether $address matches with the one from socket resource
+        */
+       public final function ifAddressMatches ($addressPort) {
+               // Get current package data
+               $data = $this->getPackageData();
+
+               // So, does both match?
+               $matches = ((isset($data['recipient'])) && ($data['recipient'] === $addressPort));
+
+               // Return result
+               return $matches;
+       }
 }
 
 // [EOF]