From 0d1c0a7ef45e7911255e0ad6c0fa7aec0bf3d134 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Apr 2012 16:59:54 +0300 Subject: Clean up the Profiler library --- system/libraries/Profiler.php | 196 ++++++++++++++++++++++-------------------- 1 file changed, 101 insertions(+), 95 deletions(-) (limited to 'system/libraries/Profiler.php') diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index d84e5d3fc..6320ab50d 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Profiler Class * @@ -45,24 +43,22 @@ class CI_Profiler { protected $_available_sections = array( - 'benchmarks', - 'get', - 'memory_usage', - 'post', - 'uri_string', - 'controller_info', - 'queries', - 'http_headers', - 'session_data', - 'config' - ); + 'benchmarks', + 'get', + 'memory_usage', + 'post', + 'uri_string', + 'controller_info', + 'queries', + 'http_headers', + 'session_data', + 'config' + ); protected $_query_toggle_count = 25; protected $CI; - // -------------------------------------------------------------------- - public function __construct($config = array()) { $this->CI =& get_instance(); @@ -102,7 +98,7 @@ class CI_Profiler { { if (in_array($method, $this->_available_sections)) { - $this->_compile_{$method} = ($enable !== FALSE) ? TRUE : FALSE; + $this->_compile_{$method} = ($enable !== FALSE); } } } @@ -127,7 +123,7 @@ class CI_Profiler { // We match the "end" marker so that the list ends // up in the order that it was defined if (preg_match('/(.+?)_end/i', $key, $match) - AND isset($this->CI->benchmark->marker[$match[1].'_end'], $this->CI->benchmark->marker[$match[1].'_start'])) + && isset($this->CI->benchmark->marker[$match[1].'_end'], $this->CI->benchmark->marker[$match[1].'_start'])) { $profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key); } @@ -135,18 +131,20 @@ class CI_Profiler { // Build a table containing the profile data. // Note: At some point we should turn this into a template that can - // be modified. We also might want to make this data available to be logged + // be modified. We also might want to make this data available to be logged $output = "\n\n" - . '
' - . "\n" - . '  '.$this->CI->lang->line('profiler_benchmarks').'  ' - . "\n\n\n\n"; + .'
' + ."\n" + .'  '.$this->CI->lang->line('profiler_benchmarks')."  " + ."\n\n\n
\n"; foreach ($profile as $key => $val) { $key = ucwords(str_replace(array('_', '-'), ' ', $key)); - $output .= "\n"; + $output .= '\n"; } return $output."
".$key."  ".$val."
' + .$key.'  ' + .$val."
\n
"; @@ -166,7 +164,7 @@ class CI_Profiler { // Let's determine which databases are currently connected to foreach (get_object_vars($this->CI) as $CI_object) { - if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') ) + if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB')) { $dbs[] = $CI_object; } @@ -175,13 +173,13 @@ class CI_Profiler { if (count($dbs) === 0) { return "\n\n" - . '
' - . "\n" - . '  '.$this->CI->lang->line('profiler_queries').'  ' - . "\n\n\n\n" - . '\n
' - . $this->CI->lang->line('profiler_no_db') - . "
\n
"; + .'
' + ."\n" + .'  '.$this->CI->lang->line('profiler_queries').'  ' + ."\n\n\n\n" + .'\n
' + .$this->CI->lang->line('profiler_no_db') + ."
\n
"; } // Load the text helper so we can highlight the SQL @@ -191,7 +189,6 @@ class CI_Profiler { $highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'GROUP BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR ', 'HAVING', 'OFFSET', 'NOT IN', 'IN', 'LIKE', 'NOT LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')'); $output = "\n\n"; - $count = 0; foreach ($dbs as $db) @@ -205,21 +202,23 @@ class CI_Profiler { $show_hide_js = '('.$this->CI->lang->line('profiler_section_show').')'; } - $output .= '
' - . "\n" - . '  '.$this->CI->lang->line('profiler_database').':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries').': '.count($db->queries).'  '.$show_hide_js.'' - . "\n\n\n\n"; + $output .= '
' + ."\n" + .'  '.$this->CI->lang->line('profiler_database') + .':  '.$db->database.'   '.$this->CI->lang->line('profiler_queries') + .': '.count($db->queries).'  '.$show_hide_js."\n\n\n" + .'
\n"; if (count($db->queries) === 0) { - $output .= "\n"; + $output .= '\n"; } else { foreach ($db->queries as $key => $val) { $time = number_format($db->query_times[$key], 4); - $val = highlight_code($val, ENT_QUOTES); foreach ($highlight as $bold) @@ -227,18 +226,18 @@ class CI_Profiler { $val = str_replace($bold, ''.$bold.'', $val); } - $output .= "\n"; + $output .= '\n"; } } $output .= "
".$this->CI->lang->line('profiler_no_queries')."
' + .$this->CI->lang->line('profiler_no_queries')."
".$time."  ".$val."
' + .$time.'  ' + .$val."
\n
"; - } return $output; } - // -------------------------------------------------------------------- /** @@ -248,19 +247,18 @@ class CI_Profiler { */ protected function _compile_get() { - $output = "\n\n" - . '
' - . "\n" - . '  '.$this->CI->lang->line('profiler_get_data').'  ' - . "\n"; + $output = "\n\n" + .'
' + ."\n" + .'  '.$this->CI->lang->line('profiler_get_data')."  \n"; if (count($_GET) === 0) { - $output .= "
".$this->CI->lang->line('profiler_no_get')."
"; + $output .= '
'.$this->CI->lang->line('profiler_no_get').'
'; } else { - $output .= "\n\n\n"; + $output .= "\n\n
\n"; foreach ($_GET as $key => $val) { @@ -269,9 +267,10 @@ class CI_Profiler { $key = "'".$key."'"; } - $output .= "\n"; + $output .= '\n"; } $output .= "
$_GET[".$key."]   " - . ((is_array($val) OR is_object($val)) ? "
" . htmlspecialchars(stripslashes(print_r($val, true))) . "
" : htmlspecialchars(stripslashes($val))) - . "
$_GET[' + .$key.']   ' + .((is_array($val) OR is_object($val)) ? '
'.htmlspecialchars(stripslashes(print_r($val, TRUE))).'
' : htmlspecialchars(stripslashes($val))) + ."
\n"; @@ -290,18 +289,17 @@ class CI_Profiler { protected function _compile_post() { $output = "\n\n" - . '
' - . "\n" - . '  '.$this->CI->lang->line('profiler_post_data').'  ' - . "\n"; + .'
' + ."\n" + .'  '.$this->CI->lang->line('profiler_post_data')."  \n"; if (count($_POST) == 0) { - $output .= "
".$this->CI->lang->line('profiler_no_post')."
"; + $output .= '
'.$this->CI->lang->line('profiler_no_post').'
'; } else { - $output .= "\n\n\n"; + $output .= "\n\n
\n"; foreach ($_POST as $key => $val) { @@ -310,15 +308,18 @@ class CI_Profiler { $key = "'".$key."'"; } - $output .= "\n"; } @@ -338,12 +339,12 @@ class CI_Profiler { protected function _compile_uri_string() { return "\n\n" - . '
' - . "\n" - . '  '.$this->CI->lang->line('profiler_uri_string').'  ' - . "\n
" - . ($this->CI->uri->uri_string == '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string) - . '
'; + .'
' + ."\n" + .'  '.$this->CI->lang->line('profiler_uri_string')."  \n" + .'
' + .($this->CI->uri->uri_string == '' ? $this->CI->lang->line('profiler_no_uri') : $this->CI->uri->uri_string) + .'
'; } // -------------------------------------------------------------------- @@ -356,11 +357,11 @@ class CI_Profiler { protected function _compile_controller_info() { return "\n\n" - . '
' - . "\n" - . '  '.$this->CI->lang->line('profiler_controller_info').'  ' - . "\n
".$this->CI->router->fetch_class().'/'.$this->CI->router->fetch_method() - . '
'; + .'
' + ."\n" + .'  '.$this->CI->lang->line('profiler_controller_info')."  \n" + .'
'.$this->CI->router->fetch_class().'/'.$this->CI->router->fetch_method() + .'
'; } // -------------------------------------------------------------------- @@ -375,12 +376,12 @@ class CI_Profiler { protected function _compile_memory_usage() { return "\n\n" - . '
' - . "\n" - . '  '.$this->CI->lang->line('profiler_memory_usage').'  ' - . "\n
" - . ((function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory')) - . '
'; + .'
' + ."\n" + .'  '.$this->CI->lang->line('profiler_memory_usage')."  \n" + .'
' + .((function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '') ? number_format($usage).' bytes' : $this->CI->lang->line('profiler_no_memory')) + .'
'; } // -------------------------------------------------------------------- @@ -395,15 +396,17 @@ class CI_Profiler { protected function _compile_http_headers() { $output = "\n\n" - . '
' - . "\n" - . '  '.$this->CI->lang->line('profiler_headers').'  ('.$this->CI->lang->line('profiler_section_show').')' - . "\n\n\n
$_POST[".$key."]   "; + $output .= '
$_POST[' + .$key.']   '; + if (is_array($val) OR is_object($val)) { - $output .= "
" . htmlspecialchars(stripslashes(print_r($val, TRUE))) . "
"; + $output .= '
'.htmlspecialchars(stripslashes(print_r($val, TRUE))).'
'; } else { $output .= htmlspecialchars(stripslashes($val)); } + $output .= "
\n"; + .'
' + ."\n" + .'  '.$this->CI->lang->line('profiler_headers') + .'  ('.$this->CI->lang->line('profiler_section_show').")\n\n\n" + .'
'."\n"; foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header) { - $val = (isset($_SERVER[$header])) ? $_SERVER[$header] : ''; - $output .= "\n"; + $val = isset($_SERVER[$header]) ? $_SERVER[$header] : ''; + $output .= '\n"; } return $output."\n
"; @@ -421,10 +424,10 @@ class CI_Profiler { protected function _compile_config() { $output = "\n\n" - . '
' - . "\n" - . '  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').')' - . "\n\n\n\n"; + .'
' + ."\n" + .'  '.$this->CI->lang->line('profiler_config').'  ('.$this->CI->lang->line('profiler_section_show').")\n\n\n" + .'
'."\n"; foreach ($this->CI->config->config as $config => $val) { @@ -433,7 +436,8 @@ class CI_Profiler { $val = print_r($val, TRUE); } - $output .= "\n"; + $output .= '\n"; } return $output."\n
"; @@ -453,9 +457,9 @@ class CI_Profiler { return; } - $output = '
' - . '  '.$this->CI->lang->line('profiler_session_data').'  ('.$this->CI->lang->line('profiler_section_show').')' - . ""; + $output = '
' + .'  '.$this->CI->lang->line('profiler_session_data').'  ('.$this->CI->lang->line('profiler_section_show').')' + .'
'; foreach ($this->CI->session->all_userdata() as $key => $val) { @@ -464,7 +468,8 @@ class CI_Profiler { $val = print_r($val, TRUE); } - $output .= "\n"; + $output .= '\n"; } return $output."\n
"; @@ -479,14 +484,14 @@ class CI_Profiler { */ public function run() { - $output = "
"; + $output = '
'; $fields_displayed = 0; foreach ($this->_available_sections as $section) { if ($this->_compile_{$section} !== FALSE) { - $func = "_compile_{$section}"; + $func = '_compile_'.$section; $output .= $this->{$func}(); $fields_displayed++; } @@ -494,7 +499,8 @@ class CI_Profiler { if ($fields_displayed === 0) { - $output .= '

'.$this->CI->lang->line('profiler_no_profiles').'

'; + $output .= '

' + .$this->CI->lang->line('profiler_no_profiles').'

'; } return $output.'
'; @@ -502,4 +508,4 @@ class CI_Profiler { } /* End of file Profiler.php */ -/* Location: ./system/libraries/Profiler.php */ +/* Location: ./system/libraries/Profiler.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b