From bba2d9c0523e0c3c3249e642e4fa2e755821f57c Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Sat, 25 Nov 2023 22:14:28 +0400 Subject: [PATCH] TrapHandle: add `if(condition)` method to dump only if the condition is true. --- src/Client/TrapHandle.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Client/TrapHandle.php b/src/Client/TrapHandle.php index bf3831b2..1fb9bcae 100644 --- a/src/Client/TrapHandle.php +++ b/src/Client/TrapHandle.php @@ -23,6 +23,19 @@ public static function fromArray(array $array): self return $new; } + /** + * Dump only if the condition is true. + */ + public function if(bool|callable $condition): self + { + if (\is_callable($condition)) { + $condition = $condition(); + } + + $this->haveToSend = $condition; + return $this; + } + public function __destruct() { $this->haveToSend and $this->sendUsingDump();