diff --git a/config/profiler.php b/config/profiler.php index faf01ac..be410ae 100644 --- a/config/profiler.php +++ b/config/profiler.php @@ -17,4 +17,4 @@ $config['eloquent'] = FALSE; $config['uri_string'] = TRUE; $config['view_data'] = TRUE; -$config['query_toggle_count'] = 50; \ No newline at end of file +$config['query_toggle_count'] = 50; diff --git a/libraries/Profiler.php b/libraries/Profiler.php index 1f498f6..5b45059 100644 --- a/libraries/Profiler.php +++ b/libraries/Profiler.php @@ -253,7 +253,7 @@ protected function _compile_eloquent() $time = number_format($q['time']/1000, 4); $total += $q['time']/1000; - $query = interpolateQuery($q['query'], $q['bindings']); + $query = $this->interpolateQuery($q['query'], $q['bindings']); foreach ($highlight as $bold) $query = str_ireplace($bold, ''.$bold.'', $query); @@ -274,6 +274,33 @@ protected function _compile_eloquent() return $output; } + public function interpolateQuery($query, array $params) { + $keys = array(); + $values = $params; + + //build a regular expression for each parameter + foreach ($params as $key => $value) { + if (is_string($key)) { + $keys[] = "/:" . $key . "/"; + } else { + $keys[] = '/[?]/'; + } + + if (is_string($value)) + $values[$key] = "'" . $value . "'"; + + if (is_array($value)) + $values[$key] = implode(',', $value); + + if (is_null($value)) + $values[$key] = 'NULL'; + } + + $query = preg_replace($keys, $values, $query, 1, $count); + + return $query; + } + // --------------------------------------------------------------------