From 31387ba8d5cbabbb4a7730b1b40a2e0f5511c376 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 15 Dec 2021 19:45:29 +0100 Subject: [PATCH] Resolver: processing of functions like not() moved to PhpGenerator --- src/DI/PhpGenerator.php | 9 +++++++++ src/DI/Resolver.php | 10 ---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/DI/PhpGenerator.php b/src/DI/PhpGenerator.php index c7bc85af7..d80fcd36c 100644 --- a/src/DI/PhpGenerator.php +++ b/src/DI/PhpGenerator.php @@ -118,6 +118,15 @@ public function formatStatement(Statement $statement): string case is_string($entity) && Strings::contains($entity, '?'): // PHP literal return $this->formatPhp($entity, $arguments); + case $entity === 'not': + return $this->formatPhp('!(?)', $arguments); + + case $entity === 'bool': + case $entity === 'int': + case $entity === 'float': + case $entity === 'string': + return $this->formatPhp('?::?(?, ?)', [Helpers::class, 'convertType', $arguments[0], $entity]); + case is_string($entity): // create class return $arguments ? $this->formatPhp("new $entity(...?:)", [$arguments]) diff --git a/src/DI/Resolver.php b/src/DI/Resolver.php index 41efe9796..2ca2a8e94 100644 --- a/src/DI/Resolver.php +++ b/src/DI/Resolver.php @@ -182,13 +182,6 @@ public function completeStatement(Statement $statement, bool $currentServiceAllo break; case $entity === 'not': - if (count($arguments) !== 1) { - throw new ServiceCreationException(sprintf('Function %s() expects 1 parameter, %s given.', $entity, count($arguments))); - } - - $entity = ['', '!']; - break; - case $entity === 'bool': case $entity === 'int': case $entity === 'float': @@ -196,9 +189,6 @@ public function completeStatement(Statement $statement, bool $currentServiceAllo if (count($arguments) !== 1) { throw new ServiceCreationException(sprintf('Function %s() expects 1 parameter, %s given.', $entity, count($arguments))); } - - $arguments = [$arguments[0], $entity]; - $entity = [Helpers::class, 'convertType']; break; case is_string($entity): // create class