1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Akeneo\Crowdin\Api; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Download ZIP file with translations (all or chosen language) |
7
|
|
|
* |
8
|
|
|
* @author Nicolas Dupont <[email protected]> |
9
|
|
|
* @see https://crowdin.com/page/api/download |
10
|
|
|
*/ |
11
|
|
|
class Download extends AbstractApi |
12
|
|
|
{ |
13
|
|
|
/** @var string */ |
14
|
|
|
protected $package = 'all.zip'; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
protected $copyDestination = '/tmp'; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
protected $branch; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
public function execute() |
26
|
|
|
{ |
27
|
|
|
$this->addUrlParameter('key', $this->client->getProjectApiKey()); |
28
|
|
|
|
29
|
|
|
$path = sprintf( |
30
|
|
|
"project/%s/download/%s?%s", |
31
|
|
|
$this->client->getProjectIdentifier(), |
32
|
|
|
$this->package, |
33
|
|
|
$this->getUrlQueryString() |
34
|
|
|
); |
35
|
|
|
if (null !== $this->branch) { |
36
|
|
|
$path = sprintf('%s&branch=%s', $path, $this->branch); |
37
|
|
|
} |
38
|
|
|
$response = $this->client->getHttpClient()->get($path, |
39
|
|
|
[ |
40
|
|
|
'sink' => $this->getCopyDestination() . '/' . $this->getPackage() |
41
|
|
|
] |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
return $response->getBody(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $package |
49
|
|
|
* |
50
|
|
|
* @return Download |
51
|
|
|
*/ |
52
|
|
|
public function setPackage($package) |
53
|
|
|
{ |
54
|
|
|
$this->package = $package; |
55
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
public function getPackage() |
63
|
|
|
{ |
64
|
|
|
return $this->package; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $dest |
69
|
|
|
* |
70
|
|
|
* @return Download |
71
|
|
|
*/ |
72
|
|
|
public function setCopyDestination($dest) |
73
|
|
|
{ |
74
|
|
|
$this->copyDestination = $dest; |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getCopyDestination() |
83
|
|
|
{ |
84
|
|
|
return $this->copyDestination; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function getBranch() |
91
|
|
|
{ |
92
|
|
|
return $this->branch; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $branch |
97
|
|
|
* |
98
|
|
|
* @return Download |
99
|
|
|
*/ |
100
|
|
|
public function setBranch($branch) |
101
|
|
|
{ |
102
|
|
|
$this->branch = $branch; |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|