1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHP Translation package. |
5
|
|
|
* |
6
|
|
|
* (c) PHP Translation team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Translation\Bundle\Model; |
13
|
|
|
|
14
|
|
|
use Translation\Common\Model\Message; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Tobias Nyholm <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
final class SfProfilerMessage |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var int |
23
|
|
|
* |
24
|
|
|
* This is the number of times the message occurs on a specific page |
25
|
|
|
*/ |
26
|
|
|
private $count; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
* |
31
|
|
|
* The domain the message belongs to |
32
|
|
|
*/ |
33
|
|
|
private $domain; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
* |
38
|
|
|
* The key/phrase you write in the source code |
39
|
|
|
*/ |
40
|
|
|
private $key; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
* |
45
|
|
|
* The locale the translations is on |
46
|
|
|
*/ |
47
|
|
|
private $locale; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var int |
51
|
|
|
* |
52
|
|
|
* The current state of the translations. See Symfony\Component\Translation\DataCollectorTranslator |
53
|
|
|
* |
54
|
|
|
* MESSAGE_DEFINED = 0; |
55
|
|
|
* MESSAGE_MISSING = 1; |
56
|
|
|
* MESSAGE_EQUALS_FALLBACK = 2; |
57
|
|
|
*/ |
58
|
|
|
private $state; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var string |
62
|
|
|
* |
63
|
|
|
* The translated string. This is the preview of the message. Ie no placeholders is visible. |
64
|
|
|
*/ |
65
|
|
|
private $translation; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var int |
69
|
|
|
* |
70
|
|
|
* The number which we are feeding a transChoice with |
71
|
|
|
* Used only in Symfony >2.8 |
72
|
|
|
*/ |
73
|
|
|
private $transChoiceNumber; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var array |
77
|
|
|
* |
78
|
|
|
* The parameters sent to the translations |
79
|
|
|
* Used only in Symfony >2.8 |
80
|
|
|
*/ |
81
|
|
|
private $parameters; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param array $data |
85
|
|
|
* |
86
|
|
|
* @return SfProfilerMessage |
87
|
|
|
*/ |
88
|
|
|
public static function create(array $data) |
89
|
|
|
{ |
90
|
|
|
$message = new self(); |
91
|
|
|
if (isset($data['id'])) { |
92
|
|
|
$message->setKey($data['id']); |
93
|
|
|
} |
94
|
|
|
if (isset($data['domain'])) { |
95
|
|
|
$message->setDomain($data['domain']); |
96
|
|
|
} |
97
|
|
|
if (isset($data['locale'])) { |
98
|
|
|
$message->setLocale($data['locale']); |
99
|
|
|
} |
100
|
|
|
if (isset($data['translation'])) { |
101
|
|
|
$message->setTranslation($data['translation']); |
102
|
|
|
} |
103
|
|
|
if (isset($data['state'])) { |
104
|
|
|
$message->setState($data['state']); |
105
|
|
|
} |
106
|
|
|
if (isset($data['count'])) { |
107
|
|
|
$message->setCount($data['count']); |
108
|
|
|
} |
109
|
|
|
if (isset($data['transChoiceNumber'])) { |
110
|
|
|
$message->setTransChoiceNumber($data['transChoiceNumber']); |
111
|
|
|
} |
112
|
|
|
if (isset($data['parameters'])) { |
113
|
|
|
$message->setParameters($data['parameters']); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $message; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Convert to a Common\Message. |
121
|
|
|
* |
122
|
|
|
* @return Message |
123
|
|
|
*/ |
124
|
|
|
public function convertToMessage() |
125
|
|
|
{ |
126
|
|
|
$meta = []; |
127
|
|
|
|
128
|
|
|
if (!empty($this->getParameters())) { |
129
|
|
|
// Reduce to only get one value of each parameter, not all the usages. |
130
|
|
|
$meta['parameters'] = array_reduce($this->getParameters(), 'array_merge', []); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
if (!empty($this->getCount())) { |
134
|
|
|
$meta['count'] = $this->getCount(); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if (!empty($this->getTransChoiceNumber())) { |
138
|
|
|
$meta['transChoiceNumber'] = $this->getTransChoiceNumber(); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
return new Message( |
142
|
|
|
$this->key, |
143
|
|
|
$this->domain, |
144
|
|
|
$this->locale, |
145
|
|
|
$this->translation, |
146
|
|
|
$meta |
147
|
|
|
); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return int |
152
|
|
|
*/ |
153
|
|
|
public function getCount() |
154
|
|
|
{ |
155
|
|
|
return $this->count; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param int $count |
160
|
|
|
* |
161
|
|
|
* @return $this |
162
|
|
|
*/ |
163
|
|
|
public function setCount($count) |
164
|
|
|
{ |
165
|
|
|
$this->count = $count; |
166
|
|
|
|
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return string |
172
|
|
|
*/ |
173
|
|
|
public function getDomain() |
174
|
|
|
{ |
175
|
|
|
return $this->domain; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param string $domain |
180
|
|
|
* |
181
|
|
|
* @return $this |
182
|
|
|
*/ |
183
|
|
|
public function setDomain($domain) |
184
|
|
|
{ |
185
|
|
|
$this->domain = $domain; |
186
|
|
|
|
187
|
|
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return string |
192
|
|
|
*/ |
193
|
|
|
public function getKey() |
194
|
|
|
{ |
195
|
|
|
return $this->key; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param string $key |
200
|
|
|
* |
201
|
|
|
* @return $this |
202
|
|
|
*/ |
203
|
|
|
public function setKey($key) |
204
|
|
|
{ |
205
|
|
|
$this->key = $key; |
206
|
|
|
|
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @return string |
212
|
|
|
*/ |
213
|
|
|
public function getLocale() |
214
|
|
|
{ |
215
|
|
|
return $this->locale; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param string $locale |
220
|
|
|
* |
221
|
|
|
* @return $this |
222
|
|
|
*/ |
223
|
|
|
public function setLocale($locale) |
224
|
|
|
{ |
225
|
|
|
$this->locale = $locale; |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return int |
232
|
|
|
*/ |
233
|
|
|
public function getState() |
234
|
|
|
{ |
235
|
|
|
return $this->state; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param int $state |
240
|
|
|
* |
241
|
|
|
* @return $this |
242
|
|
|
*/ |
243
|
|
|
public function setState($state) |
244
|
|
|
{ |
245
|
|
|
$this->state = $state; |
246
|
|
|
|
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return string |
252
|
|
|
*/ |
253
|
|
|
public function getTranslation() |
254
|
|
|
{ |
255
|
|
|
return $this->translation; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param string $translation |
260
|
|
|
* |
261
|
|
|
* @return $this |
262
|
|
|
*/ |
263
|
|
|
public function setTranslation($translation) |
264
|
|
|
{ |
265
|
|
|
$this->translation = $translation; |
266
|
|
|
|
267
|
|
|
return $this; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @return int |
272
|
|
|
*/ |
273
|
|
|
public function getTransChoiceNumber() |
274
|
|
|
{ |
275
|
|
|
return $this->transChoiceNumber; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @param int $transChoiceNumber |
280
|
|
|
* |
281
|
|
|
* @return $this |
282
|
|
|
*/ |
283
|
|
|
public function setTransChoiceNumber($transChoiceNumber) |
284
|
|
|
{ |
285
|
|
|
$this->transChoiceNumber = $transChoiceNumber; |
286
|
|
|
|
287
|
|
|
return $this; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @return array |
292
|
|
|
*/ |
293
|
|
|
public function getParameters() |
294
|
|
|
{ |
295
|
|
|
return $this->parameters; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @return bool |
300
|
|
|
*/ |
301
|
|
|
public function hasParameters() |
302
|
|
|
{ |
303
|
|
|
return !empty($this->parameters); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @param array $parameters |
308
|
|
|
* |
309
|
|
|
* @return $this |
310
|
|
|
*/ |
311
|
|
|
public function setParameters($parameters) |
312
|
|
|
{ |
313
|
|
|
$this->parameters = $parameters; |
314
|
|
|
|
315
|
|
|
return $this; |
316
|
|
|
} |
317
|
|
|
} |
318
|
|
|
|