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 Nov 2, 2023
1 parent a0460ba commit b109822
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 @@ -112,6 +112,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 b109822

Please sign in to comment.