1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Modelarium\Laravel\Directives; |
4
|
|
|
|
5
|
|
|
use Modelarium\Exception\DirectiveException; |
6
|
|
|
use Modelarium\Exception\Exception; |
7
|
|
|
use Modelarium\Laravel\Targets\MigrationGenerator; |
8
|
|
|
use Modelarium\Laravel\Targets\ModelGenerator; |
9
|
|
|
use Modelarium\Laravel\Targets\Interfaces\MigrationDirectiveInterface; |
10
|
|
|
use Modelarium\Laravel\Targets\Interfaces\ModelDirectiveInterface; |
11
|
|
|
use Modelarium\Laravel\Targets\MigrationCodeFragment; |
12
|
|
|
use Modelarium\Parser; |
13
|
|
|
|
14
|
|
|
class MigrationFulltextIndexDirective implements MigrationDirectiveInterface, ModelDirectiveInterface |
15
|
|
|
{ |
16
|
1 |
|
public static function processMigrationTypeDirective( |
17
|
|
|
MigrationGenerator $generator, |
18
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
19
|
|
|
): void { |
20
|
1 |
|
$indexFields = Parser::getDirectiveArgumentByName($directive, 'fields'); |
21
|
|
|
|
22
|
1 |
|
if (!count($indexFields)) { |
23
|
|
|
throw new Exception("You must provide at least one field to a full text index"); |
24
|
|
|
} |
25
|
1 |
|
$generator->postCreateCode[] = "DB::statement('ALTER TABLE " . |
26
|
1 |
|
$generator->getTableName() . |
27
|
1 |
|
" ADD FULLTEXT fulltext_index (\"" . |
28
|
1 |
|
implode('", "', $indexFields) . |
|
|
|
|
29
|
1 |
|
"\")');"; |
30
|
1 |
|
} |
31
|
|
|
|
32
|
|
|
public static function processMigrationFieldDirective( |
33
|
|
|
MigrationGenerator $generator, |
34
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
35
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
36
|
|
|
MigrationCodeFragment $code |
37
|
|
|
): void { |
38
|
|
|
throw new DirectiveException("Directive not supported here"); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public static function processMigrationRelationshipDirective( |
42
|
|
|
MigrationGenerator $generator, |
43
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
44
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
45
|
|
|
MigrationCodeFragment $code |
46
|
|
|
): void { |
47
|
|
|
throw new DirectiveException("Directive not supported here"); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public static function processModelTypeDirective( |
51
|
|
|
ModelGenerator $generator, |
52
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
53
|
|
|
): void { |
54
|
|
|
throw new Exception("Fulltext index model is not implemented yet"); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public static function processModelFieldDirective( |
58
|
|
|
ModelGenerator $generator, |
59
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
60
|
|
|
\Formularium\Field $fieldFormularium, |
61
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
62
|
|
|
): void { |
63
|
|
|
// nothing |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public static function processModelRelationshipDirective( |
67
|
|
|
ModelGenerator $generator, |
68
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
69
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
70
|
|
|
): string { |
71
|
|
|
// nothing |
72
|
|
|
return ''; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|