Skip to content

Commit

Permalink
Resolver: processing of functions like not() moved to PhpGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 28, 2024
1 parent 5f9473e commit 6938188
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/DI/PhpGenerator.php
Expand Up @@ -112,6 +112,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])
Expand Down
10 changes: 0 additions & 10 deletions src/DI/Resolver.php
Expand Up @@ -192,23 +192,13 @@ 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':
case $entity === 'string':
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
Expand Down

0 comments on commit 6938188

Please sign in to comment.