From 760316372a4ae6cadcd9292200098f9f0ad2f624 Mon Sep 17 00:00:00 2001 From: Jared Scholz Date: Thu, 2 Feb 2023 11:23:04 +1300 Subject: [PATCH] Added constructNew to client to instantly maintain settings --- src/RaygunClient.php | 26 ++++++++++++++++++++++++++ src/RaygunClientManager.php | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/RaygunClient.php b/src/RaygunClient.php index fa398a0..2a94f98 100644 --- a/src/RaygunClient.php +++ b/src/RaygunClient.php @@ -7,6 +7,32 @@ // RaygunClient wrapper provides protected field access class RaygunClient extends BaseRaygunClient { + /** + * Return a new copy of this client with new constructor arguments applied + * + * @param TransportInterface $transport + * @param bool $userTracking + * + * @return RaygunClient + */ + public function constructNew(TransportInterface $transport, bool $userTracking = true): RaygunClient { + $newClient = new RaygunClient($transport, !$userTracking); + $newClient->SetUser( + $this->user, + $this->firstName, + $this->fullName, + $this->email, + $this->isAnonymous, + $this->uuid + ); + $newClient->setUserIdentifier($this->userIdentifier); + $newClient->SetVersion($this->version); + $newClient->SetGroupingKey($this->groupingKeyCallback); + $newClient->setFilterParams($this->filterParams); + $newClient->setFilterAllFormValues($this->filterAllFormValues); + return $newClient; + } + /** * Get the transport being used by the client * diff --git a/src/RaygunClientManager.php b/src/RaygunClientManager.php index d15b7c8..e38b0bb 100644 --- a/src/RaygunClientManager.php +++ b/src/RaygunClientManager.php @@ -78,7 +78,7 @@ private static function createNewInstance($async, $userTracking): void { $transport->setLogger(self::$logger); } - self::$instance = new RaygunClient($transport, !$userTracking); + self::$instance = self::$instance->constructNew($transport, $userTracking); self::$currentAsyncState = $async; }