1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Modelarium\Laravel\Directives; |
4
|
|
|
|
5
|
|
|
use Modelarium\Exception\Exception; |
6
|
|
|
use Modelarium\Laravel\Targets\MigrationGenerator; |
7
|
|
|
use Modelarium\Laravel\Targets\ModelGenerator; |
8
|
|
|
use Modelarium\Laravel\Targets\Interfaces\MigrationDirectiveInterface; |
9
|
|
|
use Modelarium\Laravel\Targets\Interfaces\ModelDirectiveInterface; |
10
|
|
|
|
11
|
|
|
class MigrationIndexDirective implements MigrationDirectiveInterface, ModelDirectiveInterface |
12
|
|
|
{ |
13
|
1 |
|
public static function processMigrationTypeDirective( |
14
|
|
|
MigrationGenerator $generator, |
15
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
16
|
|
|
): void { |
17
|
|
|
/** @phpstan-ignore-next-line */ |
18
|
1 |
|
$values = $directive->arguments[0]->value->values; |
|
|
|
|
19
|
|
|
|
20
|
1 |
|
$indexFields = []; |
21
|
1 |
|
foreach ($values as $value) { |
22
|
1 |
|
$indexFields[] = $value->value; |
23
|
|
|
} |
24
|
1 |
|
if (!count($indexFields)) { |
25
|
|
|
throw new Exception("You must provide at least one field to an index"); |
26
|
|
|
} |
27
|
1 |
|
$generator->createCode[] ='$table->index("' . implode('", "', $indexFields) .'");'; |
28
|
1 |
|
} |
29
|
|
|
|
30
|
|
|
public static function processMigrationFieldDirective( |
31
|
|
|
MigrationGenerator $generator, |
32
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
33
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
34
|
|
|
): void { |
35
|
|
|
// nothing |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public static function processModelTypeDirective( |
39
|
|
|
ModelGenerator $generator, |
40
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
41
|
|
|
): void { |
42
|
|
|
throw new Exception("Primary index is not implemented yet"); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public static function processModelFieldDirective( |
46
|
|
|
ModelGenerator $generator, |
47
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
48
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
49
|
|
|
): void { |
50
|
|
|
// nothing |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public static function processModelRelationshipDirective( |
54
|
|
|
ModelGenerator $generator, |
55
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
56
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
57
|
|
|
): string { |
58
|
|
|
// nothing |
59
|
|
|
return ''; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|