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
|
|
|
* |
14
|
|
|
* @throws ArangoException |
15
|
|
|
*/ |
16
|
|
|
public function createAnalyzer(string $name, array $properties) |
17
|
|
|
{ |
18
|
|
|
$analyzer = $properties; |
19
|
|
|
$analyzer['name'] = $name; |
20
|
|
|
|
21
|
|
|
$this->schemaManager->createAnalyzer($analyzer); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param array<mixed> $properties |
26
|
|
|
* |
27
|
|
|
* @throws ArangoException |
28
|
|
|
*/ |
29
|
|
|
public function replaceAnalyzer(string $name, array $properties) |
30
|
|
|
{ |
31
|
|
|
$this->schemaManager->replaceAnalyzer($name, $properties); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @throws ArangoException |
36
|
|
|
*/ |
37
|
|
|
public function getAnalyzer(string $name): \stdClass |
38
|
|
|
{ |
39
|
|
|
return $this->schemaManager->getAnalyzer($name); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function hasAnalyzer(string $analyzer): bool |
43
|
|
|
{ |
44
|
|
|
return $this->handleExceptionsAsQueryExceptions(function () use ($analyzer) { |
|
|
|
|
45
|
|
|
return $this->schemaManager->hasAnalyzer($analyzer); |
46
|
|
|
}); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @throws ArangoException |
51
|
|
|
*/ |
52
|
|
|
public function getAllAnalyzers(): array |
53
|
|
|
{ |
54
|
|
|
return $this->schemaManager->getAnalyzers(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @throws ArangoException |
59
|
|
|
*/ |
60
|
|
|
public function dropAnalyzer(string $name) |
61
|
|
|
{ |
62
|
|
|
$this->schemaManager->deleteAnalyzer($name); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @throws ArangoException |
67
|
|
|
*/ |
68
|
|
|
public function dropAnalyzerIfExists(string $name): bool |
69
|
|
|
{ |
70
|
|
|
if ($this->hasAnalyzer($name)) { |
71
|
|
|
$this->schemaManager->deleteAnalyzer($name); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
} |