|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @see https://github.com/open-code-modeling/json-schema-to-php-ast for the canonical source repository |
| 5 | + * @copyright https://github.com/open-code-modeling/json-schema-to-php-ast/blob/master/COPYRIGHT.md |
| 6 | + * @license https://github.com/open-code-modeling/json-schema-to-php-ast/blob/master/LICENSE.md MIT License |
| 7 | + */ |
| 8 | + |
| 9 | +declare(strict_types=1); |
| 10 | + |
| 11 | +namespace OpenCodeModeling\JsonSchemaToPhpAst; |
| 12 | + |
| 13 | +use OpenCodeModeling\JsonSchemaToPhp\Type\IntegerType; |
| 14 | +use OpenCodeModeling\JsonSchemaToPhp\Type\StringType; |
| 15 | +use OpenCodeModeling\JsonSchemaToPhp\Type\TypeDefinition; |
| 16 | +use OpenCodeModeling\JsonSchemaToPhpAst\ValueObject\IntegerFactory; |
| 17 | +use OpenCodeModeling\JsonSchemaToPhpAst\ValueObject\StringFactory; |
| 18 | +use PhpParser\NodeVisitor; |
| 19 | +use PhpParser\Parser; |
| 20 | + |
| 21 | +final class ValueObjectFactory |
| 22 | +{ |
| 23 | + private StringFactory $stringFactory; |
| 24 | + private IntegerFactory $integerFactory; |
| 25 | + |
| 26 | + public function __construct(Parser $parser, bool $typed) |
| 27 | + { |
| 28 | + $this->stringFactory = new StringFactory($parser, $typed); |
| 29 | + $this->integerFactory = new IntegerFactory($parser, $typed); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @param TypeDefinition $typeDefinition |
| 34 | + * @return array<NodeVisitor> |
| 35 | + */ |
| 36 | + public function nodeVisitors(TypeDefinition $typeDefinition): array |
| 37 | + { |
| 38 | + switch (true) { |
| 39 | + case $typeDefinition instanceof StringType: |
| 40 | + return $this->stringFactory->nodeVisitors($typeDefinition); |
| 41 | + case $typeDefinition instanceof IntegerType: |
| 42 | + return $this->integerFactory->nodeVisitors($typeDefinition); |
| 43 | + default: |
| 44 | + // TODO throw exception |
| 45 | + return []; |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments