Skip to content

Commit

Permalink
Support InlineTypeResolver in DartClassFactoryGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
kubk committed Mar 21, 2023
1 parent ae6bed1 commit 4754e31
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Language/Dart/DartClassFactoryGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
use Riverwaysoft\DtoConverter\Dto\PhpType\PhpTypeInterface;
use Riverwaysoft\DtoConverter\Dto\PhpType\PhpUnionType;
use Riverwaysoft\DtoConverter\Dto\PhpType\PhpUnknownType;
use Riverwaysoft\DtoConverter\Language\UnknownTypeResolver\InlineTypeResolver;
use Webmozart\Assert\Assert;

class DartClassFactoryGenerator
{
public function __construct(private string|null $excludePattern = null)
public function __construct(
private string|null $excludePattern = null,
private InlineTypeResolver|null $inlineTypeResolver = null,
)
{
}

Expand Down Expand Up @@ -104,6 +108,13 @@ private function resolveFactoryProperty(
return sprintf("%s.values[{$mapArgumentName}]", $type->getName(), $propertyName);
}

if ($this->inlineTypeResolver?->supports($type, $dto, $dtoList)) {
$resolved = $this->inlineTypeResolver->resolve($type, $dto, $dtoList);
if ($resolved instanceof PhpTypeInterface) {
return $this->resolveFactoryProperty($propertyName, $resolved, $dto, $dtoList, $mapArgumentName);
}
}

return sprintf("%s.fromJson({$mapArgumentName})", $type->getName(), $propertyName);
}

Expand Down

0 comments on commit 4754e31

Please sign in to comment.