From 5b017aa0873b0c7248b94fb10f25cbde4619fda0 Mon Sep 17 00:00:00 2001 From: Michel Chowanski Date: Fri, 22 Sep 2023 16:38:33 +0200 Subject: [PATCH] feat(debug): #5 do not crash if profiler is enabled but APP_DEBUG is false --- src/Profiler/FeatureDataCollector.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Profiler/FeatureDataCollector.php b/src/Profiler/FeatureDataCollector.php index c24ab12..157b29d 100644 --- a/src/Profiler/FeatureDataCollector.php +++ b/src/Profiler/FeatureDataCollector.php @@ -2,6 +2,7 @@ namespace Flagception\Bundle\FlagceptionBundle\Profiler; +use Flagception\Activator\ChainActivator; use Flagception\Bundle\FlagceptionBundle\Activator\TraceableChainActivator; use Flagception\Decorator\ChainDecorator; use Symfony\Component\HttpFoundation\Request; @@ -37,7 +38,7 @@ class FeatureDataCollector extends DataCollector * @param TraceableChainActivator $chainActivator * @param ChainDecorator $chainDecorator */ - public function __construct(TraceableChainActivator $chainActivator, ChainDecorator $chainDecorator) + public function __construct(ChainActivator $chainActivator, ChainDecorator $chainDecorator) { $this->chainActivator = $chainActivator; $this->chainDecorator = $chainDecorator; @@ -58,7 +59,7 @@ public function collect(Request $request, Response $response, Throwable $excepti 'requests' => [], 'activators' => [], 'decorators' => [], - 'trace' => $this->chainActivator->getTrace() + 'trace' => [] ]; // Activators @@ -85,6 +86,12 @@ public function collect(Request $request, Response $response, Throwable $excepti } // Analyze trace + if (!$this->chainActivator instanceof TraceableChainActivator) { + return; + } + + $this->data['trace'] = $this->chainActivator->getTrace(); + foreach ($this->chainActivator->getTrace() as $trace) { if (!isset($this->data['requests'][$trace['feature']])) { $this->data['requests'][$trace['feature']] = [