Added hexval() which really stupid regex
authorRoland Häder <roland@mxchange.org>
Sat, 19 May 2012 15:30:33 +0000 (15:30 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 19 May 2012 15:30:33 +0000 (15:30 +0000)
inc/classes/main/class_BaseFrameworkSystem.php

index b3ad65ff8cc163cea7d0c01f00b6e36a4d1ec059..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;
        }
 
@@ -2042,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]