Quellcode durchsuchen

DBG update from biall

Piotr Labudda vor 10 Jahren
Ursprung
Commit
6565f2fab9
1 geänderte Dateien mit 98 neuen und 3 gelöschten Zeilen
  1. 98 3
      SE/se-lib/DBG.php

+ 98 - 3
SE/se-lib/DBG.php

@@ -3,11 +3,63 @@
 class DBG {
 class DBG {
 
 
 	/**
 	/**
+	 * @param $reqKqy - key in $_REQUEST array (if true then always show)
+	 * @param $reqValueExpr - expression to compare req value
+	 *   true - always visible - only for fast DBG without $reqKey in REQUEST
+	 *   '>*', '>=*', '<*', '<=*' - compare $reqValue
 	 * examples:
 	 * examples:
-	 *   DBG::_('DBG_SCH', '1', "fieldsConfig({$idTable})", $fieldsConfig, __CLASS__, __FUNCTION__, __LINE__ );
+	 *   - show when $_REQUEST['DBG_SCH'] == '1'
+	 *     DBG::_('DBG_SCH', '1', "fieldsConfig({$idTable})", $fieldsConfig, __CLASS__, __FUNCTION__, __LINE__);
+	 *   - show when $_REQUEST['DBG_SCH'] > '1'
+	 *     DBG::_('DBG_SCH', '>1', "fieldsConfig({$idTable})", $fieldsConfig, __CLASS__, __FUNCTION__, __LINE__);
+	 *   - show when any value: strlen($_REQUEST['DBG_SCH']) > 0
+	 *     DBG::_('DBG_SCH', true, "fieldsConfig({$idTable})", $fieldsConfig, __CLASS__, __FUNCTION__, __LINE__);
+	 *   - always show
+	 *     DBG::_(true, true, "fieldsConfig({$idTable})", $fieldsConfig, __CLASS__, __FUNCTION__, __LINE__);
 	 */
 	 */
-	public static function _($reqKey, $reqValue, $label, $variable, $className, $functionName, $lineNumber, $borderColor = 'red') {
-		if ($reqValue == V::get($reqKey, '', $_GET)) {
+	public static function _($reqKey, $reqValueExpr, $label, $variable, $className, $functionName, $lineNumber, $borderColor = 'red') {
+		$showDBG = false;
+		$reqValue = V::get($reqKey, '', $_GET);
+		if (true === $reqKey) {
+			$showDBG = true;
+		}
+		else if (strlen($reqValue) == 0) {
+			return;
+		}
+		else if ($reqValue == $reqValueExpr) {
+			$showDBG = true;
+		}
+		else if (true === $reqValueExpr) {
+			$showDBG = true;
+		}
+		else {
+			if ('>=' == substr($reqValueExpr, 0, 2)) {
+				if ($reqValue >= substr($reqValueExpr, 2)) {
+					$showDBG = true;
+				}
+			}
+			else if ('>' == substr($reqValueExpr, 0, 1)) {
+				if ($reqValue > substr($reqValueExpr, 1)) {
+					$showDBG = true;
+				}
+			}
+			else if ('<=' == substr($reqValueExpr, 0, 2)) {
+				if ($reqValue <= substr($reqValueExpr, 2)) {
+					$showDBG = true;
+				}
+			}
+			else if ('<' == substr($reqValueExpr, 0, 1)) {
+				if ($reqValue < substr($reqValueExpr, 1)) {
+					$showDBG = true;
+				}
+			}
+			else {
+				if ($reqValue = $reqValueExpr) {
+					$showDBG = true;
+				}
+			}
+		}
+		if ($showDBG) {
 			?>
 			?>
 <pre style="max-height:200px;max-width:800px;overflow:auto;border:1px solid <?php echo $borderColor; ?>;text-align:left;"
 <pre style="max-height:200px;max-width:800px;overflow:auto;border:1px solid <?php echo $borderColor; ?>;text-align:left;"
 		 ><?php echo "{$label} ({$className}::{$functionName}:{$lineNumber}):\n"; ?>
 		 ><?php echo "{$label} ({$className}::{$functionName}:{$lineNumber}):\n"; ?>
@@ -17,4 +69,47 @@ class DBG {
 		}
 		}
 	}
 	}
 
 
+	public static function table($label, $table, $className, $functionName, $lineNumber) {
+		$cols = array();
+		if (is_array($table) && !empty($table)) {
+			$firstRow = array();
+			foreach ($table as $row) {
+				$firstRow = $row;
+				break;
+			}
+			if (is_array($firstRow)) {
+				$cols = array_keys($firstRow);
+			}
+			else if (is_object($firstRow)) {
+				$cols = array_keys((array)$firstRow);
+			}
+			else {
+				return;// bad table item type
+			}
+		}
+		?>
+<table class="table table-bordered">
+	<caption><?php echo "{$label} ({$className}::{$functionName}:{$lineNumber}):"; ?></caption>
+	<thead>
+		<tr>
+			<th style="padding:2px;">Lp.</th>
+		<?php foreach ($cols as $colName) : ?>
+			<th style="padding:2px;"><?php echo $colName; ?></th>
+		<?php endforeach; ?>
+		</tr>
+	</thead>
+	<tbody>
+	<?php $i = 0; foreach ($table as $row) : $i++; ?>
+		<tr>
+			<td style="padding:2px;"><?php echo $i; ?></td>
+		<?php foreach ($cols as $colName) : ?>
+			<td style="padding:2px;"><?php echo V::get($colName, '', $row); ?></td>
+		<?php endforeach; ?>
+		</tr>
+	<?php endforeach; ?>
+	</tbody>
+</table>
+<?php
+	}
+
 }
 }