Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
96.30% |
26 / 27 |
|
90.00% |
9 / 10 |
CRAP | |
0.00% |
0 / 1 |
Language | |
96.30% |
26 / 27 |
|
90.00% |
9 / 10 |
20 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
setLatin | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getLatin | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setLangId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getLangId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setEastAsia | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getEastAsia | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setBidirectional | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getBidirectional | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
validateLocale | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
8.09 |
1 | <?php |
2 | |
3 | /** |
4 | * This file is part of PHPWord - A pure PHP library for reading and writing |
5 | * word processing documents. |
6 | * |
7 | * PHPWord is free software distributed under the terms of the GNU Lesser |
8 | * General Public License version 3 as published by the Free Software Foundation. |
9 | * |
10 | * For the full copyright and license information, please read the LICENSE |
11 | * file that was distributed with this source code. For the full list of |
12 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
13 | * |
14 | * @see https://github.com/PHPOffice/PHPWord |
15 | * |
16 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
17 | */ |
18 | |
19 | namespace PhpOffice\PhpWord\Style; |
20 | |
21 | use InvalidArgumentException; |
22 | |
23 | /** |
24 | * Language |
25 | * A couple of predefined values are defined here, see the websites below for more values. |
26 | * |
27 | * @see http://www.datypic.com/sc/ooxml/t-w_CT_Language.html |
28 | * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx |
29 | */ |
30 | final class Language extends AbstractStyle |
31 | { |
32 | const EN_US = 'en-US'; |
33 | const EN_US_ID = 1033; |
34 | |
35 | const EN_GB = 'en-GB'; |
36 | const EN_GB_ID = 2057; |
37 | |
38 | const FR_FR = 'fr-FR'; |
39 | const FR_FR_ID = 1036; |
40 | |
41 | const FR_BE = 'fr-BE'; |
42 | const FR_BE_ID = 2060; |
43 | |
44 | const FR_CH = 'fr-CH'; |
45 | const FR_CH_ID = 4108; |
46 | |
47 | const ES_ES = 'es-ES'; |
48 | const ES_ES_ID = 3082; |
49 | |
50 | const DE_DE = 'de-DE'; |
51 | const DE_DE_ID = 1031; |
52 | |
53 | const DE_CH = 'de-CH'; |
54 | const DE_CH_ID = 2055; |
55 | |
56 | const HE_IL = 'he-IL'; |
57 | const HE_IL_ID = 1037; |
58 | |
59 | const IT_IT = 'it-IT'; |
60 | const IT_IT_ID = 1040; |
61 | |
62 | const IT_CH = 'it-CH'; |
63 | const IT_CH_ID = 2064; |
64 | |
65 | const JA_JP = 'ja-JP'; |
66 | const JA_JP_ID = 1041; |
67 | |
68 | const KO_KR = 'ko-KR'; |
69 | const KO_KR_ID = 1042; |
70 | |
71 | const ZH_CN = 'zh-CN'; |
72 | const ZH_CN_ID = 2052; |
73 | |
74 | const HI_IN = 'hi-IN'; |
75 | const HI_IN_ID = 1081; |
76 | |
77 | const PT_BR = 'pt-BR'; |
78 | const PT_BR_ID = 1046; |
79 | |
80 | const NL_NL = 'nl-NL'; |
81 | const NL_NL_ID = 1043; |
82 | |
83 | const SV_SE = 'sv-SE'; |
84 | const SV_SE_ID = 1053; |
85 | |
86 | const UK_UA = 'uk-UA'; |
87 | const UK_UA_ID = 1058; |
88 | |
89 | const RU_RU = 'ru-RU'; |
90 | const RU_RU_ID = 1049; |
91 | |
92 | /** |
93 | * Language ID, used for RTF document generation. |
94 | * |
95 | * @var int |
96 | * |
97 | * @see https://technet.microsoft.com/en-us/library/cc179219.aspx |
98 | */ |
99 | private $langId; |
100 | |
101 | /** |
102 | * Latin Language. |
103 | * |
104 | * @var string |
105 | */ |
106 | private $latin; |
107 | |
108 | /** |
109 | * East Asian Language. |
110 | * |
111 | * @var string |
112 | */ |
113 | private $eastAsia; |
114 | |
115 | /** |
116 | * Complex Script Language. |
117 | * |
118 | * @var string |
119 | */ |
120 | private $bidirectional; |
121 | |
122 | /** |
123 | * Constructor. |
124 | * |
125 | * @param null|string $latin |
126 | * @param null|string $eastAsia |
127 | * @param null|string $bidirectional |
128 | */ |
129 | public function __construct($latin = null, $eastAsia = null, $bidirectional = null) |
130 | { |
131 | if (!empty($latin)) { |
132 | $this->setLatin($latin); |
133 | } |
134 | if (!empty($eastAsia)) { |
135 | $this->setEastAsia($eastAsia); |
136 | } |
137 | if (!empty($bidirectional)) { |
138 | $this->setBidirectional($bidirectional); |
139 | } |
140 | } |
141 | |
142 | /** |
143 | * Set the Latin Language. |
144 | * |
145 | * @param string $latin |
146 | * The value for the latin language |
147 | * |
148 | * @return self |
149 | */ |
150 | public function setLatin($latin) |
151 | { |
152 | $this->latin = $this->validateLocale($latin); |
153 | |
154 | return $this; |
155 | } |
156 | |
157 | /** |
158 | * Get the Latin Language. |
159 | * |
160 | * @return null|string |
161 | */ |
162 | public function getLatin() |
163 | { |
164 | return $this->latin; |
165 | } |
166 | |
167 | /** |
168 | * Set the Language ID. |
169 | * |
170 | * @param int $langId |
171 | * The value for the language ID |
172 | * |
173 | * @return self |
174 | * |
175 | * @see https://technet.microsoft.com/en-us/library/cc287874(v=office.12).aspx |
176 | */ |
177 | public function setLangId($langId) |
178 | { |
179 | $this->langId = $langId; |
180 | |
181 | return $this; |
182 | } |
183 | |
184 | /** |
185 | * Get the Language ID. |
186 | * |
187 | * @return int |
188 | */ |
189 | public function getLangId() |
190 | { |
191 | return $this->langId; |
192 | } |
193 | |
194 | /** |
195 | * Set the East Asian Language. |
196 | * |
197 | * @param string $eastAsia |
198 | * The value for the east asian language |
199 | * |
200 | * @return self |
201 | */ |
202 | public function setEastAsia($eastAsia) |
203 | { |
204 | $this->eastAsia = $this->validateLocale($eastAsia); |
205 | |
206 | return $this; |
207 | } |
208 | |
209 | /** |
210 | * Get the East Asian Language. |
211 | * |
212 | * @return null|string |
213 | */ |
214 | public function getEastAsia() |
215 | { |
216 | return $this->eastAsia; |
217 | } |
218 | |
219 | /** |
220 | * Set the Complex Script Language. |
221 | * |
222 | * @param string $bidirectional |
223 | * The value for the complex script language |
224 | * |
225 | * @return self |
226 | */ |
227 | public function setBidirectional($bidirectional) |
228 | { |
229 | $this->bidirectional = $this->validateLocale($bidirectional); |
230 | |
231 | return $this; |
232 | } |
233 | |
234 | /** |
235 | * Get the Complex Script Language. |
236 | * |
237 | * @return null|string |
238 | */ |
239 | public function getBidirectional() |
240 | { |
241 | return $this->bidirectional; |
242 | } |
243 | |
244 | /** |
245 | * Validates that the language passed is in the format xx-xx. |
246 | * |
247 | * @param string $locale |
248 | * |
249 | * @return string |
250 | */ |
251 | private function validateLocale($locale) |
252 | { |
253 | if ($locale !== null) { |
254 | $locale = str_replace('_', '-', $locale); |
255 | } |
256 | |
257 | if ($locale !== null && strlen($locale) === 2) { |
258 | return strtolower($locale) . '-' . strtoupper($locale); |
259 | } |
260 | if ($locale === 'und') { |
261 | return 'en-EN'; |
262 | } |
263 | if ($locale !== null && $locale !== 'zxx' && strstr($locale, '-') === false) { |
264 | throw new InvalidArgumentException($locale . ' is not a valid language code'); |
265 | } |
266 | |
267 | return $locale; |
268 | } |
269 | } |