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 17, 2024
1 parent 9ea6cd9 commit 933bb03
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 @@ -172,8 +173,11 @@ private function dumpObject(object $var, array $parents, int $level, int $column
$var = (array) $var;
return '(object) ' . $this->dumpArray($var, $parents, $level, $column + 10);

} else {
} elseif ($this->customObjects) {
return $this->dumpCustomObject($var, $parents, $level);

} else {
throw new Nette\InvalidArgumentException("Unable to dump class $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\InvalidArgumentException::class,
'Unable to dump class TestSer.',
);

0 comments on commit 933bb03

Please sign in to comment.