added a way to disable the profiler

This commit is contained in:
Fabien Potencier 2010-08-22 22:35:44 +02:00
parent 1687831cb7
commit fe78d5f0f0
2 changed files with 13 additions and 2 deletions

View File

@ -27,12 +27,14 @@ class Profiler implements \ArrayAccess
protected $collectors;
protected $response;
protected $logger;
protected $enabled;
public function __construct(ProfilerStorage $profilerStorage, LoggerInterface $logger = null)
{
$this->profilerStorage = $profilerStorage;
$this->logger = $logger;
$this->collectors = array();
$this->enabled = true;
}
/**
@ -75,6 +77,11 @@ class Profiler implements \ArrayAccess
return $profiler;
}
public function disable()
{
$this->enabled = false;
}
/**
* Collects data for the given Response.
*
@ -82,6 +89,10 @@ class Profiler implements \ArrayAccess
*/
public function collect(Response $response)
{
if (false === $this->enabled) {
return;
}
$this->response = $response;
$this->response->headers->set('X-Debug-Token', $this->profilerStorage->getToken());

View File

@ -48,8 +48,8 @@ class WebDebugToolbarListener
}
$request = $event->getParameter('request');
if ('3' === substr($response->getStatusCode(), 0, 1)
if (!$response->headers->has('X-Debug-Token')
|| '3' === substr($response->getStatusCode(), 0, 1)
|| ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html'))
|| 'html' !== $request->getRequestFormat()
|| $request->isXmlHttpRequest()