]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/factories/socket/class_SocketFactory.php
Some global cleanups:
[hub.git] / application / hub / main / factories / socket / class_SocketFactory.php
index 42a82da7e03986755b46da176ab2f702f0352ceb..a3eae6e97fe26d3149f65497d6e6635614b8fec5 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  * @todo               Find an interface for hub helper
@@ -41,11 +41,29 @@ class SocketFactory extends BaseHubHelper {
         * @return      $socketResource         Socket resource
         */
        public static function createSocketFromPackageData (array $packageData, $protocolName) {
-               // Construct configuration entry for object factory
-               $configEntry = $protocolName . '_connection_class';
+               // Construct registry key
+               $registryKey = 'socket_' . $protocolName . '_' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT];
 
-               // And call the static method
-               $socketResource = call_user_func(FrameworkConfiguration::getInstance()->getConfigEntry($configEntry) . '::createConnectionFromPackageData', $packageData);
+               // Is the key there?
+               if (Registry::getRegistry()->instanceExists($registryKey)) {
+                       // Get container instance
+                       $containerInstance = Registry::getRegistry()->getInstance($registryKey);
+
+                       // Get socket back
+                       $socketResource = $containerInstance->getSocketResource();
+               } else {
+                       // Construct configuration entry for object factory and get it
+                       $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry($protocolName . '_connection_helper_class');
+
+                       // And call the static method
+                       $socketResource = call_user_func($className . '::createConnectionFromPackageData', $packageData);
+
+                       // Construct container class, this won't be reached if an exception is thrown
+                       $containerInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, NULL, $packageData));
+
+                       // Register it with the registry
+                       Registry::getRegistry()->addInstance($registryKey, $containerInstance);
+               }
 
                // Return the resource
                return $socketResource;