|
1
|
|
|
<?php // Copyright ⓒ 2018 Magneds IP B.V. - All Rights Reserved |
|
2
|
|
|
namespace Magneds\Lokalise\Language\Request; |
|
3
|
|
|
|
|
4
|
|
|
use Magneds\Lokalise\Language\Entity\Language; |
|
5
|
|
|
use Magneds\Lokalise\Project\Entity\ProjectID; |
|
6
|
|
|
use Magneds\Lokalise\RequestInterface; |
|
7
|
|
|
use Magneds\Lokalise\ResponseInfo; |
|
8
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
9
|
|
|
use function json_decode; |
|
10
|
|
|
|
|
11
|
|
|
class AddLanguageRequest implements RequestInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var ProjectID |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $projectID; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var Language[] |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $languages; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* AddLanguageRequest constructor. |
|
25
|
|
|
* @param ProjectID $projectID |
|
26
|
|
|
* @param Language[] $languages |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(ProjectID $projectID, array $languages) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->projectID = $projectID; |
|
31
|
|
|
$this->languages = $languages; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Return the method to make this request in. |
|
36
|
|
|
* |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getMethod() |
|
40
|
|
|
{ |
|
41
|
|
|
return 'POST'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* This URI is appended to the route URL given to the Client object. |
|
46
|
|
|
* |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getURI() |
|
50
|
|
|
{ |
|
51
|
|
|
return 'language/add'; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getQueryArguments() |
|
58
|
|
|
{ |
|
59
|
|
|
return []; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getBody() |
|
66
|
|
|
{ |
|
67
|
|
|
$languages = []; |
|
68
|
|
|
|
|
69
|
|
|
foreach ($this->languages as $language) { |
|
70
|
|
|
$languages[] = $language->getIso(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return [ |
|
74
|
|
|
'id' => $this->projectID->getID(), |
|
75
|
|
|
'iso' => json_encode($languages), |
|
76
|
|
|
]; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param ResponseInterface $response |
|
81
|
|
|
* @return mixed |
|
82
|
|
|
*/ |
|
83
|
|
|
public function handleResponse(ResponseInterface $response): ResponseInfo |
|
84
|
|
|
{ |
|
85
|
|
|
$responseData = json_decode($response->getBody()->getContents(), true); |
|
86
|
|
|
return ResponseInfo::buildFromArray($responseData['response']); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|