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
|
|
|
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
|
|
|
return new Message( |
127
|
|
|
$this->key, |
128
|
|
|
$this->domain, |
129
|
|
|
$this->locale, |
130
|
|
|
$this->translation |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return int |
136
|
|
|
*/ |
137
|
|
|
public function getCount() |
138
|
|
|
{ |
139
|
|
|
return $this->count; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param int $count |
144
|
|
|
* |
145
|
|
|
* @return $this |
146
|
|
|
*/ |
147
|
|
|
public function setCount($count) |
148
|
|
|
{ |
149
|
|
|
$this->count = $count; |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
|
|
public function getDomain() |
158
|
|
|
{ |
159
|
|
|
return $this->domain; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param string $domain |
164
|
|
|
* |
165
|
|
|
* @return $this |
166
|
|
|
*/ |
167
|
|
|
public function setDomain($domain) |
168
|
|
|
{ |
169
|
|
|
$this->domain = $domain; |
170
|
|
|
|
171
|
|
|
return $this; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return string |
176
|
|
|
*/ |
177
|
|
|
public function getKey() |
178
|
|
|
{ |
179
|
|
|
return $this->key; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param string $key |
184
|
|
|
* |
185
|
|
|
* @return $this |
186
|
|
|
*/ |
187
|
|
|
public function setKey($key) |
188
|
|
|
{ |
189
|
|
|
$this->key = $key; |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @return string |
196
|
|
|
*/ |
197
|
|
|
public function getLocale() |
198
|
|
|
{ |
199
|
|
|
return $this->locale; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param string $locale |
204
|
|
|
* |
205
|
|
|
* @return $this |
206
|
|
|
*/ |
207
|
|
|
public function setLocale($locale) |
208
|
|
|
{ |
209
|
|
|
$this->locale = $locale; |
210
|
|
|
|
211
|
|
|
return $this; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return int |
216
|
|
|
*/ |
217
|
|
|
public function getState() |
218
|
|
|
{ |
219
|
|
|
return $this->state; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @param int $state |
224
|
|
|
* |
225
|
|
|
* @return $this |
226
|
|
|
*/ |
227
|
|
|
public function setState($state) |
228
|
|
|
{ |
229
|
|
|
$this->state = $state; |
230
|
|
|
|
231
|
|
|
return $this; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @return string |
236
|
|
|
*/ |
237
|
|
|
public function getTranslation() |
238
|
|
|
{ |
239
|
|
|
return $this->translation; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @param string $translation |
244
|
|
|
* |
245
|
|
|
* @return $this |
246
|
|
|
*/ |
247
|
|
|
public function setTranslation($translation) |
248
|
|
|
{ |
249
|
|
|
$this->translation = $translation; |
250
|
|
|
|
251
|
|
|
return $this; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @return int |
256
|
|
|
*/ |
257
|
|
|
public function getTransChoiceNumber() |
258
|
|
|
{ |
259
|
|
|
return $this->transChoiceNumber; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @param int $transChoiceNumber |
264
|
|
|
* |
265
|
|
|
* @return $this |
266
|
|
|
*/ |
267
|
|
|
public function setTransChoiceNumber($transChoiceNumber) |
268
|
|
|
{ |
269
|
|
|
$this->transChoiceNumber = $transChoiceNumber; |
270
|
|
|
|
271
|
|
|
return $this; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @return array |
276
|
|
|
*/ |
277
|
|
|
public function getParameters() |
278
|
|
|
{ |
279
|
|
|
return $this->parameters; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @return bool |
284
|
|
|
*/ |
285
|
|
|
public function hasParameters() |
286
|
|
|
{ |
287
|
|
|
return !empty($this->parameters); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @param array $parameters |
292
|
|
|
* |
293
|
|
|
* @return $this |
294
|
|
|
*/ |
295
|
|
|
public function setParameters($parameters) |
296
|
|
|
{ |
297
|
|
|
$this->parameters = $parameters; |
298
|
|
|
|
299
|
|
|
return $this; |
300
|
|
|
} |
301
|
|
|
} |
302
|
|
|
|