}
/**
- * 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
// 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]