Skip to content

Commit cb945ff

Browse files
committed
Dumper: added $customObjects
1 parent 92a1f61 commit cb945ff

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/PhpGenerator/Dumper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ final class Dumper
2222
public int $maxDepth = 50;
2323
public int $wrapLength = 120;
2424
public string $indentation = "\t";
25+
public bool $customObjects = true;
2526

2627

2728
/**
@@ -172,8 +173,11 @@ private function dumpObject(object $var, array $parents, int $level, int $column
172173
$var = (array) $var;
173174
return '(object) ' . $this->dumpArray($var, $parents, $level, $column + 10);
174175

175-
} else {
176+
} elseif ($this->customObjects) {
176177
return $this->dumpCustomObject($var, $parents, $level);
178+
179+
} else {
180+
throw new Nette\InvalidArgumentException("Unable to dump class $class.");
177181
}
178182
}
179183

tests/PhpGenerator/Dumper.dump().phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,13 @@ same(
198198
XX,
199199
$dumper->dump(new TestDateTime('2016-06-22 20:52:43.1234', new DateTimeZone('Europe/Prague'))),
200200
);
201+
202+
203+
// disallow custom objects
204+
$dumper = new Dumper;
205+
$dumper->customObjects = false;
206+
Assert::exception(
207+
fn() => $dumper->dump(new TestSer),
208+
Nette\InvalidArgumentException::class,
209+
'Unable to dump class TestSer.',
210+
);

0 commit comments

Comments
 (0)