Skip to content

Commit e9f3d9b

Browse files
committed
add export
1 parent 5f48bed commit e9f3d9b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Interfaces/VarDumpInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function withShift(int $shift): self;
4343
*/
4444
public function process(WriterInterface $writer): void;
4545

46+
/**
47+
* Export the dump as a string.
48+
*/
49+
public function export(): string;
50+
4651
/**
4752
* Provides access to the dump variables.
4853
* @return array<mixed>

src/VarDump.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Chevere\VarDump\Interfaces\OutputInterface;
1818
use Chevere\VarDump\Interfaces\VarDumpInterface;
1919
use Chevere\Writer\Interfaces\WriterInterface;
20+
use Chevere\Writer\StreamWriter;
21+
use function Chevere\Writer\streamTemp;
2022

2123
final class VarDump implements VarDumpInterface
2224
{
@@ -68,6 +70,15 @@ public function process(WriterInterface $writer): void
6870
->process($this->output, ...$this->variables);
6971
}
7072

73+
public function export(): string
74+
{
75+
$temp = streamTemp();
76+
$tempWriter = new StreamWriter($temp);
77+
$this->process($tempWriter);
78+
79+
return $tempWriter->__toString();
80+
}
81+
7182
public function variables(): array
7283
{
7384
return $this->variables;

0 commit comments

Comments
 (0)