Skip to content

Commit

Permalink
PhpGenerator: DTO and DateTime are not suspicious objects [Closes #306][
Browse files Browse the repository at this point in the history
Closes #308]
  • Loading branch information
kukulich authored and dg committed Feb 12, 2024
1 parent cba0caf commit 6b9910c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/DI/PhpGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public function convertArguments(array $args): array
}
} elseif (
is_object($val)
&& !$val instanceof Php\Literal && !$val instanceof \stdClass && !$val instanceof \UnitEnum
&& !$val instanceof Php\Literal && !$val instanceof \DateTimeInterface
&& (new \ReflectionObject($val))->getProperties(\ReflectionProperty::IS_PRIVATE | \ReflectionProperty::IS_PROTECTED)
) {
trigger_error(sprintf('Nette DI: suspicious dumping of objects %s when generating the container', $val::class));
}
Expand Down
13 changes: 13 additions & 0 deletions tests/DI/Compiler.parameters.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ test('Statement within string expansion', function () {
});


test('Statement with datetime', function () {
$compiler = new DI\Compiler;
$container = createContainer($compiler, '
parameters:
datetime: 2000-01-01 00:00:00 +0000
services:
one: Service(%datetime%)
');

Assert::same('2000-01-01', $container->getService('one')->arg->format('Y-m-d'));
});

test('Statement within array expansion', function () {
$compiler = new DI\Compiler;
$container = createContainer($compiler, '
Expand Down

0 comments on commit 6b9910c

Please sign in to comment.