sql_logger = new DebugStack(); $doctrine_configuration->setSQLLogger($this->sql_logger); } function getTab() { $queries = $this->sql_logger->queries; $count = count($queries); $count_suffix = $count === 1 ? 'query' : 'queries'; $time = $this->formatTime(array_sum(array_column($queries, 'executionMS'))); $img = ''; return $img . '' . "$count $count_suffix / $time ms" . ''; } function getPanel() { ob_start(); require __DIR__ . '/doctrine-panel.phtml'; return ob_get_clean(); } static function init(EntityManagerInterface $entity_manager) { Debugger::getBar()->addPanel(new DoctrinePanel($entity_manager->getConnection()->getConfiguration())); } protected function formatSql($sql) { // format SELECT queries a bit (wrap long select clauses, wrap lines on some keywords) preg_match('/^(SELECT\s+)(.*?)(\s+FROM\s+)(.*?)$/iu', trim($sql), $matches); if (count($matches) >= 5) { // if SELECT clause over 50 chars, make it wrappable $select_html = mb_strlen($matches[2]) > 50 ? ($matches[1] . ' ...
' . $matches[2] . '
') : ($matches[1] . $matches[2]); $from_keyword = $matches[3]; $rest = $matches[4]; // try to match & indent WHERE clause $where_html = ''; preg_match('/^(.*)(\s+WHERE\s+)(.*?)$/iu', $rest, $matches); if (count($matches) >= 4) { $where_html = $matches[1] . '
' . $matches[2]; $rest = $matches[3]; } // try to match & indent ORDER BY/GROUP BY/LIMIT/OFFSET $end_html = ''; preg_match('/^(.*?)(\s+(?:ORDER\s+BY|GROUP\s+BY|LIMIT|OFFSET)\s+)(.*)$/iu', $rest, $matches); if (count($matches) >= 4) { $end_html = $matches[1] . '
' . $matches[2]; $rest = $matches[3]; } $sql = $select_html . '
' . $from_keyword . $where_html . $end_html . $rest; } // highlight keywords $keywords = new MySQLKeywords(); $tokens = preg_split('/(\s+)/', $sql, -1, PREG_SPLIT_DELIM_CAPTURE); $output = ''; foreach ($tokens as $token) { $output .= $keywords->isKeyword($token) ? ('' . $token . '') : $token; } return $output; } protected function formatArrayData($data) { return preg_replace( '#^\s{4}#m', '', // remove 1rst "tab" of the JSON result substr( json_encode($data, JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK), 2, // remove "[\n" -2 // remove "\n]" ) ); } protected function transformNumericType($data) { $search = [ '#\b101\b#', // array of int '#\b102\b#', // array of string ]; $replace = [ 'integer[]', // array of int 'string[]', // array of string ]; return preg_replace($search, $replace, $data); } protected function formatTime($doctrine_time) { return number_format($doctrine_time * 1000, 1, '.', ' '); } }