php - 如何在 Shopware 6 中转储 SQL 查询以用于调试存储库搜索?
问题描述
如何转储类似的 SQL 查询
$searchResult = $this->propertyGroupOptionRepository->search($criteria, $context);
我知道有一个调试栏,但这是在 PHPUnit 测试中,调试栏在那里不可用?
解决方案
更新 2:这也包含在FroshDevelopmentHelper中
在测试之前这样的事情基本上有效:
Kernel::getConnection()->getConfiguration()->setSQLLogger(new EchoSQLLogger());
这会将 SQL 查询打印到控制台。
缺点:
- 参数未内联到 SQL 查询中
- UUID 参数显示为二进制数据,因此很难复制和粘贴它们以调试查询
改进版 - 使用核心代码格式化查询:
class EchoRunableSQLLogger implements \Doctrine\DBAL\Logging\SQLLogger
{
public function startQuery($sql, ?array $params = null, ?array $types = null)
{
$doctrineExtension = new \Shopware\Core\Profiling\Twig\DoctrineExtension();
echo $doctrineExtension->replaceQueryParameters(
$sql,
array_merge($params ?? array(), $types ?? array())
) . ';' . PHP_EOL;
}
public function stopQuery()
{
}
}
\Shopware\Core\Kernel::getConnection()->getConfiguration()->setSQLLogger(new EchoRunableSQLLogger());
推荐阅读
- c++ - Stringstream 正在输出正确的数据,但没有提取正确的数据
- django - 使用 django newsletter 发送邮件
- java - 通过适配器传递 MainActivity 的数据
- c# - 正则表达式引号而不是引号前的特定单词
- reactjs - 如何在 React-Recompose 应用程序中将事件处理程序传递给 React-node
- qt - qt 在视图中永久显示委托
- html - SVG tspan 元素 + 字体家族风格?
- http - 使用 HTTP 获取 Squarespace Collection 项目
- github - Github 页面未发布
- embedded-jetty - Embedded Jetty 无法获取我的资源文件