]> git.mxchange.org Git - core.git/commitdiff
Introduced isFieldSet().
authorRoland Haeder <roland@mxchange.org>
Sat, 18 Apr 2015 01:52:56 +0000 (03:52 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 18 Apr 2015 01:55:07 +0000 (03:55 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/classes/interfaces/class_FrameworkInterface.php
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/helper/class_BaseHelper.php
inc/config/class_FrameworkConfiguration.php

index 123f9c9fab17e41918a0fc2e3560baa82da7e95f..724e57d7e47b3bebaf884152eb2fa688d96466a7 100644 (file)
@@ -33,6 +33,15 @@ interface FrameworkInterface {
         */
        function getField ($fieldName);
 
         */
        function getField ($fieldName);
 
+       /**
+        * Checks if given field is set
+        *
+        * @param       $fieldName      Field name to check
+        * @return      $isSet          Whether the given field name is set
+        * @throws      NullPointerException    If the result instance is null
+        */
+       function isFieldSet ($fieldName);
+
        /**
         * Checks whether an object equals this object. You should overwrite this
         * method to implement own equality checks
        /**
         * Checks whether an object equals this object. You should overwrite this
         * method to implement own equality checks
index 94c13b750e3af3ccf586a58f070cb36472aaaa4e..2e42a794b12018efe454f560730ca1a54d9e6d3a 100644 (file)
@@ -1997,12 +1997,12 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, TRUE).'</pre>');
 
                // Convert dashes to underscore
                //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, TRUE).'</pre>');
 
                // Convert dashes to underscore
-               $fieldName = $this->convertDashesToUnderscores($fieldName);
+               $fieldName2 = $this->convertDashesToUnderscores($fieldName);
 
                // Does the field exist?
 
                // Does the field exist?
-               if (isset($fieldArray[$fieldName])) {
+               if ($this->isFieldSet($fieldName)) {
                        // Get it
                        // Get it
-                       $fieldValue = $fieldArray[$fieldName];
+                       $fieldValue = $fieldArray[$fieldName2];
                } elseif (defined('DEVELOPER')) {
                        // Missing field entry, may require debugging
                        self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldArray<pre>=' . print_r($fieldArray, TRUE) . '</pre>,fieldName=' . $fieldName . ' not found!');
                } elseif (defined('DEVELOPER')) {
                        // Missing field entry, may require debugging
                        self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']:fieldArray<pre>=' . print_r($fieldArray, TRUE) . '</pre>,fieldName=' . $fieldName . ' not found!');
@@ -2015,6 +2015,37 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $fieldValue;
        }
 
                return $fieldValue;
        }
 
+       /**
+        * Checks if given field is set
+        *
+        * @param       $fieldName      Field name to check
+        * @return      $isSet          Whether the given field name is set
+        * @throws      NullPointerException    If the result instance is null
+        */
+       public function isFieldSet ($fieldName) {
+               // Get result instance
+               $resultInstance = $this->getResultInstance();
+
+               // Is this instance null?
+               if (is_null($resultInstance)) {
+                       // Then the user instance is no longer valid (expired cookies?)
+                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+               } // END - if
+
+               // Get current array
+               $fieldArray = $resultInstance->current();
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . $this->__toString() . ':' . __LINE__ . '] fieldName=' . $fieldName . ',fieldArray=<pre>'.print_r($fieldArray, TRUE).'</pre>');
+
+               // Convert dashes to underscore
+               $fieldName = $this->convertDashesToUnderscores($fieldName);
+
+               // Determine it
+               $isSet = isset($fieldArray[$fieldName]);
+
+               // Return result
+               return $isSet;
+       }
+
        /**
         * Flushs all pending updates to the database layer
         *
        /**
         * Flushs all pending updates to the database layer
         *
index 45b74bb3cf1a33d1ed7ee866f06003e73e47ded0..f0d436f0fa8bf25518f44b2559c3daeae278d651 100644 (file)
@@ -455,22 +455,29 @@ class BaseHelper extends BaseFrameworkSystem {
         * @throws      NullPointerException    Thrown if $valueInstance is null
         */
        public function getValueField ($fieldName) {
         * @throws      NullPointerException    Thrown if $valueInstance is null
         */
        public function getValueField ($fieldName) {
+               // Init value
+               $fieldValue = NULL;
+
                // The $valueInstance attribute should not be null!
                if (is_null($this->getValueInstance())) {
                        // Throws an exception here
                        throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
                } // END - if
 
                // The $valueInstance attribute should not be null!
                if (is_null($this->getValueInstance())) {
                        // Throws an exception here
                        throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
                } // END - if
 
-               // Get the field value
-               $fieldValue = $this->getValueInstance()->getField($fieldName);
-               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.'[]='.gettype($fieldValue).'('.strlen($fieldValue).') - BEFORE!');
-
-               // Is it null?
-               if ((is_null($fieldValue)) && (!is_null($this->extraInstance))) {
+               // Is the field set?
+               if ($this->getValueInstance()->isFieldSet($fieldName)) {
+                       // Get the field value
+                       $fieldValue = $this->getValueInstance()->getField($fieldName);
+                       //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.'[]='.gettype($fieldValue).'('.strlen($fieldValue).') - Value instance!');
+               } elseif ((!is_null($this->extraInstance)) && ($this->extraInstance->isFieldSet($fieldName))) {
                        // So try the extra instance
                        $fieldValue = $this->extraInstance->getField($fieldName);
                        // So try the extra instance
                        $fieldValue = $this->extraInstance->getField($fieldName);
+                       //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.'[]='.gettype($fieldValue).'('.strlen($fieldValue).') - Extra instance!');
+               } else {
+                       // Field is not set
+                       if ((!is_null($this->extraInstance)) && ($fieldName == 'city_name')) die('<pre>'.print_r($this->extraInstance, TRUE).'</pre>');
+                       $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] fieldName=' . $fieldName . ' is not set! - @TODO');
                } // END - if
                } // END - if
-               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput($fieldName.'[]='.gettype($fieldValue).'('.strlen($fieldValue).') - AFTER!');
 
                // Return it
                return $fieldValue;
 
                // Return it
                return $fieldValue;
index a49d4aa966b06c1726daa6b4adb2ab3f10893af3..8d786742b6492a6589cdc576617a4fd782fd5512 100644 (file)
@@ -361,6 +361,17 @@ class FrameworkConfiguration implements Registerable {
                // Our super interface "FrameworkInterface" requires this
        }
 
                // Our super interface "FrameworkInterface" requires this
        }
 
+       /**
+        * Checks if given field is set
+        *
+        * @param       $fieldName      Field name to check
+        * @return      $isSet          Whether the given field name is set
+        * @throws      NullPointerException    If the result instance is null
+        */
+       public function isFieldSet ($fieldName) {
+               // Our super interface "FrameworkInterface" requires this
+       }
+
        /**
         * Generates a code for hashes from this class
         *
        /**
         * Generates a code for hashes from this class
         *