From 515237532fbcf0a34f293cd2f4cdc46a6cb28837 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 13ad83863..e475cd085 100644 --- a/src/DI/PhpGenerator.php +++ b/src/DI/PhpGenerator.php @@ -113,6 +113,15 @@ public function formatStatement(Statement $statement): string case is_string($entity) && str_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 09c2fe1c8..819fc34ee 100644 --- a/src/DI/Resolver.php +++ b/src/DI/Resolver.php @@ -192,13 +192,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': @@ -206,9 +199,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