Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Savluk committed Sep 25, 2023
1 parent c630c45 commit d99a715
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Performance/Performance.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace Savks\Negotiator\Performance;

use LogicException;
use Savks\Negotiator\Enums\PerformanceTrackers;

class Performance
{
protected readonly PerformanceProvider $provider;
protected readonly ?PerformanceProvider $provider;

/**
* @var array{
Expand All @@ -21,18 +22,24 @@ public function __construct()

$providerFQN = config("negotiator.debug.performance.providers.available.{$providerName}");

$this->provider = new $providerFQN();
$this->provider = config('negotiator.debug.enable') ?
new $providerFQN() :
null;

$this->trackers = config('negotiator.debug.performance.trackers');
}

public function event(string $event, array $data): Event
{
if ($this->provider === null) {
throw new LogicException('Performance tracking not enabled.');
}

return $this->provider->createEvent($event, $data);
}

public function trackedEnabled(PerformanceTrackers $tracker): bool
{
return $this->trackers[$tracker->value];
return $this->provider !== null && $this->trackers[$tracker->value];
}
}

0 comments on commit d99a715

Please sign in to comment.