- microtime: documentation ( source)
- print_r: documentation ( source)
- addslashes: documentation ( source)
- array_shift: documentation ( source)
- implode: documentation ( source)
- sprintf: documentation ( source)
<?php
/**
* Debug Class
*/
namespace bobcad;
class debug {
public $runtime_checkpoints;
public function __construct() {
$this->runtime_checkpoint('Begin Theme Generation');
}
public function output() {
print_r($_SERVER);
}
public function runtime_checkpoint($name = '') {
$this->runtime_checkpoints[] = array(
'name' => (string) $name,
'time' => microtime(TRUE)
);
}
public function print_js($html_id) {
$checkpoints = $this->runtime_checkpoints;
$first = array_shift($checkpoints);
$debug_info_array = array($first['name'].': '.$first['time']);
$previous_time = $first['time'];
foreach ($checkpoints as $checkpoint) {
$debug_info_array[] = sprintf(
'%1$s: %2$s (+%3$s)',
$checkpoint['name'],
($first['time'] - $checkpoint['time']),
($previous_time - $checkpoint['time'])
);
$previous_time = $checkpoint['time'];
}
$debug_info = implode('; ', $debug_info_array);
?>
<script type="text/javascript">
document.getElementById("<?php echo $html_id; ?>").setAttribute("title", "<?php echo addslashes($debug_info); ?>");
</script>
<?php
}
public function _on_shutdown() {
$this->runtime_checkpoint('Begin Theme Generation');
$this->print_js('copyright');
}
}
$test = new \bobcad\debug;
$test->_on_shutdown();