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 http://crowdin.net/page/api/download |
10
|
|
|
*/ |
11
|
|
|
class Download extends AbstractApi |
12
|
|
|
{ |
13
|
|
|
/** @var string $package */ |
14
|
|
|
protected $package = 'all.zip'; |
15
|
|
|
|
16
|
|
|
/** @var string $copyDestination */ |
17
|
|
|
protected $copyDestination = '/tmp'; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
protected $branch; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return mixed |
24
|
|
|
*/ |
25
|
|
|
public function execute() |
26
|
|
|
{ |
27
|
|
|
$path = sprintf( |
28
|
|
|
"project/%s/download/%s?key=%s", |
29
|
|
|
$this->client->getProjectIdentifier(), |
30
|
|
|
$this->getPackage(), |
31
|
|
|
$this->client->getProjectApiKey() |
32
|
|
|
); |
33
|
|
|
if (null !== $this->branch) { |
34
|
|
|
$path = sprintf('%s&branch=%s', $path, $this->branch); |
35
|
|
|
} |
36
|
|
|
$request = $this->client->getHttpClient()->get($path); |
37
|
|
|
$response = $request |
38
|
|
|
->setResponseBody($this->copyDestination.DIRECTORY_SEPARATOR.$this->getPackage()) |
39
|
|
|
->send(); |
40
|
|
|
|
41
|
|
|
return $response->getBody(true); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $package |
46
|
|
|
* |
47
|
|
|
* @return Download |
48
|
|
|
*/ |
49
|
|
|
public function setPackage($package) |
50
|
|
|
{ |
51
|
|
|
$this->package = $package; |
52
|
|
|
|
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
public function getPackage() |
60
|
|
|
{ |
61
|
|
|
return $this->package; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $dest |
66
|
|
|
* |
67
|
|
|
* @return Download |
68
|
|
|
*/ |
69
|
|
|
public function setCopyDestination($dest) |
70
|
|
|
{ |
71
|
|
|
$this->copyDestination = $dest; |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getCopyDestination() |
80
|
|
|
{ |
81
|
|
|
return $this->copyDestination; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getBranch() |
88
|
|
|
{ |
89
|
|
|
return $this->branch; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $branch |
94
|
|
|
*/ |
95
|
|
|
public function setBranch($branch) |
96
|
|
|
{ |
97
|
|
|
$this->branch = $branch; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|