]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/helper/class_BaseHelper.php
More stubs added, code "made" generic:
[shipsimu.git] / inc / classes / main / helper / class_BaseHelper.php
index dab6791f0e8830a4bdd4b2abce2fff30d4b3f4b7..a40193d3d3adec9a7040f0a6eca61947b048af9e 100644 (file)
@@ -109,17 +109,33 @@ class BaseHelper extends BaseFrameworkSystem {
         * Pre-fetches field default values from the given registry key instance into this class
         *
         * @param       $registryKey    Registry key which holds an object with values
+        * @param       $extraKey               Extra value instance key used if registryKey is null
         * @return      void
-        * @throws      NullPointerException    If an instance from registry is null
+        * @throws      NullPointerException    If recovery of requested value instance failed
         */
-       public function prefetchValueInstance ($registryKey) {
+       public function prefetchValueInstance ($registryKey, $extraKey = null) {
                // Get the required instance
                $this->valueInstance = Registry::getRegistry()->getInstance($registryKey);
 
                // Is the instance valid?
                if (is_null($this->valueInstance)) {
-                       // Throw an exception
-                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+                       // Try to create it "from scratch", by first init extra instance
+                       $extraInstance = null;
+
+                       // Shall we get an extra instance?
+                       if (!is_null($extraKey)) {
+                               // Get the extra instance.
+                               $extraInstance = Registry::getRegistry()->getInstance($extraKey);
+                       } // END - if
+
+                       // Get the requested instance
+                       try {
+                               $this->valueInstance = ObjectFactory::createObjectByConfiguredName($registryKey . '_class', array($extraInstance));
+
+                       } catch (FrameworkException $e) {
+                               // Okay, nothing found so throw a null pointer exception here
+                               throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+                       }
                } // END - if
        }
 
@@ -136,6 +152,15 @@ class BaseHelper extends BaseFrameworkSystem {
                // Return it
                return $fieldValue;
        }
+
+       /**
+        * Getter for value instance
+        *
+        * @return      $valueInstance  Instance of the class holding our values
+        */
+       public final function getValueInstance () {
+               return $this->valueInstance;
+       }
 }
 
 // [EOF]