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 Feb 6, 2024
1 parent 9334a93 commit a43bb2c
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
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,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
Original file line number Diff line number Diff line change
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 a43bb2c

Please sign in to comment.