-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtsEndpoint.php
More file actions
97 lines (87 loc) · 3.18 KB
/
Copy pathAtsEndpoint.php
File metadata and controls
97 lines (87 loc) · 3.18 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
declare(strict_types=1);
namespace Ashampoo\AtsClient\Enums;
use Ashampoo\AtsClient\QueryParam;
enum AtsEndpoint: string
{
// ProjectEndpoints
case Translations = '/api/project/{projectId}/translations';
case LangInfo = '/api/project/{projectId}/language/info';
case TranslationsAll = '/api/project/{projectId}/translations/all';
case TranslationImport = '/api/project/{projectId}/import';
// MachineTranslationEndpoints
case MachineTranslation = '/api/machinetranslations/{projectId}/generate';
case MachineTranslationAll = '/api/machinetranslations/{projectId}/generate/all';
// TranslationMemoryEndpoints
case MemoryTranslation = '/api/translationmemory/{projectId}/generate';
case MemoryTranslationAll = '/api/translationmemory/{projectId}/generate/all';
public function method(): string
{
return match ($this) {
self::TranslationImport,
self::MachineTranslation,
self::MachineTranslationAll,
self::MemoryTranslation,
self::MemoryTranslationAll => 'POST',
default => 'GET',
};
}
public function requiresBody(): bool
{
return match ($this) {
self::TranslationImport => true,
default => false,
};
}
/**
* Substitute `{placeholder}` tokens in the endpoint path with the given values.
*
* Keys without a matching placeholder are ignored; placeholders without
* a provided value are left intact in the returned path.
*
* @param array<string, scalar> $params
*/
public function resolve(array $params = []): string
{
return \preg_replace_callback(
'/\{(\w+)\}/',
fn (array $matches): string => (string) ($params[$matches[1]] ?? $matches[0]),
$this->value,
) ?? $this->value;
}
/** @return QueryParam[] */
public function queryParams(): array
{
return match ($this) {
self::Translations => [
new QueryParam('language', required: true),
new QueryParam('filter'),
new QueryParam('formatId'),
new QueryParam('contextSplitting'),
],
self::TranslationsAll => [
new QueryParam('filter'),
new QueryParam('formatId'),
new QueryParam('contextSplitting'),
],
self::LangInfo => [
new QueryParam('language', required: true),
],
self::MachineTranslation,
self::MachineTranslationAll,
self::MemoryTranslation,
self::MemoryTranslationAll => [
new QueryParam('language'),
],
self::TranslationImport => [
new QueryParam('language', required: true),
new QueryParam('sourceLanguage'),
new QueryParam('importIds', required: true),
new QueryParam('importTranslations', required: true),
new QueryParam('overWriteTranslations', required: true),
new QueryParam('formatId'),
new QueryParam('removeNotFoundIds'),
],
};
}
}