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\Common\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A object representation of a translation in a specific language. |
16
|
|
|
* |
17
|
|
|
* @author Tobias Nyholm <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Message |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
* |
24
|
|
|
* The domain the message belongs to |
25
|
|
|
*/ |
26
|
|
|
private $domain; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
* |
31
|
|
|
* The key/phrase you write in the source code |
32
|
|
|
*/ |
33
|
|
|
private $key; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
* |
38
|
|
|
* The locale the translations is on |
39
|
|
|
*/ |
40
|
|
|
private $locale; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
* |
45
|
|
|
* The translated string. This is the preview of the message. Ie no placeholders is visible. |
46
|
|
|
*/ |
47
|
|
|
private $translation; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Key value array with metadata. |
51
|
|
|
* |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
private $meta = []; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $key |
58
|
|
|
* @param string $domain |
59
|
|
|
* @param string $locale |
60
|
|
|
* @param string $translation |
61
|
|
|
* @param array $meta |
62
|
|
|
*/ |
63
|
|
|
public function __construct($key = '', $domain = '', $locale = '', $translation = '', array $meta = []) |
64
|
|
|
{ |
65
|
|
|
$this->key = $key; |
66
|
|
|
$this->domain = $domain; |
67
|
|
|
$this->locale = $locale; |
68
|
|
|
$this->translation = $translation; |
69
|
|
|
$this->meta = $meta; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function getDomain() |
76
|
|
|
{ |
77
|
|
|
return $this->domain; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param string $domain |
82
|
|
|
* |
83
|
|
|
* @return Message |
84
|
|
|
*/ |
85
|
|
|
public function setDomain($domain) |
86
|
|
|
{ |
87
|
|
|
$this->domain = $domain; |
88
|
|
|
|
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getKey() |
96
|
|
|
{ |
97
|
|
|
return $this->key; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $key |
102
|
|
|
* |
103
|
|
|
* @return Message |
104
|
|
|
*/ |
105
|
|
|
public function setKey($key) |
106
|
|
|
{ |
107
|
|
|
$this->key = $key; |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
|
|
public function getLocale() |
116
|
|
|
{ |
117
|
|
|
return $this->locale; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param string $locale |
122
|
|
|
* |
123
|
|
|
* @return Message |
124
|
|
|
*/ |
125
|
|
|
public function setLocale($locale) |
126
|
|
|
{ |
127
|
|
|
$this->locale = $locale; |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function getTranslation() |
136
|
|
|
{ |
137
|
|
|
return $this->translation; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param string $translation |
142
|
|
|
* |
143
|
|
|
* @return Message |
144
|
|
|
*/ |
145
|
|
|
public function setTranslation($translation) |
146
|
|
|
{ |
147
|
|
|
$this->translation = $translation; |
148
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return array |
154
|
|
|
*/ |
155
|
|
|
public function getAllMeta() |
156
|
|
|
{ |
157
|
|
|
return $this->meta; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param array $meta |
162
|
|
|
* |
163
|
|
|
* @return Message |
164
|
|
|
*/ |
165
|
|
|
public function setMeta(array $meta) |
166
|
|
|
{ |
167
|
|
|
$this->meta = $meta; |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param array $meta |
|
|
|
|
174
|
|
|
* |
175
|
|
|
* @return Message |
176
|
|
|
*/ |
177
|
|
|
public function addMeta($key, $value) |
178
|
|
|
{ |
179
|
|
|
$this->meta[$key] = $value; |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param string $key |
186
|
|
|
* |
187
|
|
|
* @return mixed|null |
188
|
|
|
*/ |
189
|
|
|
public function getMeta($key) |
190
|
|
|
{ |
191
|
|
|
if (isset($this->meta[$key])) { |
192
|
|
|
return $this->meta[$key]; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.