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

View File

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