diff --git a/functions.php b/functions.php index 1ad7654..95263e9 100644 --- a/functions.php +++ b/functions.php @@ -11,6 +11,8 @@ function pd(): Client $client = new Client(); } + // To not overwrite the last message again and again + $client->setLastMessageId(); return $client; } } diff --git a/src/Client.php b/src/Client.php index 4c6623f..f731e88 100644 --- a/src/Client.php +++ b/src/Client.php @@ -16,6 +16,11 @@ class Client { + /** + * @var string|null + */ + private $lastMessageId; + /** * @var string */ @@ -47,7 +52,6 @@ public function log(... $arguments): self $cloner->setMaxItems(-1); $htmlDumper = new HtmlDumper(); - foreach ($arguments as $argument) { $data = $htmlDumper->dump($cloner->cloneVar($argument), true); $msg->payload(new HtmlPayload($data)); @@ -182,6 +186,8 @@ public function send(Message $message): void \curl_exec($ch); \curl_close($ch); + + $this->lastMessageId = $message->getId(); } protected function createMessage(): Message @@ -193,7 +199,7 @@ protected function createMessage(): Message continue; } - return new Message($this->stripPath($backtrace['file']), $backtrace['line']); + return new Message($this->stripPath($backtrace['file']), $backtrace['line'], $this->lastMessageId ?? null); } throw new \RuntimeException('Cannot detect entry point'); @@ -213,7 +219,7 @@ private function lockExists(string $id): bool $resp = \curl_exec($ch); \curl_close($ch); - return $resp === "1"; + return $resp === '1'; } private function stripPath(string $path): string @@ -226,4 +232,11 @@ private function stripPath(string $path): string return $path; } + + public function setLastMessageId(?string $lastMessageId = null): self + { + $this->lastMessageId = $lastMessageId; + + return $this; + } } diff --git a/src/Message/Message.php b/src/Message/Message.php index 0229e99..ed1fc0e 100644 --- a/src/Message/Message.php +++ b/src/Message/Message.php @@ -33,9 +33,9 @@ class Message extends Struct */ protected $payloads = []; - public function __construct(string $fileName, int $lineNumber) + public function __construct(string $fileName, int $lineNumber, ?string $uuid = null) { - $this->uuid = Uuid::randomHex(); + $this->uuid = $uuid ?? Uuid::randomHex(); $this->time = \microtime(true); $this->origin = new Origin($fileName, $lineNumber); }