Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / http-kernel / Profiler / Profiler.php
index f31e243770cbf35bc8f8f37fc3230306bd7f5374..15bfbc5a07777ae51d7be9de501f65d7d7a6dca5 100644 (file)
@@ -25,9 +25,6 @@ use Psr\Log\LoggerInterface;
  */
 class Profiler
 {
-    /**
-     * @var ProfilerStorageInterface
-     */
     private $storage;
 
     /**
@@ -35,26 +32,18 @@ class Profiler
      */
     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;
     }
 
     /**
@@ -76,8 +65,6 @@ class Profiler
     /**
      * Loads the Profile for the given Response.
      *
-     * @param Response $response A Response instance
-     *
      * @return Profile|false A Profile instance
      */
     public function loadProfileFromResponse(Response $response)
@@ -104,8 +91,6 @@ class Profiler
     /**
      * Saves a Profile.
      *
-     * @param Profile $profile A Profile instance
-     *
      * @return bool
      */
     public function saveProfile(Profile $profile)
@@ -155,10 +140,6 @@ class Profiler
     /**
      * 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)
@@ -190,6 +171,18 @@ class Profiler
         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.
      *
@@ -215,11 +208,13 @@ class 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;
     }