| @@ 21-54 (lines=34) @@ | ||
| 18 | /** |
|
| 19 | * Class InterfaceBuilder |
|
| 20 | */ |
|
| 21 | class InterfaceBuilder extends Builder |
|
| 22 | { |
|
| 23 | /** |
|
| 24 | * @param RuleInterface|InterfaceDefinitionNode $rule |
|
| 25 | * @param Definition $parent |
|
| 26 | * @return Definition |
|
| 27 | * @throws \Railt\Io\Exception\ExternalFileException |
|
| 28 | */ |
|
| 29 | public function build(RuleInterface $rule, Definition $parent): Definition |
|
| 30 | { |
|
| 31 | $interface = new ObjectDefinition($parent->getDocument(), $rule->getTypeName()); |
|
| 32 | ||
| 33 | $interface->withOffset($rule->getOffset()); |
|
| 34 | $interface->withDescription($rule->getDescription()); |
|
| 35 | ||
| 36 | foreach ($rule->getFields() as $ast) { |
|
| 37 | $interface->withField($this->dependent($ast, $interface)); |
|
| 38 | } |
|
| 39 | ||
| 40 | $this->when->runtime(function () use ($rule, $interface) { |
|
| 41 | foreach ($rule->getDirectives() as $ast) { |
|
| 42 | $interface->withDirective($this->dependent($ast, $interface)); |
|
| 43 | } |
|
| 44 | }); |
|
| 45 | ||
| 46 | $this->when->resolving(function () use ($rule, $interface) { |
|
| 47 | foreach ($rule->getImplementations() as $child) { |
|
| 48 | $interface->withInterface($child->getTypeName()); |
|
| 49 | } |
|
| 50 | }); |
|
| 51 | ||
| 52 | return $interface; |
|
| 53 | } |
|
| 54 | } |
|
| 55 | ||
| @@ 21-54 (lines=34) @@ | ||
| 18 | /** |
|
| 19 | * Class ObjectBuilder |
|
| 20 | */ |
|
| 21 | class ObjectBuilder extends Builder |
|
| 22 | { |
|
| 23 | /** |
|
| 24 | * @param RuleInterface|ObjectDefinitionNode $rule |
|
| 25 | * @param Definition $parent |
|
| 26 | * @return Definition |
|
| 27 | * @throws \Railt\Io\Exception\ExternalFileException |
|
| 28 | */ |
|
| 29 | public function build(RuleInterface $rule, Definition $parent): Definition |
|
| 30 | { |
|
| 31 | $object = new ObjectDefinition($parent->getDocument(), $rule->getTypeName()); |
|
| 32 | ||
| 33 | $object->withOffset($rule->getOffset()); |
|
| 34 | $object->withDescription($rule->getDescription()); |
|
| 35 | ||
| 36 | foreach ($rule->getFields() as $ast) { |
|
| 37 | $object->withField($this->dependent($ast, $object)); |
|
| 38 | } |
|
| 39 | ||
| 40 | $this->when->resolving(function () use ($rule, $object) { |
|
| 41 | foreach ($rule->getImplementations() as $interface) { |
|
| 42 | $object->withInterface($interface->getTypeName()); |
|
| 43 | } |
|
| 44 | }); |
|
| 45 | ||
| 46 | $this->when->runtime(function () use ($rule, $object) { |
|
| 47 | foreach ($rule->getDirectives() as $ast) { |
|
| 48 | $object->withDirective($this->dependent($ast, $object)); |
|
| 49 | } |
|
| 50 | }); |
|
| 51 | ||
| 52 | return $object; |
|
| 53 | } |
|
| 54 | } |
|
| 55 | ||