-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAliasActions.php
More file actions
78 lines (68 loc) · 1.63 KB
/
Copy pathAliasActions.php
File metadata and controls
78 lines (68 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace DirectoryTree\OpenSearchAdapter\Indices;
/**
* Builds an atomic OpenSearch alias update payload.
*
* @see https://docs.opensearch.org/latest/api-reference/alias/aliases-api/
*/
class AliasActions
{
/**
* The alias actions.
*
* @var array<int, array<string, array<string, mixed>>>
*/
protected array $actions = [];
/**
* Add an alias to an index.
*/
public function add(string $index, Alias $alias): static
{
$this->actions[] = [
'add' => [
'index' => $index,
'alias' => $alias->name(),
...$alias->toArray(),
],
];
return $this;
}
/**
* Remove an alias from an index.
*/
public function remove(string $index, string $alias): static
{
$this->actions[] = [
'remove' => compact('index', 'alias'),
];
return $this;
}
/**
* Remove an index as part of the atomic alias update.
*/
public function removeIndex(string $index): static
{
$this->actions[] = [
'remove_index' => compact('index'),
];
return $this;
}
/**
* Get the configured alias actions.
*
* @return array<int, array<string, array<string, mixed>>>
*/
public function actions(): array
{
return $this->actions;
}
/**
* Get the OpenSearch update aliases body payload.
*
* @return array{actions: array<int, array<string, array<string, mixed>>>}
*/
public function toArray(): array
{
return ['actions' => $this->actions];
}
}