| @@ 22-71 (lines=50) @@ | ||
| 19 | /** |
|
| 20 | * Class InterfaceBuilder |
|
| 21 | */ |
|
| 22 | class InterfaceBuilder extends DefinitionBuilder |
|
| 23 | { |
|
| 24 | /** |
|
| 25 | * @param Readable $file |
|
| 26 | * @param RuleInterface|InterfaceDefinitionNode $ast |
|
| 27 | * @return \Generator|mixed |
|
| 28 | */ |
|
| 29 | public function build(Readable $file, RuleInterface $ast) |
|
| 30 | { |
|
| 31 | $interface = new TypeDefinition($ast->getFullName()); |
|
| 32 | $interface->in($file, $ast->getOffset()); |
|
| 33 | ||
| 34 | $interface->type = Type::INTERFACE; |
|
| 35 | $interface->description = $ast->getDescription(); |
|
| 36 | ||
| 37 | $this->loadInterfaces($ast, $interface); |
|
| 38 | ||
| 39 | yield from $this->loadFields($ast, $interface); |
|
| 40 | ||
| 41 | return $interface; |
|
| 42 | } |
|
| 43 | ||
| 44 | ||
| 45 | /** |
|
| 46 | * @param InterfaceDefinitionNode $ast |
|
| 47 | * @param TypeDefinition $object |
|
| 48 | * @return \Generator |
|
| 49 | */ |
|
| 50 | protected function loadFields(InterfaceDefinitionNode $ast, TypeDefinition $object): \Generator |
|
| 51 | { |
|
| 52 | $object->fields = []; |
|
| 53 | ||
| 54 | foreach ($ast->getFieldNodes() as $field) { |
|
| 55 | $object->fields[] = yield $field; |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * @param InterfaceDefinitionNode $ast |
|
| 61 | * @param TypeDefinition $object |
|
| 62 | */ |
|
| 63 | protected function loadInterfaces(InterfaceDefinitionNode $ast, TypeDefinition $object): void |
|
| 64 | { |
|
| 65 | $object->implements = []; |
|
| 66 | ||
| 67 | foreach ($ast->getInterfaces() as $interface) { |
|
| 68 | $object->implements[] = $interface; |
|
| 69 | } |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||
| @@ 22-70 (lines=49) @@ | ||
| 19 | /** |
|
| 20 | * Class ObjectBuilder |
|
| 21 | */ |
|
| 22 | class ObjectBuilder extends DefinitionBuilder |
|
| 23 | { |
|
| 24 | /** |
|
| 25 | * @param Readable $file |
|
| 26 | * @param RuleInterface|ObjectDefinitionNode $ast |
|
| 27 | * @return \Generator|mixed |
|
| 28 | */ |
|
| 29 | public function build(Readable $file, RuleInterface $ast) |
|
| 30 | { |
|
| 31 | $object = new TypeDefinition($ast->getFullName()); |
|
| 32 | $object->in($file, $ast->getOffset()); |
|
| 33 | ||
| 34 | $object->type = Type::OBJECT; |
|
| 35 | $object->description = $ast->getDescription(); |
|
| 36 | ||
| 37 | $this->loadInterfaces($ast, $object); |
|
| 38 | ||
| 39 | yield from $this->loadFields($ast, $object); |
|
| 40 | ||
| 41 | return $object; |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * @param ObjectDefinitionNode $ast |
|
| 46 | * @param TypeDefinition $object |
|
| 47 | * @return \Generator |
|
| 48 | */ |
|
| 49 | protected function loadFields(ObjectDefinitionNode $ast, TypeDefinition $object): \Generator |
|
| 50 | { |
|
| 51 | $object->fields = []; |
|
| 52 | ||
| 53 | foreach ($ast->getFieldNodes() as $field) { |
|
| 54 | $object->fields[] = yield $field; |
|
| 55 | } |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * @param ObjectDefinitionNode $ast |
|
| 60 | * @param TypeDefinition $object |
|
| 61 | */ |
|
| 62 | protected function loadInterfaces(ObjectDefinitionNode $ast, TypeDefinition $object): void |
|
| 63 | { |
|
| 64 | $object->implements = []; |
|
| 65 | ||
| 66 | foreach ($ast->getInterfaces() as $interface) { |
|
| 67 | $object->implements[] = $interface; |
|
| 68 | } |
|
| 69 | } |
|
| 70 | } |
|
| 71 | ||