3 // Copyright (c) 2013 Blue Static
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
17 namespace hoplite
\base
;
20 A static class used to help profile Hoplite components.
24 /*! @var bool Enable profiling. */
25 static private $profiling_enabled = FALSE
;
27 /*! Enables profiling globally. */
28 static public function EnableProfiling()
30 self
::$profiling_enabled = TRUE
;
33 /*! Gets the current state for profiling. */
34 static public function IsProfilingEnabled()
36 return self
::$profiling_enabled;
40 Prepares a debug_backtrace() array for output to the browser by
41 compressing the array into visible text
43 @param array The return value from debug_backtrace().
45 @return array Array of strings that can be imploded() for display.
47 static public function FormatDebugBacktrace($backtrace)
50 foreach ($backtrace AS $i => $frame) {
52 $file = $frame['file'] . ':' . $frame['line'];
53 $file = str_replace($_SERVER['DOCUMENT_ROOT'], '', $file);
54 $funct = (isset($frame['class']) ?
$frame['class'] . '::' . $frame['function'] : $frame['function']);
56 if (isset($frame['args']) && is_array($frame['args'])) {
57 // Convert arrays and objects to strings.
58 foreach ($frame['args'] AS $id => $arg) {
60 $frame['args']["$id"] = 'Array';
61 else if (is_object($arg))
62 $frame['args']["$id"] = get_class($arg);
64 $args = implode(', ', $frame['args']);
67 $trace[] = "#$i $funct($args) called at [$file]";