diff --git a/src/Viserio/Component/Contract/Profiler/DataCollector.php b/src/Viserio/Component/Contract/Profiler/DataCollector.php index 035c82b84..265bc3d26 100644 --- a/src/Viserio/Component/Contract/Profiler/DataCollector.php +++ b/src/Viserio/Component/Contract/Profiler/DataCollector.php @@ -42,4 +42,11 @@ public function getMenu(): array; * @return string */ public function getMenuPosition(): string; + + /** + * Resets this data collector to its initial state. + * + * @return void + */ + public function flush(): void; } diff --git a/src/Viserio/Component/Contract/Profiler/Profiler.php b/src/Viserio/Component/Contract/Profiler/Profiler.php index 45656ea07..94d40efd4 100644 --- a/src/Viserio/Component/Contract/Profiler/Profiler.php +++ b/src/Viserio/Component/Contract/Profiler/Profiler.php @@ -102,4 +102,10 @@ public function setUrlGenerator(UrlGeneratorContract $urlGenerator): Profiler; * @return null|\Viserio\Component\Contract\Routing\UrlGenerator */ public function getUrlGenerator(): ?UrlGeneratorContract; + + /** + * + * @return void + */ + public function flush(): void; } diff --git a/src/Viserio/Component/Events/DataCollector/TraceableEventManager.php b/src/Viserio/Component/Events/DataCollector/TraceableEventManager.php index 9ed3a6027..5eea5bca5 100644 --- a/src/Viserio/Component/Events/DataCollector/TraceableEventManager.php +++ b/src/Viserio/Component/Events/DataCollector/TraceableEventManager.php @@ -224,6 +224,16 @@ public function getOrphanedEvents(): array return $this->orphanedEvents; } + /** + * Resets this to its initial state. + * + * @return void + */ + public function flush(): void + { + $this->called = []; + } + /** * @param string $eventName * @param $listener diff --git a/src/Viserio/Component/Events/DataCollector/ViserioEventsDataCollector.php b/src/Viserio/Component/Events/DataCollector/ViserioEventsDataCollector.php index 9f757a474..c5f54be8d 100644 --- a/src/Viserio/Component/Events/DataCollector/ViserioEventsDataCollector.php +++ b/src/Viserio/Component/Events/DataCollector/ViserioEventsDataCollector.php @@ -116,4 +116,14 @@ public function getPanel(): string ], ]); } + + /** + * {@inheritdoc} + */ + public function flush(): void + { + $this->data = array(); + + $this->eventManager->flush(); + } } diff --git a/src/Viserio/Component/Profiler/DataCollector/AbstractDataCollector.php b/src/Viserio/Component/Profiler/DataCollector/AbstractDataCollector.php index 68e0f4e3d..39d3c5ce0 100644 --- a/src/Viserio/Component/Profiler/DataCollector/AbstractDataCollector.php +++ b/src/Viserio/Component/Profiler/DataCollector/AbstractDataCollector.php @@ -82,6 +82,14 @@ public function getData(): array return $this->data; } + /** + + * {@inheritdoc} + + */ + public function flush(): void + { + $this->data = []; + } + /** * Add measurement to float time. * diff --git a/src/Viserio/Component/Profiler/Profiler.php b/src/Viserio/Component/Profiler/Profiler.php index 2058b8a06..1da4bc40b 100644 --- a/src/Viserio/Component/Profiler/Profiler.php +++ b/src/Viserio/Component/Profiler/Profiler.php @@ -210,6 +210,16 @@ public function getAssetsRenderer(): AssetsRendererContract return $this->assetsRenderer; } + /** + * {@inheritdoc} + */ + public function flush(): void + { + foreach ($this->collectors as $collector) { + $collector->flush(); + } + } + /** * Injects the web debug toolbar into the given Response. *