Bicycle/Services/DataBase/Classes/ProfilerPDO.php
Egor Isaev 9d4edf147a dev
2026-08-07 11:40:03 +03:00

35 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @package Bicycle
* @author Egor Isaev
* @description ProfilerPDO.php
* @copyright (c) 07/08/2026
*/
namespace Services\DataBase\Classes;
/**
* Адаптер Profiler под PdoDriver::query() — замеряет время выполнения $execute
* и логирует запись в Profiler.
*/
class ProfilerPDO
{
/**
* Выполняет $execute с замером времени, логирует в Profiler и возвращает результат.
*
* @param string $sql SQL-запрос (для записи в профилировщик)
* @param array $params Параметры запроса (для записи в профилировщик)
* @param callable $execute Колбэк, выполняющий сам запрос
* @return mixed Результат $execute
*/
public static function wrap(string $sql, array $params, callable $execute): mixed
{
$start = microtime(true);
$result = $execute();
Profiler::log($sql, $params, (microtime(true) - $start) * 1000);
return $result;
}
}