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 Sep 28, 2023
1 parent 29d48c0 commit cd3f6d4
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 @@ -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])
Expand Down
10 changes: 0 additions & 10 deletions src/DI/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,23 +182,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 cd3f6d4

Please sign in to comment.