LoggedStatementsTrait.php in Drupal 10
File
core/modules/system/tests/modules/database_statement_monitoring_test/src/LoggedStatementsTrait.php
View source
<?php
namespace Drupal\database_statement_monitoring_test;
trait LoggedStatementsTrait {
protected $loggedStatements;
public function query($query, array $args = [], $options = []) {
if (is_string($query)) {
$stringified_args = array_map(function ($v) {
return is_array($v) ? implode(',', $v) : $v;
}, $args);
$this->loggedStatements[] = str_replace(array_keys($stringified_args), array_values($stringified_args), $query);
}
return parent::query($query, $args, $options);
}
public function resetLoggedStatements() {
$this->loggedStatements = [];
return $this;
}
public function getDriverClass($class) {
static $fixed_namespace;
if (!$fixed_namespace) {
$this->connectionOptions['namespace'] = (new \ReflectionClass(get_parent_class($this)))
->getNamespaceName();
$fixed_namespace = TRUE;
}
return parent::getDriverClass($class);
}
public function getLoggedStatements() {
return $this->loggedStatements;
}
}