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
|
|
|
$this->addUrlParameter('key', $this->client->getProjectApiKey()); |
41
|
|
|
|
42
|
|
|
$path = sprintf( |
43
|
|
|
"project/%s/change-directory?%s", |
44
|
|
|
$this->client->getProjectIdentifier(), |
45
|
|
|
$this->getUrlQueryString() |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$data = ['name' => $this->name]; |
49
|
|
|
|
50
|
|
|
if (null !== $this->newName) { |
51
|
|
|
$data['new_name'] = $this->newName; |
52
|
|
|
} |
53
|
|
|
if (null !== $this->title) { |
54
|
|
|
$data['title'] = $this->title; |
55
|
|
|
} |
56
|
|
|
if (null !== $this->exportPattern) { |
57
|
|
|
$data['export_pattern'] = $this->exportPattern; |
58
|
|
|
} |
59
|
|
|
if (null !== $this->branch) { |
60
|
|
|
$data['branch'] = $this->branch; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$data = ['form_params' => $data]; |
64
|
|
|
$response = $this->client->getHttpClient()->post($path, $data); |
65
|
|
|
|
66
|
|
|
return $response->getBody(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $branch |
71
|
|
|
* |
72
|
|
|
* @return ChangeDirectory |
73
|
|
|
*/ |
74
|
|
|
public function setBranch($branch) |
75
|
|
|
{ |
76
|
|
|
$this->branch = $branch; |
77
|
|
|
|
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Set new directory export pattern. Is used to create directory name and path in resulted translations bundle. |
83
|
|
|
* |
84
|
|
|
* @param string $exportPattern |
85
|
|
|
* |
86
|
|
|
* @return ChangeDirectory |
87
|
|
|
*/ |
88
|
|
|
public function setExportPattern($exportPattern) |
89
|
|
|
{ |
90
|
|
|
$this->exportPattern = $exportPattern; |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Set new directory title to be displayed in Crowdin UI. |
97
|
|
|
* |
98
|
|
|
* @param string $title |
99
|
|
|
* |
100
|
|
|
* @return ChangeDirectory |
101
|
|
|
*/ |
102
|
|
|
public function setTitle($title) |
103
|
|
|
{ |
104
|
|
|
$this->title = $title; |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Set new directory name. |
111
|
|
|
* |
112
|
|
|
* @param string $newName |
113
|
|
|
* |
114
|
|
|
* @return ChangeDirectory |
115
|
|
|
*/ |
116
|
|
|
public function setNewName($newName) |
117
|
|
|
{ |
118
|
|
|
$this->newName = $newName; |
119
|
|
|
|
120
|
|
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Set full directory path that should be modified (e.g. /MainPage/AboutUs). |
125
|
|
|
* |
126
|
|
|
* @param string $name |
127
|
|
|
* |
128
|
|
|
* @return ChangeDirectory |
129
|
|
|
*/ |
130
|
|
|
public function setName($name) |
131
|
|
|
{ |
132
|
|
|
$this->name = $name; |
133
|
|
|
|
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|