1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Akeneo\Crowdin\Api; |
4
|
|
|
|
5
|
|
|
use \InvalidArgumentException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Rename directory or modify its attributes. When renaming directory the path can not be changed (it means new_name |
9
|
|
|
* parameter can not contain path, name only). |
10
|
|
|
* |
11
|
|
|
* @author Pierre Allard <[email protected]> |
12
|
|
|
* @see https://crowdin.com/page/api/change-directory |
13
|
|
|
*/ |
14
|
|
|
class ChangeDirectory extends AbstractApi |
15
|
|
|
{ |
16
|
|
|
/** @var string */ |
17
|
|
|
protected $name; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
protected $newName; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $title; |
24
|
|
|
|
25
|
|
|
/** @var string */ |
26
|
|
|
protected $exportPattern; |
27
|
|
|
|
28
|
|
|
/** @var string */ |
29
|
|
|
protected $branch; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function execute() |
35
|
|
|
{ |
36
|
|
|
if (null == $this->name) { |
37
|
|
|
throw new InvalidArgumentException('Argument name is required.'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$path = sprintf( |
41
|
|
|
"project/%s/change-directory?key=%s", |
42
|
|
|
$this->client->getProjectIdentifier(), |
43
|
|
|
$this->client->getProjectApiKey() |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$data = array_merge($this->parameters, ['name' => $this->name]); |
47
|
|
|
|
48
|
|
|
if (null !== $this->newName) { |
49
|
|
|
$data['new_name'] = $this->newName; |
50
|
|
|
} |
51
|
|
|
if (null !== $this->title) { |
52
|
|
|
$data['title'] = $this->title; |
53
|
|
|
} |
54
|
|
|
if (null !== $this->exportPattern) { |
55
|
|
|
$data['export_pattern'] = $this->exportPattern; |
56
|
|
|
} |
57
|
|
|
if (null !== $this->branch) { |
58
|
|
|
$data['branch'] = $this->branch; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$request = $this->client->getHttpClient()->post($path, [], $data); |
62
|
|
|
$response = $request->send(); |
63
|
|
|
|
64
|
|
|
return $response->getBody(true); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $branch |
69
|
|
|
* |
70
|
|
|
* @return ChangeDirectory |
71
|
|
|
*/ |
72
|
|
|
public function setBranch($branch) |
73
|
|
|
{ |
74
|
|
|
$this->branch = $branch; |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Set new directory export pattern. Is used to create directory name and path in resulted translations bundle. |
81
|
|
|
* |
82
|
|
|
* @param string $exportPattern |
83
|
|
|
* |
84
|
|
|
* @return ChangeDirectory |
85
|
|
|
*/ |
86
|
|
|
public function setExportPattern($exportPattern) |
87
|
|
|
{ |
88
|
|
|
$this->exportPattern = $exportPattern; |
89
|
|
|
|
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Set new directory title to be displayed in Crowdin UI. |
95
|
|
|
* |
96
|
|
|
* @param string $title |
97
|
|
|
* |
98
|
|
|
* @return ChangeDirectory |
99
|
|
|
*/ |
100
|
|
|
public function setTitle($title) |
101
|
|
|
{ |
102
|
|
|
$this->title = $title; |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Set new directory name. |
109
|
|
|
* |
110
|
|
|
* @param string $newName |
111
|
|
|
* |
112
|
|
|
* @return ChangeDirectory |
113
|
|
|
*/ |
114
|
|
|
public function setNewName($newName) |
115
|
|
|
{ |
116
|
|
|
$this->newName = $newName; |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Set full directory path that should be modified (e.g. /MainPage/AboutUs). |
123
|
|
|
* |
124
|
|
|
* @param string $name |
125
|
|
|
* |
126
|
|
|
* @return ChangeDirectory |
127
|
|
|
*/ |
128
|
|
|
public function setName($name) |
129
|
|
|
{ |
130
|
|
|
$this->name = $name; |
131
|
|
|
|
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|