*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
* @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;
}
*
* @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;
}
* @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)) {
$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
$fieldValue = $fieldArray[$fieldName];
- } // END - if
+ } else {
+ // Missing field entry, may require debugging
+ $this->debugOutput($this->__toString() . ':fieldname=' . $fieldName . ' not found!');
+ }
// Return it
return $fieldValue;
// 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]