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 static($entity_manager->getConnection()->getConfiguration()));
}
protected function formatSql($sql) {
$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, '.', ' ');
}
}