diff --git a/src/DI/PhpGenerator.php b/src/DI/PhpGenerator.php index 42a979059..961f96d8f 100644 --- a/src/DI/PhpGenerator.php +++ b/src/DI/PhpGenerator.php @@ -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)); } diff --git a/tests/DI/Compiler.parameters.phpt b/tests/DI/Compiler.parameters.phpt index 778de5e4c..e971ee4d6 100644 --- a/tests/DI/Compiler.parameters.phpt +++ b/tests/DI/Compiler.parameters.phpt @@ -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, '