Skip to content

Commit 182fc16

Browse files
committed
feat: add dumpif dump if condition true
1 parent 3c0303a commit 182fc16

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Put `here()` anywhere to your code
2020
- `here()->countAll()`, count all group.
2121

2222
### Other
23+
- `here()->dumpIf()`, dump current line (if condition true).
2324
- `here()->info()`, dump current line (without code snapshot).
2425
- `track()`, print debug backtrace information.
2526
- `work()`, short hand for `here()->dump()`.

src/Abstracts/Printer.php

+19
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,23 @@ abstract protected function printInfo(&$print, $content, $with_counter = false);
6363
* @return void
6464
*/
6565
abstract protected function printSnapshot(&$print, $content, ...$var);
66+
67+
/**
68+
* Dump if condition true.
69+
*
70+
* @param \Closure|bool $condition
71+
* @param string|array<int|string, mixed>|false $var
72+
*
73+
* @return void
74+
*/
75+
public function dumpIf($condition, ...$var)
76+
{
77+
$condition = is_callable($condition)
78+
? call_user_func($condition)
79+
: $condition;
80+
81+
if ($condition === true) {
82+
$this->dump(...$var);
83+
}
84+
}
6685
}

0 commit comments

Comments
 (0)