noalyss Version-9
dbg.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief This class contains utility for developpers
24 */
25/*!
26 *
27 * \class Dbg
28 * \brief utilities for showing debug message
29 */
30namespace Noalyss;
31require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
32/**
33 *
34 */
35class Dbg
36{
37 /**
38 * @brief Display the value of a var if DEBUGNOALYSS is greater than $n_level, the debugging info has a certain
39 * formatting
40 * @param $n_level integer if greater than DEBUGNOALYSS, the variable will be displaid
41 * @param $msg value to display : could be an object array, ..
42 * @param $print if true display , otherwise returns a string
43 * @return string|void
44 */
45 public static function echo_var($n_level, $msg,$print=true)
46 {
47 if (DEBUGNOALYSS > $n_level) {
48 $r= '<span style="font-size:12px;color:orangered;background-color:lightyellow;margin:1rem;border:1px black dashed">';
49 $type = gettype($msg);
50 if (in_array($type, ["string", "integer", "double"])) {
51 $r.= $msg;
52 } else {
53
54 $r.= "<pre>DBG";
55 $r.=print_r($msg,true);
56 $r.='</pre>';
57 }
58 $r.='</span>';
59 if ($print) { echo $r;}
60 return $r;
61 }
62 }
63
64 /**
65 * @brief returns a string , for the function with a specific style
66 * @param $msg function name __FUNCTION__ or __CLASS__
67 * @param $print if true display , otherwise returns a string
68 * @return string|void
69 */
70 public static function echo_function($msg,$print=true)
71 {
72 if (DEBUGNOALYSS > 1) {
73 $r = '<span style="font-size:12px;color:brown;background-color:bisque;">';
74 $r.="[FUNC: $msg]";
75
76 $r.= '</span>';
77 if ($print) { echo $r;}
78 return $r;
79 }
80 }
81
82 /**
83 * @brief display the file
84 * @param $msg name of file , usually always __FILE__
85 * @param $print if true display , otherwise returns a string
86 * @return string|void
87 */
88 public static function echo_file($msg,$print=true)
89 {
90 if (DEBUGNOALYSS > 1) {
91 $r = '<span style="font-size:12px;color:brown;background-color:lightyellow;display:table-row">';
92 $r.="[FILE: $msg]";
93
94 $r.= '</span>';
95 if ($print) { echo $r;}
96 return $r;
97 }
98 }
99
100 /**
101 * @brief display a bar depending of the size of the screen , it helps for CSS to see the media-size
102 * @return void
103 */
104 static function display_size()
105 {
106 echo <<<EOF
107<div class="d-block d-sm-none " style="background-color:lightblue">Xtra Small</div>
108<div class="d-none d-sm-block d-md-none d-lg-none d-xl-none " style="background-color:red">Small</div>
109<div class="d-none d-md-block d-lg-none " style="background-color:orangered">Medium</div>
110<div class="d-none d-lg-block d-xl-none " style="background-color:orange">Large</div>
111<div class="d-none d-xl-block " style="background-color:wheat">X Large</div>
112EOF;
113 }
114
115 /**
116 * @brief for development , show request (POST, GET)
117 * @return void
118 */
119 static function display_request()
120 {
121 $id = uniqid("debug");
122 $title = \HtmlInput::title_box(_("REQUEST"), $id, "hide");
123 ?>
124 <div class=" col-10 inner_box" style="display:none" id="<?= $id ?>">
125 <?= $title ?>
126
127 <h2 style="margin-top:100px"> Memory Usage
128 <?php echo round(memory_get_usage() / 1024.0, 2) . " kb \n"; ?>
129 </h2>
130 $_POST
131 <pre><?php echo print_r($_POST) ?></pre>
132 $_GET
133 <pre><?= print_r($_GET) ?></pre>
135 <pre><?= print_r($_REQUEST) ?></pre>
136 $_FILES
137 <pre><?= print_r($_FILES) ?></pre>
139 </div>
140 <input type="button" onclick="document.getElementById('<?= $id ?>').show();" value="Show request">
141 <?php
142 }
143
144 /**
145 * @brief for development , show GLOBAL and SESSION
146 * @return void
147 */
148 static function display_global()
149 {
150 $id = uniqid("debug");
151 $title = \HtmlInput::title_box(_("GLOBALS"), $id, "hide");
152 ?>
153 <div class=" col-10 inner_box" style="display:none" id="<?= $id ?>">
154 <?= $title ?>
155 $GLOBALS
156 <pre><?= print_r($GLOBALS) ?></pre>
157
159 </div>
160 <input type="button" onclick="document.getElementById('<?= $id ?>').show();" value="Show session">
161 <?php
162 }
163
164 /**
165 * @brief Show a icon to display large information on demand, when you click it , the content will be showned
166 * @param string $p_title title of the dialog box
167 * @param mixed $msg var_export of the msg
168 * @return string HTML to display
169 */
170 public static function hidden_info($p_title,$msg)
171 {
172 $id=uniqid("debug");
173 $title=\HtmlInput::title_box($p_title,"$id"."_infodiv","hide");
174 $content=var_export($msg,true);
175
176 $button_close=\HtmlInput::button_hide("$id"."_infodiv");
177 $r=<<<EOF
178<div id="{$id}_infodiv" style="display: none;background:rgba(234, 221, 114, 0.66);color:black;font-size:80%;width:auto;">
179{$title}
180<div>
181<pre>
182 {$content}
183
184</pre>
185</div>
186{$button_close}
187</div>
188<a href="javascript:void(0)" onclick="$('{$id}_infodiv').show()">&#128374;</a>
189
190EOF;
191 return $r;
192 }
193
194 /**
195 * @brief start a timer
196 * @return void
197 */
198 public static function timer_start()
199 {
200 global $timer;
201 $timer=hrtime(true);
202 }
203
204 /**
205 * @brief stop the timer and show the elapsed time, it is used for optimising the code
206 * @return void
207 */
208 public static function timer_show()
209 {
210 global $timer;
211 // $delta=$timer-microtime(true) ;
212 echo '<span style="font-size:80%;color:navy;background:lightgreen">';
213 echo _("Temps écoulé : ");
214 echo (hrtime(true)-$timer)/1e+6;
215 echo '</span>';
216 }
217}
218?>
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$opd_description style
$_REQUEST['ac']
$input_from type
Definition: balance.inc.php:65
$_GET['qcode']
static button_hide($div_name)
Hide the HTML popup.
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n')
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
static timer_start()
start a timer
Definition: dbg.php:198
static echo_var($n_level, $msg, $print=true)
Display the value of a var if DEBUGNOALYSS is greater than $n_level, the debugging info has a certain...
Definition: dbg.php:45
static echo_file($msg, $print=true)
display the file
Definition: dbg.php:88
static display_global()
for development , show GLOBAL and SESSION
Definition: dbg.php:148
static display_request()
for development , show request (POST, GET)
Definition: dbg.php:119
static hidden_info($p_title, $msg)
Show a icon to display large information on demand, when you click it , the content will be showned.
Definition: dbg.php:170
static echo_function($msg, $print=true)
returns a string , for the function with a specific style
Definition: dbg.php:70
static timer_show()
stop the timer and show the elapsed time, it is used for optimising the code
Definition: dbg.php:208
static display_size()
display a bar depending of the size of the screen , it helps for CSS to see the media-size
Definition: dbg.php:104
$_POST['ac']
Definition: do.php:310
$content
Definition: xml.php:17