diff --git a/src/PhpGenerator/Dumper.php b/src/PhpGenerator/Dumper.php index 24e929df..84d90a2d 100644 --- a/src/PhpGenerator/Dumper.php +++ b/src/PhpGenerator/Dumper.php @@ -22,6 +22,7 @@ final class Dumper public int $maxDepth = 50; public int $wrapLength = 120; public string $indentation = "\t"; + public bool $customObjects = true; /** @@ -169,8 +170,11 @@ private function dumpObject(object $var, array $parents, int $level, int $column throw new Nette\InvalidStateException('Cannot dump object of type Closure.'); - } else { + } elseif ($this->customObjects) { return $this->dumpCustomObject($var, $parents, $level); + + } else { + throw new Nette\InvalidStateException("Cannot dump object of type $class."); } } diff --git a/tests/PhpGenerator/Dumper.dump().phpt b/tests/PhpGenerator/Dumper.dump().phpt index f9e1d507..8dae1852 100644 --- a/tests/PhpGenerator/Dumper.dump().phpt +++ b/tests/PhpGenerator/Dumper.dump().phpt @@ -198,3 +198,13 @@ same( XX, $dumper->dump(new TestDateTime('2016-06-22 20:52:43.1234', new DateTimeZone('Europe/Prague'))), ); + + +// disallow custom objects +$dumper = new Dumper; +$dumper->customObjects = false; +Assert::exception( + fn() => $dumper->dump(new TestSer), + Nette\InvalidStateException::class, + 'Cannot dump object of type TestSer.', +);