|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Modelarium\Laravel\Directives; |
|
4
|
|
|
|
|
5
|
|
|
use Formularium\Datatype\Datatype_constant; |
|
6
|
|
|
use Illuminate\Support\Str; |
|
7
|
|
|
use Modelarium\Laravel\Targets\ModelGenerator; |
|
8
|
|
|
use Modelarium\Laravel\Targets\Interfaces\ModelDirectiveInterface; |
|
9
|
|
|
use Modelarium\Parser; |
|
10
|
|
|
|
|
11
|
|
|
class ModelAccessorDirective implements ModelDirectiveInterface |
|
12
|
|
|
{ |
|
13
|
|
|
public static function processModelTypeDirective( |
|
14
|
|
|
ModelGenerator $generator, |
|
15
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
|
16
|
|
|
): void { |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public static function processModelFieldDirective( |
|
20
|
|
|
ModelGenerator $generator, |
|
21
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
|
22
|
|
|
\Formularium\Field $fieldFormularium, |
|
23
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
|
24
|
|
|
): void { |
|
25
|
|
|
$studly = Str::studly($field->name); |
|
26
|
|
|
// TODO: return type, converted to PHP |
|
27
|
|
|
// list($type, $isRequired) = Parser::getUnwrappedType($field->type); |
|
28
|
|
|
// $typeName = $type->name; |
|
29
|
|
|
|
|
30
|
|
|
$generator->class->addMethod("get{$studly}Attribute") |
|
31
|
|
|
->setPublic() |
|
32
|
|
|
->setAbstract(); // user will fill it |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public static function processModelRelationshipDirective( |
|
36
|
|
|
ModelGenerator $generator, |
|
37
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
|
38
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
|
39
|
|
|
\Formularium\Datatype $datatype = null |
|
40
|
|
|
): ?\Formularium\Datatype { |
|
41
|
|
|
$studly = Str::studly($field->name); |
|
42
|
|
|
list($type, $isRequired) = Parser::getUnwrappedType($field->type); |
|
43
|
|
|
|
|
44
|
|
|
$generator->class->addMethod("get{$studly}Attribute") |
|
45
|
|
|
->setPublic() |
|
46
|
|
|
->setReturnType('array') |
|
47
|
|
|
->setReturnNullable($isRequired) |
|
48
|
|
|
->setAbstract(); |
|
49
|
|
|
return new Datatype_constant(); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|