Skip to content

Commit

Permalink
Dumper: added $customObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 18, 2024
1 parent 75c9ba3 commit 08ab9bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/PhpGenerator/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class Dumper
public int $maxDepth = 50;
public int $wrapLength = 120;
public string $indentation = "\t";
public bool $customObjects = true;


/**
Expand Down Expand Up @@ -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.");
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/PhpGenerator/Dumper.dump().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
);

0 comments on commit 08ab9bf

Please sign in to comment.