XOOPS  2.6.0
Debug.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
12 namespace Xmf;
13 
27 class Debug
28 {
35  private static $times = array();
36 
44  private static $timerQueue = array();
45 
52  private static $timerLabels = array();
53 
54 
64  public static function dump($var, $inline = false)
65  {
66  $events = \Xoops::getInstance()->events();
67  $eventName = 'debug.log';
68  if (!$inline && $events->hasListeners($eventName)) {
69  $events->triggerEvent($eventName, $var);
70  //\Kint::dump(func_get_arg(0));
71  } else {
72  $config = array(
73  'skin' => array('selected' => 'modern'),
74  'css' => array('url' => \XoopsBaseConfig::get('url') . '/modules/xmf/css/krumo/'),
75  'display' => array(
76  'show_version' => false,
77  'show_call_info' => false,
78  'sort_arrays' => false,
79  ),
80  );
81  \krumo::setConfig($config);
82  $msg = \krumo::dump($var);
83  echo $msg;
84  }
85  }
86 
95  public static function backtrace($inline = false)
96  {
97  $events = \Xoops::getInstance()->events();
98  $eventName = 'debug.log';
99  if (!$inline && $events->hasListeners($eventName)) {
100  $events->triggerEvent($eventName, debug_backtrace());
101  } else {
102  return self::dump(debug_backtrace(), $inline);
103  }
104  }
105 
114  public static function startTimer($name, $label = null)
115  {
116  $events = \Xoops::getInstance()->events();
117  $var = array($name);
118  $var[] = empty($label) ? $name : $label;
119  $eventName = 'debug.timer.start';
120  if ($events->hasListeners($eventName)) {
121  $events->triggerEvent($eventName, $var);
122  } else {
123  self::$times[$name] = microtime(true);
124  }
125  }
126 
134  public static function stopTimer($name)
135  {
136  $events = \Xoops::getInstance()->events();
137  $eventName = 'debug.timer.stop';
138  if ($events->hasListeners($eventName)) {
139  $events->triggerEvent($eventName, $name);
140  } else {
141  echo $name . ' - ' . intval(microtime(true) - self::$times[$name]) . " \n";
142  }
143  }
144 
157  public static function startQueuedTimer($name, $label = null)
158  {
159  self::$times[$name] = microtime(true);
160  self::$timerLabels[$name] = empty($label) ? $name : $label;
161  }
162 
170  public static function stopQueuedTimer($name)
171  {
172  if (isset(self::$timerLabels[$name]) && isset(self::$times[$name])) {
173  $queueItem = array(
174  'label' => self::$timerLabels[$name],
175  'start' => self::$times[$name],
176  'elapsed' => microtime(true) - self::$times[$name],
177  );
178  self::$timerQueue[] = $queueItem;
179  }
180  }
181 
192  public static function dumpQueuedTimers($returnOnly = false)
193  {
194  $queue = self::$timerQueue;
195  self::$timerQueue = array();
196  if (!$returnOnly) {
197  self::dump($queue);
198  }
199 
200  return $queue;
201  }
202 
216  public static function startTrace($tracefile = '', $collect_params = '3', $collect_return = 'On')
217  {
218  if (function_exists('xdebug_start_trace')) {
219  ini_set('xdebug.collect_params', $collect_params);
220  ini_set('xdebug.collect_return', $collect_return);
221  if ($tracefile == '') {
222  $tracefile = \XoopsBaseConfig::get('var-path') . '/logs/php_trace';
223  }
224  xdebug_start_trace($tracefile);
225  }
226  }
227 
235  public static function stopTrace()
236  {
237  if (function_exists('xdebug_stop_trace')) {
238  xdebug_stop_trace();
239  }
240  }
241 }
static getInstance()
Definition: Xoops.php:160
static startQueuedTimer($name, $label=null)
Definition: Debug.php:157
static startTrace($tracefile= '', $collect_params= '3', $collect_return= 'On')
Definition: Debug.php:216
static startTimer($name, $label=null)
Definition: Debug.php:114
static backtrace($inline=false)
Definition: Debug.php:95
static dump($var, $inline=false)
Definition: Debug.php:64
static get($name)
return $config
if(!is_object($module)||!$module->getVar('isactive')) $msg
Definition: groupperm.php:38
$var
Definition: userinfo.php:125
static dumpQueuedTimers($returnOnly=false)
Definition: Debug.php:192
static stopTimer($name)
Definition: Debug.php:134
static stopQueuedTimer($name)
Definition: Debug.php:170
static stopTrace()
Definition: Debug.php:235