|
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
|
|
|
|
|
13
|
|
|
class MigrationFulltextIndexDirective implements MigrationDirectiveInterface, ModelDirectiveInterface |
|
14
|
1 |
|
{ |
|
15
|
|
|
public static function processMigrationTypeDirective( |
|
16
|
|
|
MigrationGenerator $generator, |
|
17
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
|
18
|
|
|
): void { |
|
19
|
1 |
|
/** @phpstan-ignore-next-line */ |
|
20
|
|
|
$values = $directive->arguments[0]->value->values; |
|
|
|
|
|
|
21
|
1 |
|
|
|
22
|
1 |
|
$indexFields = []; |
|
23
|
1 |
|
foreach ($values as $value) { |
|
24
|
|
|
$indexFields[] = $value->value; |
|
25
|
|
|
} |
|
26
|
1 |
|
|
|
27
|
|
|
if (!count($indexFields)) { |
|
28
|
|
|
throw new Exception("You must provide at least one field to a full text index"); |
|
29
|
1 |
|
} |
|
30
|
1 |
|
$generator->postCreateCode[] = "DB::statement('ALTER TABLE " . |
|
31
|
1 |
|
$generator->getLowerNamePlural() . |
|
32
|
1 |
|
" ADD FULLTEXT fulltext_index (\"" . |
|
33
|
1 |
|
implode('", "', $indexFields) . |
|
34
|
1 |
|
"\")');"; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public static function processMigrationFieldDirective( |
|
38
|
|
|
MigrationGenerator $generator, |
|
39
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
|
40
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
|
41
|
|
|
MigrationCodeFragment $code |
|
42
|
|
|
): void { |
|
43
|
|
|
throw new DirectiveException("Directive not supported here"); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function processMigrationRelationshipDirective( |
|
47
|
|
|
MigrationGenerator $generator, |
|
48
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
|
49
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive, |
|
50
|
|
|
MigrationCodeFragment $code |
|
51
|
|
|
): void { |
|
52
|
|
|
throw new DirectiveException("Directive not supported here"); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public static function processModelTypeDirective( |
|
56
|
|
|
ModelGenerator $generator, |
|
57
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
|
58
|
|
|
): void { |
|
59
|
|
|
throw new Exception("Fulltext index model is not implemented yet"); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public static function processModelFieldDirective( |
|
63
|
|
|
ModelGenerator $generator, |
|
64
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
|
65
|
|
|
\Formularium\Field $fieldFormularium, |
|
66
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
|
67
|
|
|
): void { |
|
68
|
|
|
// nothing |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public static function processModelRelationshipDirective( |
|
72
|
|
|
ModelGenerator $generator, |
|
73
|
|
|
\GraphQL\Type\Definition\FieldDefinition $field, |
|
74
|
|
|
\GraphQL\Language\AST\DirectiveNode $directive |
|
75
|
|
|
): string { |
|
76
|
|
|
// nothing |
|
77
|
|
|
return ''; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|