public function _eventHandlerPeek($source, $data, $event)
{
if ($event === 'logger:log') {
if (count($this->_log) <= $this->_log_max) {
$format = '[%time%][%level%] %message%';
$micro_date = explode(' ', microtime());
$replaces = ['%time%' => date('H:i:s.', $micro_date[1]) . str_pad(ceil($micro_date[0] * 10000), '0', STR_PAD_LEFT), '%level%' => $data['context']['level'], '%message%' => $data['message']];
$this->_log[] = ['level' => $data['level'], 'message' => strtr($format, $replaces)];
}
} elseif ($event === 'db:beforeQuery') {
$this->_sql_beforeQueryTime = microtime(true);
/**
* @var \ManaPHP\DbInterface $source
*/
if (count($this->_sql_prepared) <= $this->_sql_prepared_max) {
$preparedSQL = $source->getSQL();
if (!isset($this->_sql_prepared[$preparedSQL])) {
$this->_sql_prepared[$preparedSQL] = 1;
} else {
$this->_sql_prepared[$preparedSQL]++;
}
}
$this->_sql_count++;
if (count($this->_sql_executed) <= $this->_sql_executed_max) {
$this->_sql_executed[] = ['prepared' => $source->getSQL(), 'bind' => $source->getBind(), 'emulated' => $source->getEmulatedSQL()];
}
} elseif ($event === 'db:afterQuery') {
/**
* @var \ManaPHP\DbInterface $source
*/
if (count($this->_sql_executed) <= $this->_sql_executed_max) {
$this->_sql_executed[$this->_sql_count - 1]['time'] = round(microtime(true) - $this->_sql_beforeQueryTime, 4);
$this->_sql_executed[$this->_sql_count - 1]['row_count'] = $source->affectedRows();
}
} elseif ($event === 'db:beginTransaction' || $event === 'db:rollbackTransaction' || $event === 'db:commitTransaction') {
$this->_sql_count++;
$parts = explode(':', $event);
$name = $parts[1];
if (count($this->_sql_executed) <= $this->_sql_executed_max) {
$this->_sql_executed[] = ['prepared' => $name, 'bind' => [], 'emulated' => $name, 'time' => 0, 'row_count' => 0];
}
if (count($this->_sql_prepared) <= $this->_sql_prepared_max) {
$preparedSQL = $name;
if (!isset($this->_sql_prepared[$preparedSQL])) {
$this->_sql_prepared[$preparedSQL] = 1;
} else {
$this->_sql_prepared[$preparedSQL]++;
}
}
} elseif ($event === 'renderer:beforeRender') {
$vars = $data['vars'];
unset($vars['view']);
$this->_view[] = ['file' => $data['file'], 'vars' => $vars, 'base_name' => basename(dirname($data['file'])) . '/' . basename($data['file'])];
} elseif ($event === 'component:setUndefinedProperty') {
$this->_warnings[] = 'Set to undefined property `' . $data['name'] . '` of `' . $data['class'] . '`';
}
}