var SQ_DEBUG = true;'; } } } /** * Get the debug buffer * @param $buffer * @return mixed */ public function getBuffer($buffer) { if (SQ_Classes_Helpers_Tools::isAjax()) { return $buffer; } if (!$this->getIsset('sq_debug')) { return $buffer; } return false; } /** * Store the debug for a later view * * @return bool|void */ public static function dump() { if (SQ_DEBUG) { if (self::getValue('sq_debug') !== 'on') { return; } $output = ''; $callee = array('file' => '', 'line' => ''); if (function_exists('func_get_args')) { $arguments = func_get_args(); $total_arguments = count($arguments); } else $arguments = array(); $run_time = number_format(microtime(true) - SQ_REQUEST_TIME, 3); if (function_exists('debug_backtrace')) list($callee) = debug_backtrace(); $output .= '
'; $output .= '' . $callee['file'] . ' Time: ' . $run_time . ' @ line: ' . $callee['line'] . '
';

            $i = 0;
            foreach ($arguments as $argument) {
                if (count($arguments) > 1)
                    $output .= "\n" . '#' . (++$i) . ' of ' . $total_arguments . ': ';

                // if argument is boolean, false value does not display, so ...
                if (is_bool($argument))
                    $argument = ($argument) ? 'TRUE' : 'FALSE';
                else
                    if (is_object($argument) && function_exists('array_reverse') && function_exists('class_parents'))
                        $output .= implode("\n" . '|' . "\n", array_reverse(class_parents($argument))) . "\n" . '|' . "\n";

                $output .= htmlspecialchars(print_r($argument, TRUE))
                    . ((is_object($argument) && function_exists('spl_object_hash')) ? spl_object_hash($argument) : '');
            }
            $output .= "
"; $output .= "
"; self::$debug[] = $output; } } /** * Show the debug dump */ public static function showDebug() { SQ_Classes_Helpers_Tools::setHeader('html'); $errors = error_get_last(); echo "Debug result:
" . '
' . '
' . @implode('
', self::$debug) . '
'; $run_time = number_format(microtime(true) - SQ_REQUEST_TIME, 3); $pps = number_format(1 / $run_time, 0); $memory_avail = ini_get('memory_limit'); $memory_used = number_format(memory_get_usage(true) / (1024 * 1024), 2); $memory_peak = number_format(memory_get_peak_usage(true) / (1024 * 1024), 2); if (PHP_SAPI == 'cli') { // if run for command line, display some info $debug = PHP_EOL . "======================================================================================" . PHP_EOL . " Config: php " . phpversion() . " " . php_sapi_name() . PHP_EOL . " Load: {$memory_avail} (avail) / {$memory_used}M (used) / {$memory_peak}M (peak)" . " | Time: {$run_time}s | {$pps} req/sec" . PHP_EOL . " | Server Timezone: " . date_default_timezone_get() . " | Agent: CLI" . PHP_EOL . "======================================================================================" . PHP_EOL; } else { // if not run from command line, only display if debug is enabled $debug = "" //
" . "
" . "
" . " Config: " . "
" . "    | php " . phpversion() . " " . php_sapi_name() . "
" . "    | Server Timezone: " . date_default_timezone_get() . "
" . " Load: " . "
" . "    | Memory: {$memory_avail} (avail) / {$memory_used}M (used) / {$memory_peak}M (peak)" . "
" . "    | Time: {$run_time}s    | {$pps} req/sec" . "
" . "Url: " . "
" . "    |" . "
" . "    | Agent: " . (@$_SERVER["HTTP_USER_AGENT"]) . "
" . "Version Control: " . "
" . "
" . "
" . "
"; } echo '
' . $debug . '
'; } public static function showLoadingTime() { $run_time = number_format(microtime(true) - SQ_REQUEST_TIME, 3); $pps = number_format(1 / $run_time, 0); $memory_avail = ini_get('memory_limit'); $memory_used = number_format(memory_get_usage(true) / (1024 * 1024), 2); $memory_peak = number_format(memory_get_peak_usage(true) / (1024 * 1024), 2); $debug = PHP_EOL . "======================================================================================" . PHP_EOL . " Config: php " . phpversion() . " " . php_sapi_name() . " / zend engine " . zend_version() . PHP_EOL . " Load: {$memory_avail} (avail) / {$memory_used}M (used) / {$memory_peak}M (peak)" . " | Time: {$run_time}s | {$pps} req/sec" . PHP_EOL . " | Server Timezone: " . date_default_timezone_get() . " | Agent: CLI" . PHP_EOL . "======================================================================================" . PHP_EOL; echo '
' . $debug . '
'; } } defined('SQ_DEBUG') || define('SQ_DEBUG', false); SQ_Debug::checkDebug();