*/
class Profiler
{
- /**
- * @var ProfilerStorageInterface
- */
private $storage;
/**
*/
private $collectors = array();
- /**
- * @var LoggerInterface
- */
private $logger;
-
- /**
- * @var bool
- */
+ private $initiallyEnabled = true;
private $enabled = true;
/**
- * Constructor.
- *
- * @param ProfilerStorageInterface $storage A ProfilerStorageInterface instance
- * @param LoggerInterface $logger A LoggerInterface instance
+ * @param bool $enable The initial enabled state
*/
- public function __construct(ProfilerStorageInterface $storage, LoggerInterface $logger = null)
+ public function __construct(ProfilerStorageInterface $storage, LoggerInterface $logger = null, $enable = true)
{
$this->storage = $storage;
$this->logger = $logger;
+ $this->initiallyEnabled = $this->enabled = (bool) $enable;
}
/**
/**
* Loads the Profile for the given Response.
*
- * @param Response $response A Response instance
- *
* @return Profile|false A Profile instance
*/
public function loadProfileFromResponse(Response $response)
/**
* Saves a Profile.
*
- * @param Profile $profile A Profile instance
- *
* @return bool
*/
public function saveProfile(Profile $profile)
/**
* Collects data for the given Response.
*
- * @param Request $request A Request instance
- * @param Response $response A Response instance
- * @param \Exception $exception An exception instance if the request threw one
- *
* @return Profile|null A Profile instance or null if the profiler is disabled
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
return $profile;
}
+ public function reset()
+ {
+ foreach ($this->collectors as $collector) {
+ if (!method_exists($collector, 'reset')) {
+ continue;
+ }
+
+ $collector->reset();
+ }
+ $this->enabled = $this->initiallyEnabled;
+ }
+
/**
* Gets the Collectors associated with this profiler.
*
/**
* Adds a Collector.
- *
- * @param DataCollectorInterface $collector A DataCollectorInterface instance
*/
public function add(DataCollectorInterface $collector)
{
+ if (!method_exists($collector, 'reset')) {
+ @trigger_error(sprintf('Implementing "%s" without the "reset()" method is deprecated since Symfony 3.4 and will be unsupported in 4.0 for class "%s".', DataCollectorInterface::class, \get_class($collector)), E_USER_DEPRECATED);
+ }
+
$this->collectors[$collector->getName()] = $collector;
}