]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/factories/handler/class_ProtocolHandlerFactory.php
A lot changes for refacturing protocol handler
[hub.git] / application / hub / main / factories / handler / class_ProtocolHandlerFactory.php
index 6955bd0a4f1ef49d3e684b42825ee5c6e0efe835..12ada2e94afa906ef96fa7759ae95ad5d525d6ee 100644 (file)
@@ -34,17 +34,12 @@ class ProtocolHandlerFactory extends ObjectFactory {
        }
 
        /**
-        * Returns a singleton protocol handler instance from given HubHelper
-        * instance. If an instance is found in registry, it will be returned, else
-        * a new instance is created and stored in the same registry entry.
+        * Returns a protocol handler based on given protocol type. This is mostly 'tcp'.
         *
-        * @param       $helperInstance         An instance of a HubHelper class
+        * @param       $protocolType           Protocol type to create/return a protocol handler instance for
         * @return      $handlerInstance        A protocol handler instance
         */
-       public static final function createProtocolHandlerFromRecipientHelper (HubHelper $helperInstance) {
-               // Get the protocol type from given helper instance
-               die(__METHOD__ . ':' . print_r($helperInstance, TRUE));
-
+       private static function createProtocolHandlerByType ($protocolType) {
                // Do we have an instance in the registry?
                if (Registry::getRegistry()->instanceExists($protocolType . '_protocol_handler')) {
                        // Then use this instance
@@ -60,6 +55,39 @@ class ProtocolHandlerFactory extends ObjectFactory {
                // Return the instance
                return $handlerInstance;
        }
+
+       /**
+        * Returns a singleton protocol handler instance from given HubHelper
+        * instance. If an instance is found in registry, it will be returned, else
+        * a new instance is created and stored in the same registry entry.
+        *
+        * @param       $helperInstance         An instance of a HubHelper class
+        * @return      $handlerInstance        A protocol handler instance
+        */
+       public static final function createProtocolHandlerFromRecipientHelper (HubHelper $helperInstance) {
+               // Get the protocol type from given helper instance
+               $protocolType = $helperInstance->determineProtocolType();
+
+               // Call super factory method
+               return self::createProtocolHandlerByType($protocolType);
+       }
+
+       /**
+        * Creates an instance of a protocol handler from given (raw) package data
+        *
+        * @param       $packageData            An array with raw package data
+        * @return      $handlerInstance        A protocol handler instance
+        */
+       public static final function createProtocolHandlerFromPackageData (array $packageData) {
+               // Now that there is no direct node instance available, a protocol discovery class is required
+               $discoveryInstance = ObjectFactory::createObjectByConfiguredName('protocol_discovery_class');
+
+               // "Discover" the protocol type
+               $protocolType = $discoveryInstance->discoverProtocolByPackageData($packageData);
+
+               // Call super factory method
+               return self::createProtocolHandlerByType($protocolType);
+       }
 }
 
 // [EOF]