]> git.mxchange.org Git - hub.git/commitdiff
Rewrote unit source factory to registry pattern
authorRoland Häder <roland@mxchange.org>
Sat, 30 Apr 2011 00:11:14 +0000 (00:11 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 30 Apr 2011 00:11:14 +0000 (00:11 +0000)
application/hub/main/factories/source/units/class_UnitSourceFactory.php

index 6c9ded7348e9a8200057b4939b8396faaf76785a..1afe986aeb93755ef5d08e04d02e895d454cc5a4 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class UnitSourceFactory extends ObjectFactory {
-       /**
-        * Source instances
-        */
-       private static $sourceInstances = array();
-
        /**
         * Protected constructor
         *
@@ -45,16 +40,22 @@ class UnitSourceFactory extends ObjectFactory {
         */
        public static final function createUnitSourceInstance ($unitType) {
                // Do we have cache?
-               if (!isset(self::$sourceInstances[$unitType])) {
+               if (!Registry::getRegistry()->instanceExists($unitType . '_unit_source')) {
                        // Then construct the class' configuraton entry
                        $className = '' . $unitType . '_unit_source_class';
 
                        // Get a class from that configuration entry
-                       self::$sourceInstances[$unitType] = self::createObjectByConfiguredName($className);
-               } // END - if
+                       $sourceInstance = self::createObjectByConfiguredName($className);
+
+                       // Add it to the registry
+                       Registry::getRegistry()->addInstance($unitType . '_unit_source', $sourceInstance);
+               } else {
+                       // Get it from registry
+                       $sourceInstance = Registry::getRegistry()->getInstance($unitType . '_unit_source');
+               }
 
                // For any purposes, return the source instance
-               return self::$sourceInstances[$unitType];
+               return $sourceInstance;
        }
 }