3 * SPDX-License-Identifier: GPL-2.0-only
5 * This file is part of Nominatim. (https://nominatim.org)
7 * Copyright (C) 2022 by the Nominatim developer community.
8 * For a full list of authors see the git log.
15 public static function newFunction($sHeading)
17 echo "<pre><h2>Debug output for $sHeading</h2></pre>\n";
20 public static function newSection($sHeading)
22 echo "<hr><pre><h3>$sHeading</h3></pre>\n";
25 public static function printVar($sHeading, $mVar)
27 echo '<pre><b>'.$sHeading. ':</b> ';
28 Debug::outputVar($mVar, str_repeat(' ', strlen($sHeading) + 3));
32 public static function fmtArrayVals($aArr)
34 return array('__debug_format' => 'array_vals', 'data' => $aArr);
37 public static function printDebugArray($sHeading, $oVar)
41 Debug::printVar($sHeading, 'null');
43 Debug::printVar($sHeading, $oVar->debugInfo());
47 public static function printDebugTable($sHeading, $aVar)
49 echo '<b>'.$sHeading.":</b>\n";
50 echo "<table border='1'>\n";
54 $aInfo = reset($aVar);
55 if (!is_array($aInfo)) {
56 $aInfo = $aInfo->debugInfo();
58 foreach ($aInfo as $sKey => $mVal) {
59 echo ' <th><small>'.$sKey.'</small></th>'."\n";
63 foreach ($aVar as $oRow) {
65 if (!is_array($oRow)) {
66 $aInfo = $oRow->debugInfo();
69 foreach ($aKeys as $sKey) {
71 if (isset($aInfo[$sKey])) {
72 Debug::outputVar($aInfo[$sKey], '');
74 echo '</pre></td>'."\n";
82 public static function printGroupedSearch($aSearches, $aWordsIDs)
84 echo '<table border="1">';
85 echo '<tr><th>rank</th><th>Name Tokens</th><th>Name Not</th>';
86 echo '<th>Address Tokens</th><th>Address Not</th>';
87 echo '<th>country</th><th>operator</th>';
88 echo '<th>class</th><th>type</th><th>postcode</th><th>housenumber</th></tr>';
89 foreach ($aSearches as $aRankedSet) {
90 foreach ($aRankedSet as $aRow) {
91 $aRow->dumpAsHtmlTableRow($aWordsIDs);
97 public static function printGroupTable($sHeading, $aVar)
99 echo '<b>'.$sHeading.":</b>\n";
100 echo "<table border='1'>\n";
103 echo ' <th><small>Group</small></th>'."\n";
105 $aInfo = reset($aVar)[0];
106 if (!is_array($aInfo)) {
107 $aInfo = $aInfo->debugInfo();
109 foreach ($aInfo as $sKey => $mVal) {
110 echo ' <th><small>'.$sKey.'</small></th>'."\n";
114 foreach ($aVar as $sGrpKey => $aGroup) {
115 foreach ($aGroup as $oRow) {
117 if (!is_array($oRow)) {
118 $aInfo = $oRow->debugInfo();
121 echo ' <td><pre>'.$sGrpKey.'</pre></td>'."\n";
122 foreach ($aKeys as $sKey) {
124 if (!empty($aInfo[$sKey])) {
125 Debug::outputVar($aInfo[$sKey], '');
127 echo '</pre></td>'."\n";
136 public static function printSQL($sSQL)
138 echo '<p><tt><b>'.date('c').'</b> <font color="#aaa">'.htmlspecialchars($sSQL, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401).'</font></tt></p>'."\n";
141 private static function outputVar($mVar, $sPreNL)
143 if (is_array($mVar) && !isset($mVar['__debug_format'])) {
145 foreach ($mVar as $mKey => $aValue) {
147 $iKeyLen = Debug::outputSimpleVar($mKey);
151 $sPreNL.str_repeat(' ', $iKeyLen + 4)
153 $sPre = "\n".$sPreNL;
155 } elseif (is_array($mVar) && isset($mVar['__debug_format'])) {
156 if (!empty($mVar['data'])) {
158 foreach ($mVar['data'] as $mValue) {
160 Debug::outputSimpleVar($mValue);
164 } elseif (is_object($mVar) && method_exists($mVar, 'debugInfo')) {
165 Debug::outputVar($mVar->debugInfo(), $sPreNL);
166 } elseif (is_a($mVar, 'stdClass')) {
167 Debug::outputVar(json_decode(json_encode($mVar), true), $sPreNL);
169 Debug::outputSimpleVar($mVar);
173 private static function outputSimpleVar($mVar)
175 if (is_bool($mVar)) {
176 echo '<i>'.($mVar ? 'True' : 'False').'</i>';
177 return $mVar ? 4 : 5;
180 if (is_string($mVar)) {
183 $sOut = (string)$mVar;
186 echo htmlspecialchars($sOut, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401);
187 return strlen($sOut);