Skip to content

Commit 08ab9bf

Browse files
committed
Dumper: added $customObjects
1 parent 75c9ba3 commit 08ab9bf

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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
/**
@@ -169,8 +170,11 @@ private function dumpObject(object $var, array $parents, int $level, int $column
169170

170171
throw new Nette\InvalidStateException('Cannot dump object of type Closure.');
171172

172-
} else {
173+
} elseif ($this->customObjects) {
173174
return $this->dumpCustomObject($var, $parents, $level);
175+
176+
} else {
177+
throw new Nette\InvalidStateException("Cannot dump object of type $class.");
174178
}
175179
}
176180

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\InvalidStateException::class,
209+
'Cannot dump object of type TestSer.',
210+
);

0 commit comments

Comments
 (0)