我想用我自己的自定义数据扩展Symfony2调试工具栏。如何用自定义数据扩展Symfony2调试工具栏?
我有我想要的记录特定的方法调用,然后调试工具栏显示它们的服务。
我读了cookbook article,但它不是很有帮助。
我创建了自己DataCollector
类:
class PermissionDataCollector extends DataCollector
{
private $permissionCalls = array();
private $permissionExtension;
public function __construct(PermissionExtension $permissionExtension)
{
$this->permissionExtension = $permissionExtension;
}
/**
* Collects data for the given Request and Response.
*
* @param Request $request A Request instance
* @param Response $response A Response instance
* @param \Exception $exception An Exception instance
*
* @api
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->permissionCalls = $this->permissionExtension->getPermissionCalls();
$this->data = array(
'calls' => $this->permissionCalls
);
}
public function getPermissionCallsCount()
{
return count($this->permissionCalls);
}
public function getFailedPermissionCallsCount()
{
return count(array_filter($this->permissionCalls, array(&$this, "filterForFailedPermissionCalls")));
}
private function filterForFailedPermissionCalls($var)
{
return $var['success'];
}
/**
* Returns the name of the collector.
*
* @return string The collector name
*
* @api
*/
public function getName()
{
return 'permission';
}
}
的PermissionExtension
记录所有来电,然后我想在 PermissionDataCollector
检索该数组调用。
和模板只是输出{{ collector.permissionCallsCount }}
。
该部分显示在工具栏中,但只显示0
这是错误的。
我不知道如果我连这样做的权利,因为该文档缺乏这一部分。我使用的Symfony 2.1
有没有人扩展了自定义数据的工具栏?
我不知道如何从内存中做到这一点,但我知道FOQElasticaBundle会显示ElasticSearch查询的日志,这将是一个很好的开始。 – Steve 2013-05-14 22:19:19
啊太棒了!有用。我基本上需要始终引用'$ this-> data'。非常感谢捆绑参考! – 2013-05-15 09:31:11
哈,拍摄和分数:)很高兴它帮助! – Steve 2013-05-18 13:19:08