1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Schema\Concerns; |
6
|
|
|
|
7
|
|
|
use ArangoClient\Exceptions\ArangoException; |
8
|
|
|
|
9
|
|
|
trait HandlesAnalyzers |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param array<mixed> $properties |
13
|
|
|
* @param array<string> $features |
14
|
|
|
* |
15
|
|
|
* @throws ArangoException |
16
|
|
|
*/ |
17
|
13 |
|
public function createAnalyzer(string $name, string $type, array $properties = null, array $features = null) |
18
|
|
|
{ |
19
|
13 |
|
$analyzer = array_filter([ |
20
|
13 |
|
'name' => $name, |
21
|
13 |
|
'type' => $type, |
22
|
13 |
|
'properties' => $properties, |
23
|
13 |
|
'features' => $features, |
24
|
13 |
|
]); |
25
|
|
|
|
26
|
13 |
|
$this->schemaManager->createAnalyzer($analyzer); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param array<mixed> $properties |
31
|
|
|
* @param array<string> $features |
32
|
|
|
* |
33
|
|
|
* @throws ArangoException |
34
|
|
|
*/ |
35
|
2 |
|
public function replaceAnalyzer(string $name, string $type, array $properties = null, array $features = null) |
36
|
|
|
{ |
37
|
2 |
|
$analyzer = array_filter([ |
38
|
2 |
|
'name' => $name, |
39
|
2 |
|
'type' => $type, |
40
|
2 |
|
'properties' => $properties, |
41
|
2 |
|
'features' => $features, |
42
|
2 |
|
]); |
43
|
|
|
|
44
|
2 |
|
$this->schemaManager->replaceAnalyzer($name, $analyzer); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @throws ArangoException |
49
|
|
|
*/ |
50
|
|
|
public function getAnalyzer(string $name): \stdClass |
51
|
|
|
{ |
52
|
|
|
return $this->schemaManager->getAnalyzer($name); |
53
|
|
|
} |
54
|
|
|
|
55
|
4 |
|
public function hasAnalyzer(string $analyzer): bool |
56
|
|
|
{ |
57
|
4 |
|
return $this->handleExceptionsAsQueryExceptions(function () use ($analyzer) { |
|
|
|
|
58
|
4 |
|
return $this->schemaManager->hasAnalyzer($analyzer); |
59
|
4 |
|
}); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @throws ArangoException |
64
|
|
|
*/ |
65
|
9 |
|
public function getAnalyzers(): array |
66
|
|
|
{ |
67
|
9 |
|
return $this->schemaManager->getAnalyzers(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @throws ArangoException |
72
|
|
|
*/ |
73
|
2 |
|
public function dropAnalyzer(string $name) |
74
|
|
|
{ |
75
|
2 |
|
$this->schemaManager->deleteAnalyzer($name); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @throws ArangoException |
80
|
|
|
*/ |
81
|
4 |
|
public function dropAnalyzerIfExists(string $name): bool |
82
|
|
|
{ |
83
|
4 |
|
if ($this->hasAnalyzer($name)) { |
84
|
2 |
|
$this->schemaManager->deleteAnalyzer($name); |
85
|
|
|
} |
86
|
|
|
|
87
|
4 |
|
return true; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Drop all custom analyzers from the schema. |
92
|
|
|
* |
93
|
|
|
* @throws ArangoException |
94
|
|
|
*/ |
95
|
35 |
|
public function dropAllAnalyzers(): void |
96
|
|
|
{ |
97
|
35 |
|
$this->schemaManager->deleteAllAnalyzers(); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|