phpexpertsinc / doctrine-detective
一个 Symfony2 Bundle,为 HTML 和 JSON 响应提供详细的 SQL 查询日志,包括 SQL 查询、其位置和持续时间,按 Controller -> Service -> Repository 组织。
v1.0.0
2015-02-01 13:38 UTC
Requires
- php: >=5.4
- doctrine/doctrine-bundle: *
- doctrine/orm: *
- symfony/dependency-injection: 2.*
- symfony/http-kernel: 2.*
This package is auto-updated.
Last update: 2024-09-13 10:37:00 UTC
README
Doctrine Detective 是一个 Symfony2 Bundle,为 HTML 和 JSON 响应提供详细的 SQL 查询日志,包括 SQL 查询、其位置和持续时间,按 Controller -> Service -> Repository 组织。
它主要用于调试、分析以及对 Doctrine ORM 查询进行重构,以使其成为更高效的 Doctrine DBAL 查询。
与其他 SQL 日志记录器不同,Doctrine Detective 具有以下功能
- 查询按类和方法分层组织。
- 预编译语句的参数已插值,因此您可以直接对数据库进行查询。
- 支持 RESTful API。
安装
- 将
"phpexpertsinc/doctrine-detective" : "1.*"
添加到您的 composer.json。 - 运行
$ composer update phpexpertsinc/doctrine-detective
。 - 编辑
app/appKernel.php
。 - 将
new PHPExperts\DoctrineDetectiveBundle\DoctrineDetectiveBundle(),
添加到AppKernel::registerBundles()
数组。 -or- (首选),仅将其添加到dev
和test
环境中
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new PHPExperts\DoctrineDetectiveBundle\DoctrineDetectiveBundle();
}
输出
HTML 响应
在每个 HTML 响应的末尾,您将找到以下内容
<div class="doctrineDetective-SQLLog">
<table>
<tr>
<td>TestController::getActiveUsersAction</td>
<td>3.886604999847429 ms</td>
<td>-</td>
</tr>
<tr>
<td>UserService</td>
<td>3.37965652160646 ms</td>
<td>-</td>
</tr>
<tr>
<td>UserService::getUsers(), Line 210</td>
<td>2.622127532959 ms</td>
<td>SELECT * FROM users WHERE ids IN (1, 2, 3, 4, 5)</td>
</tr>
<tr>
<td>UserRepository</td>
<td>0.75697898864746 ms</td>
<td>-</td>
</tr>
<tr>
<td>UserRepository::isActive(), Line 115</td>
<td>0.75697898864746</td>
<td>SELECT last_visit FROM login_log WHERE userId IN (1, 2, 3, 4, 5)</td>
</tr>
</table>
</div>
JSON 响应
在您的 JSON 响应的末尾,您将找到 sqlLog
数组
"sqlLog": {
"TestController::getActiveUsersAction": {
"time": 3.886604999847429,
"UserService": {
"time": 3.37965652160646,
"getUsers": {
"time": 2.622127532959,
"queries": [
{
"query": "SELECT * FROM users WHERE ids IN (1, 2, 3, 4, 5)",
"line": 210,
"time": 2.622127532959
}
]
},
},
"UserRepository": {
"isActive": {
"time": 0.75697898864746,
"queries": [
{
"query": "SELECT last_visit FROM login_log WHERE userId IN (1, 2, 3, 4, 5)",
"line": 115,
"time": 0.75697898864746
}
]
},
}
}
}