Added hexval() which really stupid regex
[core.git] / inc / classes / main / class_BaseFrameworkSystem.php
index d42cfc3968cf0c06554df81e1d23c10c3dbb2015..4b2812dc41adfc530e6fbbb9fe106b0d69f71dc4 100644 (file)
@@ -1004,6 +1004,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      void
         */
        public final function setSocketResource ($socketResource) {
+               //* NOISY-DEBUG: */ $this->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource=' . $socketResource . ',previous[' . gettype($this->socketResource) . ']=' . $this->socketResource);
                $this->socketResource = $socketResource;
        }
 
@@ -1012,7 +1013,8 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         *
         * @return      $socketResource         A valid socket resource
         */
-       public function getSocketResource () {
+       public final function getSocketResource () {
+               //* NOISY-DEBUG: */ $this->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': socketResource[' . gettype($this->socketResource) . ']=' . $this->socketResource);
                return $this->socketResource;
        }
 
@@ -1398,8 +1400,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      void
         */
        public function debugOutput ($message, $doPrint = true) {
-               // Get debug instance
-               $debugInstance = $this->getDebugInstance();
+               // Set debug instance to NULL
+               $debugInstance = NULL;
+
+               // Try it:
+               try {
+                       // Get debug instance
+                       $debugInstance = $this->getDebugInstance();
+               } catch (NullPointerException $e) {
+                       // The debug instance is not set (yet)
+               }
 
                // Is the debug instance there?
                if (is_object($debugInstance)) {
@@ -1628,6 +1638,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                $fieldArray = $resultInstance->current();
                //* DEBUG: */ $this->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
 
+               // Convert dashes to underscore
+               $fieldName = $this->convertDashesToUnderscores($fieldName);
+
                // Does the field exist?
                if (isset($fieldArray[$fieldName])) {
                        // Get it
@@ -2031,6 +2044,27 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Return result
                return $ret;
        }
+
+       /**
+        * Checks whether the given hexadecimal number is really a hex-number (only chars 0-9,a-f).
+        *
+        * @param       $num    A string consisting only chars between 0 and 9
+        * @param       $assertMismatch         Whether to assert mismatches
+        * @return      $ret    The (hopefully) secured hext-numbered value
+        */
+       public function hexval ($num, $assertMismatch = false) {
+               // Filter all numbers out
+               $ret = preg_replace('/[^0123456789abcdefABCDEF]/', '', $num);
+
+               // Assert only if requested
+               if ($assertMismatch === true) {
+                       // Has the whole value changed?
+                       assert(('' . $ret . '' != '' . $num . '') && (!is_null($num)));
+               } // END - if
+
+               // Return result
+               return $ret;
+       }
 }
 
 // [EOF]