added a way to disable the profiler
This commit is contained in:
parent
1687831cb7
commit
fe78d5f0f0
@ -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());
|
||||
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user