X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fclass_BaseFrameworkSystem.php;h=77390bc205f7851427ec7c2c3ff049f5c30ffbb9;hb=178bf871182d5e4b5f02378674a0f9504db555c8;hp=370e2ff0f4baa6de2ebb75aa63686c53bf449234;hpb=8e5bb526ab03b1de868e80e9bf0ef662ba2421a3;p=core.git diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 370e2ff0..77390bc2 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -5,7 +5,7 @@ * * @author Roland Haeder * @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 * @@ -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; } @@ -1346,14 +1348,14 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } // END - if // Construct the full message - $stubMessage = sprintf("[%s:] Partial stub!", + $stubMessage = sprintf('[%s:] Partial stub!', $methodName ); // Is the extra message given? if (!empty($message)) { // Then add it as well - $stubMessage .= sprintf(' Message: %s', $message); + $stubMessage .= ' Message: ' . $message; } // END - if // Debug instance is there? @@ -1362,7 +1364,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { $this->debugOutput($stubMessage); } else { // Trigger an error - trigger_error($stubMessage . '
' . chr(10)); + trigger_error($stubMessage); } } @@ -1377,7 +1379,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { // Sorry, there is no other way getting this nice backtrace if (!empty($message)) { // Output message - printf("Message: %s
" . chr(10), $message); + printf('Message: %s
' . chr(10), $message); } // END - if print('
');
@@ -1391,38 +1393,49 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
 	}
 
 	/**
-	 * Outputs a debug message whether to debug instance (should be set!) or dies with or pints the message
+	 * Outputs a debug message whether to debug instance (should be set!) or
+	 * dies with or ptints the message. Do NEVER EVER rewrite the die() call to
+	 * ApplicationEntryPoint::app_die(), this would cause an endless loop.
 	 *
 	 * @param	$message	Message we shall send out...
-	 * @param	$doPrint	Whether we shall print or die here which first is the default
+	 * @param	$doPrint	Whether print or die here (default: print)
+	 * @paran	$stripTags	Whether to strip tags (default: false)
 	 * @return	void
 	 */
-	public function debugOutput ($message, $doPrint = true) {
-		// Get debug instance
-		$debugInstance = $this->getDebugInstance();
+	public function debugOutput ($message, $doPrint = true, $stripTags = false) {
+		// 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)) {
 			// Use debug output handler
-			$debugInstance->output($message);
+			$debugInstance->output($message, $stripTags);
 
 			if ($doPrint === false) {
 				// Die here if not printed
 				die();
 			} // END - if
 		} else {
+			// Are debug times enabled?
+			if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
+				// Prepent it
+				$message = $this->getPrintableExecutionTime() . $message;
+			} // END - if
+
 			// Put directly out
 			if ($doPrint === true) {
-				// Are debug times enabled?
-				if ($this->getConfigInstance()->getConfigEntry('debug_output_timings') == 'Y') {
-					// Output it first
-					print($this->getPrintableExecutionTime());
-				} // END - if
-
 				// Print message
 				print($message . chr(10));
 			} else {
-				// DO NOT REWRITE THIS TO app_die() !!!
+				// Die here
 				die($message);
 			}
 		}
@@ -1625,11 +1638,17 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
 		$fieldArray = $resultInstance->current();
 		//* DEBUG: */ $this->debugOutput($fieldName.':
'.print_r($fieldArray, true).'
'); + // 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; @@ -2025,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]