@@ -16,408 +16,408 @@ |
||
16 | 16 | */ |
17 | 17 | class VueJs extends Extractor implements ExtractorInterface, ExtractorMultiInterface |
18 | 18 | { |
19 | - public static $options = [ |
|
20 | - 'constants' => [], |
|
21 | - |
|
22 | - 'functions' => [ |
|
23 | - 'gettext' => 'gettext', |
|
24 | - '__' => 'gettext', |
|
25 | - 'ngettext' => 'ngettext', |
|
26 | - 'n__' => 'ngettext', |
|
27 | - 'pgettext' => 'pgettext', |
|
28 | - 'p__' => 'pgettext', |
|
29 | - 'dgettext' => 'dgettext', |
|
30 | - 'd__' => 'dgettext', |
|
31 | - 'dngettext' => 'dngettext', |
|
32 | - 'dn__' => 'dngettext', |
|
33 | - 'dpgettext' => 'dpgettext', |
|
34 | - 'dp__' => 'dpgettext', |
|
35 | - 'npgettext' => 'npgettext', |
|
36 | - 'np__' => 'npgettext', |
|
37 | - 'dnpgettext' => 'dnpgettext', |
|
38 | - 'dnp__' => 'dnpgettext', |
|
39 | - 'noop' => 'noop', |
|
40 | - 'noop__' => 'noop', |
|
41 | - ], |
|
42 | - ]; |
|
43 | - |
|
44 | - protected static $functionsScannerClass = 'Gettext\Utils\JsFunctionsScanner'; |
|
45 | - |
|
46 | - /** |
|
47 | - * @inheritDoc |
|
48 | - * @throws Exception |
|
49 | - */ |
|
50 | - public static function fromFileMultiple($file, array $translations, array $options = []) |
|
51 | - { |
|
52 | - foreach (static::getFiles($file) as $file) { |
|
53 | - $options['file'] = $file; |
|
54 | - static::fromStringMultiple(static::readFile($file), $translations, $options); |
|
55 | - } |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @inheritdoc |
|
60 | - * @throws Exception |
|
61 | - */ |
|
62 | - public static function fromString($string, Translations $translations, array $options = []) |
|
63 | - { |
|
64 | - static::fromStringMultiple($string, [$translations], $options); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @inheritDoc |
|
69 | - * @throws Exception |
|
70 | - */ |
|
71 | - public static function fromStringMultiple($string, array $translations, array $options = []) |
|
72 | - { |
|
73 | - $options += static::$options; |
|
74 | - $options += [ |
|
75 | - // HTML attribute prefixes we parse as JS which could contain translations (are JS expressions) |
|
76 | - 'attributePrefixes' => [ |
|
77 | - ':', |
|
78 | - 'v-bind:', |
|
79 | - 'v-on:', |
|
80 | - 'v-text', |
|
81 | - ], |
|
82 | - // HTML Tags to parse |
|
83 | - 'tagNames' => [ |
|
84 | - 'translate', |
|
85 | - ], |
|
86 | - // HTML tags to parse when attribute exists |
|
87 | - 'tagAttributes' => [ |
|
88 | - 'v-translate', |
|
89 | - ], |
|
90 | - // Comments |
|
91 | - 'commentAttributes' => [ |
|
92 | - 'translate-comment', |
|
93 | - ], |
|
94 | - 'contextAttributes' => [ |
|
95 | - 'translate-context', |
|
96 | - ], |
|
97 | - // Attribute with plural content |
|
98 | - 'pluralAttributes' => [ |
|
99 | - 'translate-plural', |
|
100 | - ], |
|
101 | - ]; |
|
102 | - |
|
103 | - // Ok, this is the weirdest hack, but let me explain: |
|
104 | - // On Linux (Mac is fine), when converting HTML to DOM, new lines get trimmed after the first tag. |
|
105 | - // So if there are new lines between <template> and next element, they are lost |
|
106 | - // So we insert a "." which is a text node, and it will prevent that newlines are stripped between elements. |
|
107 | - // Same thing happens between template and script tag. |
|
108 | - $string = str_replace('<template>', '<template>.', $string); |
|
109 | - $string = str_replace('</template>', '</template>.', $string); |
|
110 | - |
|
111 | - // Normalize newlines |
|
112 | - $string = str_replace(["\r\n", "\n\r", "\r"], "\n", $string); |
|
113 | - |
|
114 | - // VueJS files are valid HTML files, we will operate with the DOM here |
|
115 | - $dom = static::convertHtmlToDom($string); |
|
116 | - |
|
117 | - $script = static::extractScriptTag($string); |
|
118 | - |
|
119 | - // Parse the script part as a regular JS code |
|
120 | - if ($script) { |
|
121 | - $scriptLineNumber = $dom->getElementsByTagName('script')->item(0)->getLineNo(); |
|
122 | - static::getScriptTranslationsFromString( |
|
123 | - $script, |
|
124 | - $translations, |
|
125 | - $options, |
|
126 | - $scriptLineNumber - 1 |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - // Template part is parsed separately, all variables will be extracted |
|
131 | - // and handled as a regular JS code |
|
132 | - $template = $dom->getElementsByTagName('template')->item(0); |
|
133 | - if ($template) { |
|
134 | - static::getTemplateTranslations( |
|
135 | - $template, |
|
136 | - $translations, |
|
137 | - $options, |
|
138 | - $template->getLineNo() - 1 |
|
139 | - ); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Extracts script tag contents using regex instead of DOM operations. |
|
145 | - * If we parse using DOM, some contents may change, for example, tags within strings will be stripped |
|
146 | - * |
|
147 | - * @param $string |
|
148 | - * @return bool|string |
|
149 | - */ |
|
150 | - protected static function extractScriptTag($string) |
|
151 | - { |
|
152 | - if (preg_match('#<\s*?script\b[^>]*>(.*?)</script\b[^>]*>#s', $string, $matches)) { |
|
153 | - return $matches[1]; |
|
154 | - } |
|
155 | - |
|
156 | - return ''; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @param string $html |
|
161 | - * @return DOMDocument |
|
162 | - */ |
|
163 | - protected static function convertHtmlToDom($html) |
|
164 | - { |
|
165 | - $dom = new DOMDocument; |
|
166 | - |
|
167 | - libxml_use_internal_errors(true); |
|
168 | - |
|
169 | - // Prepend xml encoding so DOMDocument document handles UTF8 correctly. |
|
170 | - // Assuming that vue template files will not have any xml encoding tags, because duplicate tags may be ignored. |
|
171 | - $dom->loadHTML('<?xml encoding="utf-8"?>' . $html); |
|
172 | - |
|
173 | - libxml_clear_errors(); |
|
174 | - |
|
175 | - return $dom; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Extract translations from script part |
|
180 | - * |
|
181 | - * @param string $scriptContents Only script tag contents, not the whole template |
|
182 | - * @param Translations|Translations[] $translations One or multiple domain Translation objects |
|
183 | - * @param array $options |
|
184 | - * @param int $lineOffset Number of lines the script is offset in the vue template file |
|
185 | - * @throws Exception |
|
186 | - */ |
|
187 | - protected static function getScriptTranslationsFromString( |
|
188 | - $scriptContents, |
|
189 | - $translations, |
|
190 | - array $options = [], |
|
191 | - $lineOffset = 0 |
|
192 | - ) { |
|
193 | - /** @var FunctionsScanner $functions */ |
|
194 | - $functions = new static::$functionsScannerClass($scriptContents); |
|
195 | - $options['lineOffset'] = $lineOffset; |
|
196 | - $functions->saveGettextFunctions($translations, $options); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Parse template to extract all translations (element content and dynamic element attributes) |
|
201 | - * |
|
202 | - * @param DOMNode $dom |
|
203 | - * @param Translations|Translations[] $translations One or multiple domain Translation objects |
|
204 | - * @param array $options |
|
205 | - * @param int $lineOffset Line number where the template part starts in the vue file |
|
206 | - * @throws Exception |
|
207 | - */ |
|
208 | - protected static function getTemplateTranslations( |
|
209 | - DOMNode $dom, |
|
210 | - $translations, |
|
211 | - array $options, |
|
212 | - $lineOffset = 0 |
|
213 | - ) { |
|
214 | - // Build a JS string from all template attribute expressions |
|
215 | - $fakeAttributeJs = static::getTemplateAttributeFakeJs($options, $dom); |
|
216 | - |
|
217 | - // 1 line offset is necessary because parent template element was ignored when converting to DOM |
|
218 | - static::getScriptTranslationsFromString($fakeAttributeJs, $translations, $options, $lineOffset); |
|
219 | - |
|
220 | - // Build a JS string from template element content expressions |
|
221 | - $fakeTemplateJs = static::getTemplateFakeJs($dom); |
|
222 | - static::getScriptTranslationsFromString($fakeTemplateJs, $translations, $options, $lineOffset); |
|
223 | - |
|
224 | - static::getTagTranslations($options, $dom, $translations); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @param array $options |
|
229 | - * @param DOMNode $dom |
|
230 | - * @param Translations|Translations[] $translations |
|
231 | - */ |
|
232 | - protected static function getTagTranslations(array $options, DOMNode $dom, $translations) |
|
233 | - { |
|
234 | - // Since tag scanning does not support domains, we always use the first translation given |
|
235 | - $translations = is_array($translations) ? reset($translations) : $translations; |
|
236 | - |
|
237 | - $children = $dom->childNodes; |
|
238 | - for ($i = 0; $i < $children->length; $i++) { |
|
239 | - $node = $children->item($i); |
|
240 | - |
|
241 | - if (!($node instanceof DOMElement)) { |
|
242 | - continue; |
|
243 | - } |
|
244 | - |
|
245 | - $translatable = false; |
|
246 | - |
|
247 | - if (in_array($node->tagName, $options['tagNames'], true)) { |
|
248 | - $translatable = true; |
|
249 | - } |
|
250 | - |
|
251 | - $attrList = $node->attributes; |
|
252 | - $context = null; |
|
253 | - $plural = ""; |
|
254 | - $comment = null; |
|
255 | - |
|
256 | - for ($j = 0; $j < $attrList->length; $j++) { |
|
257 | - /** @var DOMAttr $domAttr */ |
|
258 | - $domAttr = $attrList->item($j); |
|
259 | - // Check if this is a dynamic vue attribute |
|
260 | - if (in_array($domAttr->name, $options['tagAttributes'])) { |
|
261 | - $translatable = true; |
|
262 | - } |
|
263 | - if (in_array($domAttr->name, $options['contextAttributes'])) { |
|
264 | - $context = $domAttr->value; |
|
265 | - } |
|
266 | - if (in_array($domAttr->name, $options['pluralAttributes'])) { |
|
267 | - $plural = $domAttr->value; |
|
268 | - } |
|
269 | - if (in_array($domAttr->name, $options['commentAttributes'])) { |
|
270 | - $comment = $domAttr->value; |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - if ($translatable) { |
|
275 | - $translation = $translations->insert($context, trim($node->textContent), $plural); |
|
276 | - $translation->addReference($options['file'], $node->getLineNo()); |
|
277 | - if ($comment) { |
|
278 | - $translation->addExtractedComment($comment); |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - if ($node->hasChildNodes()) { |
|
283 | - static::getTagTranslations($options, $node, $translations); |
|
284 | - } |
|
285 | - } |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Extract JS expressions from element attribute bindings (excluding text within elements) |
|
290 | - * For example: <span :title="__('extract this')"> skip element content </span> |
|
291 | - * |
|
292 | - * @param array $options |
|
293 | - * @param DOMNode $dom |
|
294 | - * @return string JS code |
|
295 | - */ |
|
296 | - protected static function getTemplateAttributeFakeJs(array $options, DOMNode $dom) |
|
297 | - { |
|
298 | - $expressionsByLine = static::getVueAttributeExpressions($options['attributePrefixes'], $dom); |
|
299 | - |
|
300 | - if (empty($expressionsByLine)) { |
|
301 | - return ''; |
|
302 | - } |
|
303 | - |
|
304 | - $maxLines = max(array_keys($expressionsByLine)); |
|
305 | - $fakeJs = ''; |
|
306 | - |
|
307 | - for ($line = 1; $line <= $maxLines; $line++) { |
|
308 | - if (isset($expressionsByLine[$line])) { |
|
309 | - $fakeJs .= implode("; ", $expressionsByLine[$line]); |
|
310 | - } |
|
311 | - $fakeJs .= "\n"; |
|
312 | - } |
|
313 | - |
|
314 | - return $fakeJs; |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * Loop DOM element recursively and parse out all dynamic vue attributes which are basically JS expressions |
|
319 | - * |
|
320 | - * @param array $attributePrefixes List of attribute prefixes we parse as JS (may contain translations) |
|
321 | - * @param DOMNode $dom |
|
322 | - * @param array $expressionByLine [lineNumber => [jsExpression, ..], ..] |
|
323 | - * @return array [lineNumber => [jsExpression, ..], ..] |
|
324 | - */ |
|
325 | - protected static function getVueAttributeExpressions( |
|
326 | - array $attributePrefixes, |
|
327 | - DOMNode $dom, |
|
328 | - array &$expressionByLine = [] |
|
329 | - ) { |
|
330 | - $children = $dom->childNodes; |
|
331 | - |
|
332 | - for ($i = 0; $i < $children->length; $i++) { |
|
333 | - $node = $children->item($i); |
|
334 | - |
|
335 | - if (!($node instanceof DOMElement)) { |
|
336 | - continue; |
|
337 | - } |
|
338 | - $attrList = $node->attributes; |
|
339 | - |
|
340 | - for ($j = 0; $j < $attrList->length; $j++) { |
|
341 | - /** @var DOMAttr $domAttr */ |
|
342 | - $domAttr = $attrList->item($j); |
|
343 | - |
|
344 | - // Check if this is a dynamic vue attribute |
|
345 | - if (static::isAttributeMatching($domAttr->name, $attributePrefixes)) { |
|
346 | - $line = $domAttr->getLineNo(); |
|
347 | - $expressionByLine += [$line => []]; |
|
348 | - $expressionByLine[$line][] = $domAttr->value; |
|
349 | - } |
|
350 | - } |
|
351 | - |
|
352 | - if ($node->hasChildNodes()) { |
|
353 | - $expressionByLine = static::getVueAttributeExpressions($attributePrefixes, $node, $expressionByLine); |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - return $expressionByLine; |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Check if this attribute name should be parsed for translations |
|
362 | - * |
|
363 | - * @param string $attributeName |
|
364 | - * @param string[] $attributePrefixes |
|
365 | - * @return bool |
|
366 | - */ |
|
367 | - protected static function isAttributeMatching($attributeName, $attributePrefixes) |
|
368 | - { |
|
369 | - foreach ($attributePrefixes as $prefix) { |
|
370 | - if (strpos($attributeName, $prefix) === 0) { |
|
371 | - return true; |
|
372 | - } |
|
373 | - } |
|
374 | - return false; |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Extract JS expressions from within template elements (excluding attributes) |
|
379 | - * For example: <span :title="skip attributes"> {{__("extract element content")}} </span> |
|
380 | - * |
|
381 | - * @param DOMNode $dom |
|
382 | - * @return string JS code |
|
383 | - */ |
|
384 | - protected static function getTemplateFakeJs(DOMNode $dom) |
|
385 | - { |
|
386 | - $fakeJs = ''; |
|
387 | - $lines = explode("\n", $dom->textContent); |
|
388 | - |
|
389 | - // Build a fake JS file from template by extracting JS expressions within each template line |
|
390 | - foreach ($lines as $line) { |
|
391 | - $expressionMatched = static::parseOneTemplateLine($line); |
|
392 | - |
|
393 | - $fakeJs .= implode("; ", $expressionMatched) . "\n"; |
|
394 | - } |
|
395 | - |
|
396 | - return $fakeJs; |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * Match JS expressions in a template line |
|
401 | - * |
|
402 | - * @param string $line |
|
403 | - * @return string[] |
|
404 | - */ |
|
405 | - protected static function parseOneTemplateLine($line) |
|
406 | - { |
|
407 | - $line = trim($line); |
|
408 | - |
|
409 | - if (!$line) { |
|
410 | - return []; |
|
411 | - } |
|
412 | - |
|
413 | - $regex = '#\{\{(.*?)\}\}#'; |
|
414 | - |
|
415 | - preg_match_all($regex, $line, $matches); |
|
416 | - |
|
417 | - $matched = array_map(function ($v) { |
|
418 | - return trim($v, '\'"{}'); |
|
419 | - }, $matches[1]); |
|
420 | - |
|
421 | - return $matched; |
|
422 | - } |
|
19 | + public static $options = [ |
|
20 | + 'constants' => [], |
|
21 | + |
|
22 | + 'functions' => [ |
|
23 | + 'gettext' => 'gettext', |
|
24 | + '__' => 'gettext', |
|
25 | + 'ngettext' => 'ngettext', |
|
26 | + 'n__' => 'ngettext', |
|
27 | + 'pgettext' => 'pgettext', |
|
28 | + 'p__' => 'pgettext', |
|
29 | + 'dgettext' => 'dgettext', |
|
30 | + 'd__' => 'dgettext', |
|
31 | + 'dngettext' => 'dngettext', |
|
32 | + 'dn__' => 'dngettext', |
|
33 | + 'dpgettext' => 'dpgettext', |
|
34 | + 'dp__' => 'dpgettext', |
|
35 | + 'npgettext' => 'npgettext', |
|
36 | + 'np__' => 'npgettext', |
|
37 | + 'dnpgettext' => 'dnpgettext', |
|
38 | + 'dnp__' => 'dnpgettext', |
|
39 | + 'noop' => 'noop', |
|
40 | + 'noop__' => 'noop', |
|
41 | + ], |
|
42 | + ]; |
|
43 | + |
|
44 | + protected static $functionsScannerClass = 'Gettext\Utils\JsFunctionsScanner'; |
|
45 | + |
|
46 | + /** |
|
47 | + * @inheritDoc |
|
48 | + * @throws Exception |
|
49 | + */ |
|
50 | + public static function fromFileMultiple($file, array $translations, array $options = []) |
|
51 | + { |
|
52 | + foreach (static::getFiles($file) as $file) { |
|
53 | + $options['file'] = $file; |
|
54 | + static::fromStringMultiple(static::readFile($file), $translations, $options); |
|
55 | + } |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @inheritdoc |
|
60 | + * @throws Exception |
|
61 | + */ |
|
62 | + public static function fromString($string, Translations $translations, array $options = []) |
|
63 | + { |
|
64 | + static::fromStringMultiple($string, [$translations], $options); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @inheritDoc |
|
69 | + * @throws Exception |
|
70 | + */ |
|
71 | + public static function fromStringMultiple($string, array $translations, array $options = []) |
|
72 | + { |
|
73 | + $options += static::$options; |
|
74 | + $options += [ |
|
75 | + // HTML attribute prefixes we parse as JS which could contain translations (are JS expressions) |
|
76 | + 'attributePrefixes' => [ |
|
77 | + ':', |
|
78 | + 'v-bind:', |
|
79 | + 'v-on:', |
|
80 | + 'v-text', |
|
81 | + ], |
|
82 | + // HTML Tags to parse |
|
83 | + 'tagNames' => [ |
|
84 | + 'translate', |
|
85 | + ], |
|
86 | + // HTML tags to parse when attribute exists |
|
87 | + 'tagAttributes' => [ |
|
88 | + 'v-translate', |
|
89 | + ], |
|
90 | + // Comments |
|
91 | + 'commentAttributes' => [ |
|
92 | + 'translate-comment', |
|
93 | + ], |
|
94 | + 'contextAttributes' => [ |
|
95 | + 'translate-context', |
|
96 | + ], |
|
97 | + // Attribute with plural content |
|
98 | + 'pluralAttributes' => [ |
|
99 | + 'translate-plural', |
|
100 | + ], |
|
101 | + ]; |
|
102 | + |
|
103 | + // Ok, this is the weirdest hack, but let me explain: |
|
104 | + // On Linux (Mac is fine), when converting HTML to DOM, new lines get trimmed after the first tag. |
|
105 | + // So if there are new lines between <template> and next element, they are lost |
|
106 | + // So we insert a "." which is a text node, and it will prevent that newlines are stripped between elements. |
|
107 | + // Same thing happens between template and script tag. |
|
108 | + $string = str_replace('<template>', '<template>.', $string); |
|
109 | + $string = str_replace('</template>', '</template>.', $string); |
|
110 | + |
|
111 | + // Normalize newlines |
|
112 | + $string = str_replace(["\r\n", "\n\r", "\r"], "\n", $string); |
|
113 | + |
|
114 | + // VueJS files are valid HTML files, we will operate with the DOM here |
|
115 | + $dom = static::convertHtmlToDom($string); |
|
116 | + |
|
117 | + $script = static::extractScriptTag($string); |
|
118 | + |
|
119 | + // Parse the script part as a regular JS code |
|
120 | + if ($script) { |
|
121 | + $scriptLineNumber = $dom->getElementsByTagName('script')->item(0)->getLineNo(); |
|
122 | + static::getScriptTranslationsFromString( |
|
123 | + $script, |
|
124 | + $translations, |
|
125 | + $options, |
|
126 | + $scriptLineNumber - 1 |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + // Template part is parsed separately, all variables will be extracted |
|
131 | + // and handled as a regular JS code |
|
132 | + $template = $dom->getElementsByTagName('template')->item(0); |
|
133 | + if ($template) { |
|
134 | + static::getTemplateTranslations( |
|
135 | + $template, |
|
136 | + $translations, |
|
137 | + $options, |
|
138 | + $template->getLineNo() - 1 |
|
139 | + ); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Extracts script tag contents using regex instead of DOM operations. |
|
145 | + * If we parse using DOM, some contents may change, for example, tags within strings will be stripped |
|
146 | + * |
|
147 | + * @param $string |
|
148 | + * @return bool|string |
|
149 | + */ |
|
150 | + protected static function extractScriptTag($string) |
|
151 | + { |
|
152 | + if (preg_match('#<\s*?script\b[^>]*>(.*?)</script\b[^>]*>#s', $string, $matches)) { |
|
153 | + return $matches[1]; |
|
154 | + } |
|
155 | + |
|
156 | + return ''; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @param string $html |
|
161 | + * @return DOMDocument |
|
162 | + */ |
|
163 | + protected static function convertHtmlToDom($html) |
|
164 | + { |
|
165 | + $dom = new DOMDocument; |
|
166 | + |
|
167 | + libxml_use_internal_errors(true); |
|
168 | + |
|
169 | + // Prepend xml encoding so DOMDocument document handles UTF8 correctly. |
|
170 | + // Assuming that vue template files will not have any xml encoding tags, because duplicate tags may be ignored. |
|
171 | + $dom->loadHTML('<?xml encoding="utf-8"?>' . $html); |
|
172 | + |
|
173 | + libxml_clear_errors(); |
|
174 | + |
|
175 | + return $dom; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Extract translations from script part |
|
180 | + * |
|
181 | + * @param string $scriptContents Only script tag contents, not the whole template |
|
182 | + * @param Translations|Translations[] $translations One or multiple domain Translation objects |
|
183 | + * @param array $options |
|
184 | + * @param int $lineOffset Number of lines the script is offset in the vue template file |
|
185 | + * @throws Exception |
|
186 | + */ |
|
187 | + protected static function getScriptTranslationsFromString( |
|
188 | + $scriptContents, |
|
189 | + $translations, |
|
190 | + array $options = [], |
|
191 | + $lineOffset = 0 |
|
192 | + ) { |
|
193 | + /** @var FunctionsScanner $functions */ |
|
194 | + $functions = new static::$functionsScannerClass($scriptContents); |
|
195 | + $options['lineOffset'] = $lineOffset; |
|
196 | + $functions->saveGettextFunctions($translations, $options); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Parse template to extract all translations (element content and dynamic element attributes) |
|
201 | + * |
|
202 | + * @param DOMNode $dom |
|
203 | + * @param Translations|Translations[] $translations One or multiple domain Translation objects |
|
204 | + * @param array $options |
|
205 | + * @param int $lineOffset Line number where the template part starts in the vue file |
|
206 | + * @throws Exception |
|
207 | + */ |
|
208 | + protected static function getTemplateTranslations( |
|
209 | + DOMNode $dom, |
|
210 | + $translations, |
|
211 | + array $options, |
|
212 | + $lineOffset = 0 |
|
213 | + ) { |
|
214 | + // Build a JS string from all template attribute expressions |
|
215 | + $fakeAttributeJs = static::getTemplateAttributeFakeJs($options, $dom); |
|
216 | + |
|
217 | + // 1 line offset is necessary because parent template element was ignored when converting to DOM |
|
218 | + static::getScriptTranslationsFromString($fakeAttributeJs, $translations, $options, $lineOffset); |
|
219 | + |
|
220 | + // Build a JS string from template element content expressions |
|
221 | + $fakeTemplateJs = static::getTemplateFakeJs($dom); |
|
222 | + static::getScriptTranslationsFromString($fakeTemplateJs, $translations, $options, $lineOffset); |
|
223 | + |
|
224 | + static::getTagTranslations($options, $dom, $translations); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @param array $options |
|
229 | + * @param DOMNode $dom |
|
230 | + * @param Translations|Translations[] $translations |
|
231 | + */ |
|
232 | + protected static function getTagTranslations(array $options, DOMNode $dom, $translations) |
|
233 | + { |
|
234 | + // Since tag scanning does not support domains, we always use the first translation given |
|
235 | + $translations = is_array($translations) ? reset($translations) : $translations; |
|
236 | + |
|
237 | + $children = $dom->childNodes; |
|
238 | + for ($i = 0; $i < $children->length; $i++) { |
|
239 | + $node = $children->item($i); |
|
240 | + |
|
241 | + if (!($node instanceof DOMElement)) { |
|
242 | + continue; |
|
243 | + } |
|
244 | + |
|
245 | + $translatable = false; |
|
246 | + |
|
247 | + if (in_array($node->tagName, $options['tagNames'], true)) { |
|
248 | + $translatable = true; |
|
249 | + } |
|
250 | + |
|
251 | + $attrList = $node->attributes; |
|
252 | + $context = null; |
|
253 | + $plural = ""; |
|
254 | + $comment = null; |
|
255 | + |
|
256 | + for ($j = 0; $j < $attrList->length; $j++) { |
|
257 | + /** @var DOMAttr $domAttr */ |
|
258 | + $domAttr = $attrList->item($j); |
|
259 | + // Check if this is a dynamic vue attribute |
|
260 | + if (in_array($domAttr->name, $options['tagAttributes'])) { |
|
261 | + $translatable = true; |
|
262 | + } |
|
263 | + if (in_array($domAttr->name, $options['contextAttributes'])) { |
|
264 | + $context = $domAttr->value; |
|
265 | + } |
|
266 | + if (in_array($domAttr->name, $options['pluralAttributes'])) { |
|
267 | + $plural = $domAttr->value; |
|
268 | + } |
|
269 | + if (in_array($domAttr->name, $options['commentAttributes'])) { |
|
270 | + $comment = $domAttr->value; |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + if ($translatable) { |
|
275 | + $translation = $translations->insert($context, trim($node->textContent), $plural); |
|
276 | + $translation->addReference($options['file'], $node->getLineNo()); |
|
277 | + if ($comment) { |
|
278 | + $translation->addExtractedComment($comment); |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + if ($node->hasChildNodes()) { |
|
283 | + static::getTagTranslations($options, $node, $translations); |
|
284 | + } |
|
285 | + } |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Extract JS expressions from element attribute bindings (excluding text within elements) |
|
290 | + * For example: <span :title="__('extract this')"> skip element content </span> |
|
291 | + * |
|
292 | + * @param array $options |
|
293 | + * @param DOMNode $dom |
|
294 | + * @return string JS code |
|
295 | + */ |
|
296 | + protected static function getTemplateAttributeFakeJs(array $options, DOMNode $dom) |
|
297 | + { |
|
298 | + $expressionsByLine = static::getVueAttributeExpressions($options['attributePrefixes'], $dom); |
|
299 | + |
|
300 | + if (empty($expressionsByLine)) { |
|
301 | + return ''; |
|
302 | + } |
|
303 | + |
|
304 | + $maxLines = max(array_keys($expressionsByLine)); |
|
305 | + $fakeJs = ''; |
|
306 | + |
|
307 | + for ($line = 1; $line <= $maxLines; $line++) { |
|
308 | + if (isset($expressionsByLine[$line])) { |
|
309 | + $fakeJs .= implode("; ", $expressionsByLine[$line]); |
|
310 | + } |
|
311 | + $fakeJs .= "\n"; |
|
312 | + } |
|
313 | + |
|
314 | + return $fakeJs; |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * Loop DOM element recursively and parse out all dynamic vue attributes which are basically JS expressions |
|
319 | + * |
|
320 | + * @param array $attributePrefixes List of attribute prefixes we parse as JS (may contain translations) |
|
321 | + * @param DOMNode $dom |
|
322 | + * @param array $expressionByLine [lineNumber => [jsExpression, ..], ..] |
|
323 | + * @return array [lineNumber => [jsExpression, ..], ..] |
|
324 | + */ |
|
325 | + protected static function getVueAttributeExpressions( |
|
326 | + array $attributePrefixes, |
|
327 | + DOMNode $dom, |
|
328 | + array &$expressionByLine = [] |
|
329 | + ) { |
|
330 | + $children = $dom->childNodes; |
|
331 | + |
|
332 | + for ($i = 0; $i < $children->length; $i++) { |
|
333 | + $node = $children->item($i); |
|
334 | + |
|
335 | + if (!($node instanceof DOMElement)) { |
|
336 | + continue; |
|
337 | + } |
|
338 | + $attrList = $node->attributes; |
|
339 | + |
|
340 | + for ($j = 0; $j < $attrList->length; $j++) { |
|
341 | + /** @var DOMAttr $domAttr */ |
|
342 | + $domAttr = $attrList->item($j); |
|
343 | + |
|
344 | + // Check if this is a dynamic vue attribute |
|
345 | + if (static::isAttributeMatching($domAttr->name, $attributePrefixes)) { |
|
346 | + $line = $domAttr->getLineNo(); |
|
347 | + $expressionByLine += [$line => []]; |
|
348 | + $expressionByLine[$line][] = $domAttr->value; |
|
349 | + } |
|
350 | + } |
|
351 | + |
|
352 | + if ($node->hasChildNodes()) { |
|
353 | + $expressionByLine = static::getVueAttributeExpressions($attributePrefixes, $node, $expressionByLine); |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + return $expressionByLine; |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Check if this attribute name should be parsed for translations |
|
362 | + * |
|
363 | + * @param string $attributeName |
|
364 | + * @param string[] $attributePrefixes |
|
365 | + * @return bool |
|
366 | + */ |
|
367 | + protected static function isAttributeMatching($attributeName, $attributePrefixes) |
|
368 | + { |
|
369 | + foreach ($attributePrefixes as $prefix) { |
|
370 | + if (strpos($attributeName, $prefix) === 0) { |
|
371 | + return true; |
|
372 | + } |
|
373 | + } |
|
374 | + return false; |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Extract JS expressions from within template elements (excluding attributes) |
|
379 | + * For example: <span :title="skip attributes"> {{__("extract element content")}} </span> |
|
380 | + * |
|
381 | + * @param DOMNode $dom |
|
382 | + * @return string JS code |
|
383 | + */ |
|
384 | + protected static function getTemplateFakeJs(DOMNode $dom) |
|
385 | + { |
|
386 | + $fakeJs = ''; |
|
387 | + $lines = explode("\n", $dom->textContent); |
|
388 | + |
|
389 | + // Build a fake JS file from template by extracting JS expressions within each template line |
|
390 | + foreach ($lines as $line) { |
|
391 | + $expressionMatched = static::parseOneTemplateLine($line); |
|
392 | + |
|
393 | + $fakeJs .= implode("; ", $expressionMatched) . "\n"; |
|
394 | + } |
|
395 | + |
|
396 | + return $fakeJs; |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * Match JS expressions in a template line |
|
401 | + * |
|
402 | + * @param string $line |
|
403 | + * @return string[] |
|
404 | + */ |
|
405 | + protected static function parseOneTemplateLine($line) |
|
406 | + { |
|
407 | + $line = trim($line); |
|
408 | + |
|
409 | + if (!$line) { |
|
410 | + return []; |
|
411 | + } |
|
412 | + |
|
413 | + $regex = '#\{\{(.*?)\}\}#'; |
|
414 | + |
|
415 | + preg_match_all($regex, $line, $matches); |
|
416 | + |
|
417 | + $matched = array_map(function ($v) { |
|
418 | + return trim($v, '\'"{}'); |
|
419 | + }, $matches[1]); |
|
420 | + |
|
421 | + return $matched; |
|
422 | + } |
|
423 | 423 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | class VueJs extends Extractor implements ExtractorInterface, ExtractorMultiInterface |
18 | 18 | { |
19 | 19 | public static $options = [ |
20 | - 'constants' => [], |
|
20 | + 'constants' => [ ], |
|
21 | 21 | |
22 | 22 | 'functions' => [ |
23 | 23 | 'gettext' => 'gettext', |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | * @inheritDoc |
48 | 48 | * @throws Exception |
49 | 49 | */ |
50 | - public static function fromFileMultiple($file, array $translations, array $options = []) |
|
50 | + public static function fromFileMultiple( $file, array $translations, array $options = [ ] ) |
|
51 | 51 | { |
52 | - foreach (static::getFiles($file) as $file) { |
|
53 | - $options['file'] = $file; |
|
54 | - static::fromStringMultiple(static::readFile($file), $translations, $options); |
|
52 | + foreach ( static::getFiles( $file ) as $file ) { |
|
53 | + $options[ 'file' ] = $file; |
|
54 | + static::fromStringMultiple( static::readFile( $file ), $translations, $options ); |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
@@ -59,16 +59,16 @@ discard block |
||
59 | 59 | * @inheritdoc |
60 | 60 | * @throws Exception |
61 | 61 | */ |
62 | - public static function fromString($string, Translations $translations, array $options = []) |
|
62 | + public static function fromString( $string, Translations $translations, array $options = [ ] ) |
|
63 | 63 | { |
64 | - static::fromStringMultiple($string, [$translations], $options); |
|
64 | + static::fromStringMultiple( $string, [ $translations ], $options ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | 68 | * @inheritDoc |
69 | 69 | * @throws Exception |
70 | 70 | */ |
71 | - public static function fromStringMultiple($string, array $translations, array $options = []) |
|
71 | + public static function fromStringMultiple( $string, array $translations, array $options = [ ] ) |
|
72 | 72 | { |
73 | 73 | $options += static::$options; |
74 | 74 | $options += [ |
@@ -105,20 +105,20 @@ discard block |
||
105 | 105 | // So if there are new lines between <template> and next element, they are lost |
106 | 106 | // So we insert a "." which is a text node, and it will prevent that newlines are stripped between elements. |
107 | 107 | // Same thing happens between template and script tag. |
108 | - $string = str_replace('<template>', '<template>.', $string); |
|
109 | - $string = str_replace('</template>', '</template>.', $string); |
|
108 | + $string = str_replace( '<template>', '<template>.', $string ); |
|
109 | + $string = str_replace( '</template>', '</template>.', $string ); |
|
110 | 110 | |
111 | 111 | // Normalize newlines |
112 | - $string = str_replace(["\r\n", "\n\r", "\r"], "\n", $string); |
|
112 | + $string = str_replace( [ "\r\n", "\n\r", "\r" ], "\n", $string ); |
|
113 | 113 | |
114 | 114 | // VueJS files are valid HTML files, we will operate with the DOM here |
115 | - $dom = static::convertHtmlToDom($string); |
|
115 | + $dom = static::convertHtmlToDom( $string ); |
|
116 | 116 | |
117 | - $script = static::extractScriptTag($string); |
|
117 | + $script = static::extractScriptTag( $string ); |
|
118 | 118 | |
119 | 119 | // Parse the script part as a regular JS code |
120 | - if ($script) { |
|
121 | - $scriptLineNumber = $dom->getElementsByTagName('script')->item(0)->getLineNo(); |
|
120 | + if ( $script ) { |
|
121 | + $scriptLineNumber = $dom->getElementsByTagName( 'script' )->item( 0 )->getLineNo(); |
|
122 | 122 | static::getScriptTranslationsFromString( |
123 | 123 | $script, |
124 | 124 | $translations, |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | |
130 | 130 | // Template part is parsed separately, all variables will be extracted |
131 | 131 | // and handled as a regular JS code |
132 | - $template = $dom->getElementsByTagName('template')->item(0); |
|
133 | - if ($template) { |
|
132 | + $template = $dom->getElementsByTagName( 'template' )->item( 0 ); |
|
133 | + if ( $template ) { |
|
134 | 134 | static::getTemplateTranslations( |
135 | 135 | $template, |
136 | 136 | $translations, |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | * @param $string |
148 | 148 | * @return bool|string |
149 | 149 | */ |
150 | - protected static function extractScriptTag($string) |
|
150 | + protected static function extractScriptTag( $string ) |
|
151 | 151 | { |
152 | - if (preg_match('#<\s*?script\b[^>]*>(.*?)</script\b[^>]*>#s', $string, $matches)) { |
|
153 | - return $matches[1]; |
|
152 | + if ( preg_match( '#<\s*?script\b[^>]*>(.*?)</script\b[^>]*>#s', $string, $matches ) ) { |
|
153 | + return $matches[ 1 ]; |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | return ''; |
@@ -160,15 +160,15 @@ discard block |
||
160 | 160 | * @param string $html |
161 | 161 | * @return DOMDocument |
162 | 162 | */ |
163 | - protected static function convertHtmlToDom($html) |
|
163 | + protected static function convertHtmlToDom( $html ) |
|
164 | 164 | { |
165 | 165 | $dom = new DOMDocument; |
166 | 166 | |
167 | - libxml_use_internal_errors(true); |
|
167 | + libxml_use_internal_errors( true ); |
|
168 | 168 | |
169 | 169 | // Prepend xml encoding so DOMDocument document handles UTF8 correctly. |
170 | 170 | // Assuming that vue template files will not have any xml encoding tags, because duplicate tags may be ignored. |
171 | - $dom->loadHTML('<?xml encoding="utf-8"?>' . $html); |
|
171 | + $dom->loadHTML( '<?xml encoding="utf-8"?>' . $html ); |
|
172 | 172 | |
173 | 173 | libxml_clear_errors(); |
174 | 174 | |
@@ -187,13 +187,13 @@ discard block |
||
187 | 187 | protected static function getScriptTranslationsFromString( |
188 | 188 | $scriptContents, |
189 | 189 | $translations, |
190 | - array $options = [], |
|
190 | + array $options = [ ], |
|
191 | 191 | $lineOffset = 0 |
192 | 192 | ) { |
193 | 193 | /** @var FunctionsScanner $functions */ |
194 | - $functions = new static::$functionsScannerClass($scriptContents); |
|
195 | - $options['lineOffset'] = $lineOffset; |
|
196 | - $functions->saveGettextFunctions($translations, $options); |
|
194 | + $functions = new static::$functionsScannerClass( $scriptContents ); |
|
195 | + $options[ 'lineOffset' ] = $lineOffset; |
|
196 | + $functions->saveGettextFunctions( $translations, $options ); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -212,16 +212,16 @@ discard block |
||
212 | 212 | $lineOffset = 0 |
213 | 213 | ) { |
214 | 214 | // Build a JS string from all template attribute expressions |
215 | - $fakeAttributeJs = static::getTemplateAttributeFakeJs($options, $dom); |
|
215 | + $fakeAttributeJs = static::getTemplateAttributeFakeJs( $options, $dom ); |
|
216 | 216 | |
217 | 217 | // 1 line offset is necessary because parent template element was ignored when converting to DOM |
218 | - static::getScriptTranslationsFromString($fakeAttributeJs, $translations, $options, $lineOffset); |
|
218 | + static::getScriptTranslationsFromString( $fakeAttributeJs, $translations, $options, $lineOffset ); |
|
219 | 219 | |
220 | 220 | // Build a JS string from template element content expressions |
221 | - $fakeTemplateJs = static::getTemplateFakeJs($dom); |
|
222 | - static::getScriptTranslationsFromString($fakeTemplateJs, $translations, $options, $lineOffset); |
|
221 | + $fakeTemplateJs = static::getTemplateFakeJs( $dom ); |
|
222 | + static::getScriptTranslationsFromString( $fakeTemplateJs, $translations, $options, $lineOffset ); |
|
223 | 223 | |
224 | - static::getTagTranslations($options, $dom, $translations); |
|
224 | + static::getTagTranslations( $options, $dom, $translations ); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -229,22 +229,22 @@ discard block |
||
229 | 229 | * @param DOMNode $dom |
230 | 230 | * @param Translations|Translations[] $translations |
231 | 231 | */ |
232 | - protected static function getTagTranslations(array $options, DOMNode $dom, $translations) |
|
232 | + protected static function getTagTranslations( array $options, DOMNode $dom, $translations ) |
|
233 | 233 | { |
234 | 234 | // Since tag scanning does not support domains, we always use the first translation given |
235 | - $translations = is_array($translations) ? reset($translations) : $translations; |
|
235 | + $translations = is_array( $translations ) ? reset( $translations ) : $translations; |
|
236 | 236 | |
237 | 237 | $children = $dom->childNodes; |
238 | - for ($i = 0; $i < $children->length; $i++) { |
|
239 | - $node = $children->item($i); |
|
238 | + for ( $i = 0; $i < $children->length; $i++ ) { |
|
239 | + $node = $children->item( $i ); |
|
240 | 240 | |
241 | - if (!($node instanceof DOMElement)) { |
|
241 | + if ( ! ( $node instanceof DOMElement ) ) { |
|
242 | 242 | continue; |
243 | 243 | } |
244 | 244 | |
245 | 245 | $translatable = false; |
246 | 246 | |
247 | - if (in_array($node->tagName, $options['tagNames'], true)) { |
|
247 | + if ( in_array( $node->tagName, $options[ 'tagNames' ], true ) ) { |
|
248 | 248 | $translatable = true; |
249 | 249 | } |
250 | 250 | |
@@ -253,34 +253,34 @@ discard block |
||
253 | 253 | $plural = ""; |
254 | 254 | $comment = null; |
255 | 255 | |
256 | - for ($j = 0; $j < $attrList->length; $j++) { |
|
256 | + for ( $j = 0; $j < $attrList->length; $j++ ) { |
|
257 | 257 | /** @var DOMAttr $domAttr */ |
258 | - $domAttr = $attrList->item($j); |
|
258 | + $domAttr = $attrList->item( $j ); |
|
259 | 259 | // Check if this is a dynamic vue attribute |
260 | - if (in_array($domAttr->name, $options['tagAttributes'])) { |
|
260 | + if ( in_array( $domAttr->name, $options[ 'tagAttributes' ] ) ) { |
|
261 | 261 | $translatable = true; |
262 | 262 | } |
263 | - if (in_array($domAttr->name, $options['contextAttributes'])) { |
|
263 | + if ( in_array( $domAttr->name, $options[ 'contextAttributes' ] ) ) { |
|
264 | 264 | $context = $domAttr->value; |
265 | 265 | } |
266 | - if (in_array($domAttr->name, $options['pluralAttributes'])) { |
|
266 | + if ( in_array( $domAttr->name, $options[ 'pluralAttributes' ] ) ) { |
|
267 | 267 | $plural = $domAttr->value; |
268 | 268 | } |
269 | - if (in_array($domAttr->name, $options['commentAttributes'])) { |
|
269 | + if ( in_array( $domAttr->name, $options[ 'commentAttributes' ] ) ) { |
|
270 | 270 | $comment = $domAttr->value; |
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | - if ($translatable) { |
|
275 | - $translation = $translations->insert($context, trim($node->textContent), $plural); |
|
276 | - $translation->addReference($options['file'], $node->getLineNo()); |
|
277 | - if ($comment) { |
|
278 | - $translation->addExtractedComment($comment); |
|
274 | + if ( $translatable ) { |
|
275 | + $translation = $translations->insert( $context, trim( $node->textContent ), $plural ); |
|
276 | + $translation->addReference( $options[ 'file' ], $node->getLineNo() ); |
|
277 | + if ( $comment ) { |
|
278 | + $translation->addExtractedComment( $comment ); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | - if ($node->hasChildNodes()) { |
|
283 | - static::getTagTranslations($options, $node, $translations); |
|
282 | + if ( $node->hasChildNodes() ) { |
|
283 | + static::getTagTranslations( $options, $node, $translations ); |
|
284 | 284 | } |
285 | 285 | } |
286 | 286 | } |
@@ -293,20 +293,20 @@ discard block |
||
293 | 293 | * @param DOMNode $dom |
294 | 294 | * @return string JS code |
295 | 295 | */ |
296 | - protected static function getTemplateAttributeFakeJs(array $options, DOMNode $dom) |
|
296 | + protected static function getTemplateAttributeFakeJs( array $options, DOMNode $dom ) |
|
297 | 297 | { |
298 | - $expressionsByLine = static::getVueAttributeExpressions($options['attributePrefixes'], $dom); |
|
298 | + $expressionsByLine = static::getVueAttributeExpressions( $options[ 'attributePrefixes' ], $dom ); |
|
299 | 299 | |
300 | - if (empty($expressionsByLine)) { |
|
300 | + if ( empty( $expressionsByLine ) ) { |
|
301 | 301 | return ''; |
302 | 302 | } |
303 | 303 | |
304 | - $maxLines = max(array_keys($expressionsByLine)); |
|
304 | + $maxLines = max( array_keys( $expressionsByLine ) ); |
|
305 | 305 | $fakeJs = ''; |
306 | 306 | |
307 | - for ($line = 1; $line <= $maxLines; $line++) { |
|
308 | - if (isset($expressionsByLine[$line])) { |
|
309 | - $fakeJs .= implode("; ", $expressionsByLine[$line]); |
|
307 | + for ( $line = 1; $line <= $maxLines; $line++ ) { |
|
308 | + if ( isset( $expressionsByLine[ $line ] ) ) { |
|
309 | + $fakeJs .= implode( "; ", $expressionsByLine[ $line ] ); |
|
310 | 310 | } |
311 | 311 | $fakeJs .= "\n"; |
312 | 312 | } |
@@ -325,32 +325,32 @@ discard block |
||
325 | 325 | protected static function getVueAttributeExpressions( |
326 | 326 | array $attributePrefixes, |
327 | 327 | DOMNode $dom, |
328 | - array &$expressionByLine = [] |
|
328 | + array &$expressionByLine = [ ] |
|
329 | 329 | ) { |
330 | 330 | $children = $dom->childNodes; |
331 | 331 | |
332 | - for ($i = 0; $i < $children->length; $i++) { |
|
333 | - $node = $children->item($i); |
|
332 | + for ( $i = 0; $i < $children->length; $i++ ) { |
|
333 | + $node = $children->item( $i ); |
|
334 | 334 | |
335 | - if (!($node instanceof DOMElement)) { |
|
335 | + if ( ! ( $node instanceof DOMElement ) ) { |
|
336 | 336 | continue; |
337 | 337 | } |
338 | 338 | $attrList = $node->attributes; |
339 | 339 | |
340 | - for ($j = 0; $j < $attrList->length; $j++) { |
|
340 | + for ( $j = 0; $j < $attrList->length; $j++ ) { |
|
341 | 341 | /** @var DOMAttr $domAttr */ |
342 | - $domAttr = $attrList->item($j); |
|
342 | + $domAttr = $attrList->item( $j ); |
|
343 | 343 | |
344 | 344 | // Check if this is a dynamic vue attribute |
345 | - if (static::isAttributeMatching($domAttr->name, $attributePrefixes)) { |
|
345 | + if ( static::isAttributeMatching( $domAttr->name, $attributePrefixes ) ) { |
|
346 | 346 | $line = $domAttr->getLineNo(); |
347 | - $expressionByLine += [$line => []]; |
|
348 | - $expressionByLine[$line][] = $domAttr->value; |
|
347 | + $expressionByLine += [ $line => [ ] ]; |
|
348 | + $expressionByLine[ $line ][ ] = $domAttr->value; |
|
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
352 | - if ($node->hasChildNodes()) { |
|
353 | - $expressionByLine = static::getVueAttributeExpressions($attributePrefixes, $node, $expressionByLine); |
|
352 | + if ( $node->hasChildNodes() ) { |
|
353 | + $expressionByLine = static::getVueAttributeExpressions( $attributePrefixes, $node, $expressionByLine ); |
|
354 | 354 | } |
355 | 355 | } |
356 | 356 | |
@@ -364,10 +364,10 @@ discard block |
||
364 | 364 | * @param string[] $attributePrefixes |
365 | 365 | * @return bool |
366 | 366 | */ |
367 | - protected static function isAttributeMatching($attributeName, $attributePrefixes) |
|
367 | + protected static function isAttributeMatching( $attributeName, $attributePrefixes ) |
|
368 | 368 | { |
369 | - foreach ($attributePrefixes as $prefix) { |
|
370 | - if (strpos($attributeName, $prefix) === 0) { |
|
369 | + foreach ( $attributePrefixes as $prefix ) { |
|
370 | + if ( strpos( $attributeName, $prefix ) === 0 ) { |
|
371 | 371 | return true; |
372 | 372 | } |
373 | 373 | } |
@@ -381,16 +381,16 @@ discard block |
||
381 | 381 | * @param DOMNode $dom |
382 | 382 | * @return string JS code |
383 | 383 | */ |
384 | - protected static function getTemplateFakeJs(DOMNode $dom) |
|
384 | + protected static function getTemplateFakeJs( DOMNode $dom ) |
|
385 | 385 | { |
386 | 386 | $fakeJs = ''; |
387 | - $lines = explode("\n", $dom->textContent); |
|
387 | + $lines = explode( "\n", $dom->textContent ); |
|
388 | 388 | |
389 | 389 | // Build a fake JS file from template by extracting JS expressions within each template line |
390 | - foreach ($lines as $line) { |
|
391 | - $expressionMatched = static::parseOneTemplateLine($line); |
|
390 | + foreach ( $lines as $line ) { |
|
391 | + $expressionMatched = static::parseOneTemplateLine( $line ); |
|
392 | 392 | |
393 | - $fakeJs .= implode("; ", $expressionMatched) . "\n"; |
|
393 | + $fakeJs .= implode( "; ", $expressionMatched ) . "\n"; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | return $fakeJs; |
@@ -402,21 +402,21 @@ discard block |
||
402 | 402 | * @param string $line |
403 | 403 | * @return string[] |
404 | 404 | */ |
405 | - protected static function parseOneTemplateLine($line) |
|
405 | + protected static function parseOneTemplateLine( $line ) |
|
406 | 406 | { |
407 | - $line = trim($line); |
|
407 | + $line = trim( $line ); |
|
408 | 408 | |
409 | - if (!$line) { |
|
410 | - return []; |
|
409 | + if ( ! $line ) { |
|
410 | + return [ ]; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | $regex = '#\{\{(.*?)\}\}#'; |
414 | 414 | |
415 | - preg_match_all($regex, $line, $matches); |
|
415 | + preg_match_all( $regex, $line, $matches ); |
|
416 | 416 | |
417 | - $matched = array_map(function ($v) { |
|
418 | - return trim($v, '\'"{}'); |
|
419 | - }, $matches[1]); |
|
417 | + $matched = array_map( function( $v ) { |
|
418 | + return trim( $v, '\'"{}' ); |
|
419 | + }, $matches[ 1 ] ); |
|
420 | 420 | |
421 | 421 | return $matched; |
422 | 422 | } |
@@ -47,8 +47,7 @@ discard block |
||
47 | 47 | * @inheritDoc |
48 | 48 | * @throws Exception |
49 | 49 | */ |
50 | - public static function fromFileMultiple($file, array $translations, array $options = []) |
|
51 | - { |
|
50 | + public static function fromFileMultiple($file, array $translations, array $options = []) { |
|
52 | 51 | foreach (static::getFiles($file) as $file) { |
53 | 52 | $options['file'] = $file; |
54 | 53 | static::fromStringMultiple(static::readFile($file), $translations, $options); |
@@ -59,8 +58,7 @@ discard block |
||
59 | 58 | * @inheritdoc |
60 | 59 | * @throws Exception |
61 | 60 | */ |
62 | - public static function fromString($string, Translations $translations, array $options = []) |
|
63 | - { |
|
61 | + public static function fromString($string, Translations $translations, array $options = []) { |
|
64 | 62 | static::fromStringMultiple($string, [$translations], $options); |
65 | 63 | } |
66 | 64 | |
@@ -68,8 +66,7 @@ discard block |
||
68 | 66 | * @inheritDoc |
69 | 67 | * @throws Exception |
70 | 68 | */ |
71 | - public static function fromStringMultiple($string, array $translations, array $options = []) |
|
72 | - { |
|
69 | + public static function fromStringMultiple($string, array $translations, array $options = []) { |
|
73 | 70 | $options += static::$options; |
74 | 71 | $options += [ |
75 | 72 | // HTML attribute prefixes we parse as JS which could contain translations (are JS expressions) |
@@ -147,8 +144,7 @@ discard block |
||
147 | 144 | * @param $string |
148 | 145 | * @return bool|string |
149 | 146 | */ |
150 | - protected static function extractScriptTag($string) |
|
151 | - { |
|
147 | + protected static function extractScriptTag($string) { |
|
152 | 148 | if (preg_match('#<\s*?script\b[^>]*>(.*?)</script\b[^>]*>#s', $string, $matches)) { |
153 | 149 | return $matches[1]; |
154 | 150 | } |
@@ -160,8 +156,7 @@ discard block |
||
160 | 156 | * @param string $html |
161 | 157 | * @return DOMDocument |
162 | 158 | */ |
163 | - protected static function convertHtmlToDom($html) |
|
164 | - { |
|
159 | + protected static function convertHtmlToDom($html) { |
|
165 | 160 | $dom = new DOMDocument; |
166 | 161 | |
167 | 162 | libxml_use_internal_errors(true); |
@@ -229,8 +224,7 @@ discard block |
||
229 | 224 | * @param DOMNode $dom |
230 | 225 | * @param Translations|Translations[] $translations |
231 | 226 | */ |
232 | - protected static function getTagTranslations(array $options, DOMNode $dom, $translations) |
|
233 | - { |
|
227 | + protected static function getTagTranslations(array $options, DOMNode $dom, $translations) { |
|
234 | 228 | // Since tag scanning does not support domains, we always use the first translation given |
235 | 229 | $translations = is_array($translations) ? reset($translations) : $translations; |
236 | 230 | |
@@ -293,8 +287,7 @@ discard block |
||
293 | 287 | * @param DOMNode $dom |
294 | 288 | * @return string JS code |
295 | 289 | */ |
296 | - protected static function getTemplateAttributeFakeJs(array $options, DOMNode $dom) |
|
297 | - { |
|
290 | + protected static function getTemplateAttributeFakeJs(array $options, DOMNode $dom) { |
|
298 | 291 | $expressionsByLine = static::getVueAttributeExpressions($options['attributePrefixes'], $dom); |
299 | 292 | |
300 | 293 | if (empty($expressionsByLine)) { |
@@ -364,8 +357,7 @@ discard block |
||
364 | 357 | * @param string[] $attributePrefixes |
365 | 358 | * @return bool |
366 | 359 | */ |
367 | - protected static function isAttributeMatching($attributeName, $attributePrefixes) |
|
368 | - { |
|
360 | + protected static function isAttributeMatching($attributeName, $attributePrefixes) { |
|
369 | 361 | foreach ($attributePrefixes as $prefix) { |
370 | 362 | if (strpos($attributeName, $prefix) === 0) { |
371 | 363 | return true; |
@@ -381,8 +373,7 @@ discard block |
||
381 | 373 | * @param DOMNode $dom |
382 | 374 | * @return string JS code |
383 | 375 | */ |
384 | - protected static function getTemplateFakeJs(DOMNode $dom) |
|
385 | - { |
|
376 | + protected static function getTemplateFakeJs(DOMNode $dom) { |
|
386 | 377 | $fakeJs = ''; |
387 | 378 | $lines = explode("\n", $dom->textContent); |
388 | 379 | |
@@ -402,8 +393,7 @@ discard block |
||
402 | 393 | * @param string $line |
403 | 394 | * @return string[] |
404 | 395 | */ |
405 | - protected static function parseOneTemplateLine($line) |
|
406 | - { |
|
396 | + protected static function parseOneTemplateLine($line) { |
|
407 | 397 | $line = trim($line); |
408 | 398 | |
409 | 399 | if (!$line) { |
@@ -8,73 +8,73 @@ |
||
8 | 8 | |
9 | 9 | abstract class Extractor implements ExtractorInterface |
10 | 10 | { |
11 | - /** |
|
12 | - * {@inheritdoc} |
|
13 | - */ |
|
14 | - public static function fromFile($file, Translations $translations, array $options = []) |
|
15 | - { |
|
16 | - foreach (static::getFiles($file) as $file) { |
|
17 | - $options['file'] = $file; |
|
18 | - static::fromString(static::readFile($file), $translations, $options); |
|
19 | - } |
|
20 | - } |
|
11 | + /** |
|
12 | + * {@inheritdoc} |
|
13 | + */ |
|
14 | + public static function fromFile($file, Translations $translations, array $options = []) |
|
15 | + { |
|
16 | + foreach (static::getFiles($file) as $file) { |
|
17 | + $options['file'] = $file; |
|
18 | + static::fromString(static::readFile($file), $translations, $options); |
|
19 | + } |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * Checks and returns all files. |
|
24 | - * |
|
25 | - * @param string|array $file The file/s |
|
26 | - * |
|
27 | - * @return array The file paths |
|
28 | - */ |
|
29 | - protected static function getFiles($file) |
|
30 | - { |
|
31 | - if (empty($file)) { |
|
32 | - throw new InvalidArgumentException('There is not any file defined'); |
|
33 | - } |
|
22 | + /** |
|
23 | + * Checks and returns all files. |
|
24 | + * |
|
25 | + * @param string|array $file The file/s |
|
26 | + * |
|
27 | + * @return array The file paths |
|
28 | + */ |
|
29 | + protected static function getFiles($file) |
|
30 | + { |
|
31 | + if (empty($file)) { |
|
32 | + throw new InvalidArgumentException('There is not any file defined'); |
|
33 | + } |
|
34 | 34 | |
35 | - if (is_string($file)) { |
|
36 | - if (!is_file($file)) { |
|
37 | - throw new InvalidArgumentException("'$file' is not a valid file"); |
|
38 | - } |
|
35 | + if (is_string($file)) { |
|
36 | + if (!is_file($file)) { |
|
37 | + throw new InvalidArgumentException("'$file' is not a valid file"); |
|
38 | + } |
|
39 | 39 | |
40 | - if (!is_readable($file)) { |
|
41 | - throw new InvalidArgumentException("'$file' is not a readable file"); |
|
42 | - } |
|
40 | + if (!is_readable($file)) { |
|
41 | + throw new InvalidArgumentException("'$file' is not a readable file"); |
|
42 | + } |
|
43 | 43 | |
44 | - return [$file]; |
|
45 | - } |
|
44 | + return [$file]; |
|
45 | + } |
|
46 | 46 | |
47 | - if (is_array($file)) { |
|
48 | - $files = []; |
|
47 | + if (is_array($file)) { |
|
48 | + $files = []; |
|
49 | 49 | |
50 | - foreach ($file as $f) { |
|
51 | - $files = array_merge($files, static::getFiles($f)); |
|
52 | - } |
|
50 | + foreach ($file as $f) { |
|
51 | + $files = array_merge($files, static::getFiles($f)); |
|
52 | + } |
|
53 | 53 | |
54 | - return $files; |
|
55 | - } |
|
54 | + return $files; |
|
55 | + } |
|
56 | 56 | |
57 | - throw new InvalidArgumentException('The first argument must be string or array'); |
|
58 | - } |
|
57 | + throw new InvalidArgumentException('The first argument must be string or array'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Reads and returns the content of a file. |
|
62 | - * |
|
63 | - * @param string $file |
|
64 | - * |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - protected static function readFile($file) |
|
68 | - { |
|
69 | - $length = filesize($file); |
|
60 | + /** |
|
61 | + * Reads and returns the content of a file. |
|
62 | + * |
|
63 | + * @param string $file |
|
64 | + * |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + protected static function readFile($file) |
|
68 | + { |
|
69 | + $length = filesize($file); |
|
70 | 70 | |
71 | - if (!($fd = fopen($file, 'rb'))) { |
|
72 | - throw new Exception("Cannot read the file '$file', probably permissions"); |
|
73 | - } |
|
71 | + if (!($fd = fopen($file, 'rb'))) { |
|
72 | + throw new Exception("Cannot read the file '$file', probably permissions"); |
|
73 | + } |
|
74 | 74 | |
75 | - $content = $length ? fread($fd, $length) : ''; |
|
76 | - fclose($fd); |
|
75 | + $content = $length ? fread($fd, $length) : ''; |
|
76 | + fclose($fd); |
|
77 | 77 | |
78 | - return $content; |
|
79 | - } |
|
78 | + return $content; |
|
79 | + } |
|
80 | 80 | } |
@@ -11,11 +11,11 @@ discard block |
||
11 | 11 | /** |
12 | 12 | * {@inheritdoc} |
13 | 13 | */ |
14 | - public static function fromFile($file, Translations $translations, array $options = []) |
|
14 | + public static function fromFile( $file, Translations $translations, array $options = [ ] ) |
|
15 | 15 | { |
16 | - foreach (static::getFiles($file) as $file) { |
|
17 | - $options['file'] = $file; |
|
18 | - static::fromString(static::readFile($file), $translations, $options); |
|
16 | + foreach ( static::getFiles( $file ) as $file ) { |
|
17 | + $options[ 'file' ] = $file; |
|
18 | + static::fromString( static::readFile( $file ), $translations, $options ); |
|
19 | 19 | } |
20 | 20 | } |
21 | 21 | |
@@ -26,35 +26,35 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return array The file paths |
28 | 28 | */ |
29 | - protected static function getFiles($file) |
|
29 | + protected static function getFiles( $file ) |
|
30 | 30 | { |
31 | - if (empty($file)) { |
|
32 | - throw new InvalidArgumentException('There is not any file defined'); |
|
31 | + if ( empty( $file ) ) { |
|
32 | + throw new InvalidArgumentException( 'There is not any file defined' ); |
|
33 | 33 | } |
34 | 34 | |
35 | - if (is_string($file)) { |
|
36 | - if (!is_file($file)) { |
|
37 | - throw new InvalidArgumentException("'$file' is not a valid file"); |
|
35 | + if ( is_string( $file ) ) { |
|
36 | + if ( ! is_file( $file ) ) { |
|
37 | + throw new InvalidArgumentException( "'$file' is not a valid file" ); |
|
38 | 38 | } |
39 | 39 | |
40 | - if (!is_readable($file)) { |
|
41 | - throw new InvalidArgumentException("'$file' is not a readable file"); |
|
40 | + if ( ! is_readable( $file ) ) { |
|
41 | + throw new InvalidArgumentException( "'$file' is not a readable file" ); |
|
42 | 42 | } |
43 | 43 | |
44 | - return [$file]; |
|
44 | + return [ $file ]; |
|
45 | 45 | } |
46 | 46 | |
47 | - if (is_array($file)) { |
|
48 | - $files = []; |
|
47 | + if ( is_array( $file ) ) { |
|
48 | + $files = [ ]; |
|
49 | 49 | |
50 | - foreach ($file as $f) { |
|
51 | - $files = array_merge($files, static::getFiles($f)); |
|
50 | + foreach ( $file as $f ) { |
|
51 | + $files = array_merge( $files, static::getFiles( $f ) ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | return $files; |
55 | 55 | } |
56 | 56 | |
57 | - throw new InvalidArgumentException('The first argument must be string or array'); |
|
57 | + throw new InvalidArgumentException( 'The first argument must be string or array' ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -64,16 +64,16 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return string |
66 | 66 | */ |
67 | - protected static function readFile($file) |
|
67 | + protected static function readFile( $file ) |
|
68 | 68 | { |
69 | - $length = filesize($file); |
|
69 | + $length = filesize( $file ); |
|
70 | 70 | |
71 | - if (!($fd = fopen($file, 'rb'))) { |
|
72 | - throw new Exception("Cannot read the file '$file', probably permissions"); |
|
71 | + if ( ! ( $fd = fopen( $file, 'rb' ) ) ) { |
|
72 | + throw new Exception( "Cannot read the file '$file', probably permissions" ); |
|
73 | 73 | } |
74 | 74 | |
75 | - $content = $length ? fread($fd, $length) : ''; |
|
76 | - fclose($fd); |
|
75 | + $content = $length ? fread( $fd, $length ) : ''; |
|
76 | + fclose( $fd ); |
|
77 | 77 | |
78 | 78 | return $content; |
79 | 79 | } |
@@ -6,13 +6,11 @@ discard block |
||
6 | 6 | use InvalidArgumentException; |
7 | 7 | use Gettext\Translations; |
8 | 8 | |
9 | -abstract class Extractor implements ExtractorInterface |
|
10 | -{ |
|
9 | +abstract class Extractor implements ExtractorInterface { |
|
11 | 10 | /** |
12 | 11 | * {@inheritdoc} |
13 | 12 | */ |
14 | - public static function fromFile($file, Translations $translations, array $options = []) |
|
15 | - { |
|
13 | + public static function fromFile($file, Translations $translations, array $options = []) { |
|
16 | 14 | foreach (static::getFiles($file) as $file) { |
17 | 15 | $options['file'] = $file; |
18 | 16 | static::fromString(static::readFile($file), $translations, $options); |
@@ -26,8 +24,7 @@ discard block |
||
26 | 24 | * |
27 | 25 | * @return array The file paths |
28 | 26 | */ |
29 | - protected static function getFiles($file) |
|
30 | - { |
|
27 | + protected static function getFiles($file) { |
|
31 | 28 | if (empty($file)) { |
32 | 29 | throw new InvalidArgumentException('There is not any file defined'); |
33 | 30 | } |
@@ -64,8 +61,7 @@ discard block |
||
64 | 61 | * |
65 | 62 | * @return string |
66 | 63 | */ |
67 | - protected static function readFile($file) |
|
68 | - { |
|
64 | + protected static function readFile($file) { |
|
69 | 65 | $length = filesize($file); |
70 | 66 | |
71 | 67 | if (!($fd = fopen($file, 'rb'))) { |
@@ -10,17 +10,17 @@ |
||
10 | 10 | */ |
11 | 11 | class Json extends Extractor implements ExtractorInterface |
12 | 12 | { |
13 | - use MultidimensionalArrayTrait; |
|
13 | + use MultidimensionalArrayTrait; |
|
14 | 14 | |
15 | - /** |
|
16 | - * {@inheritdoc} |
|
17 | - */ |
|
18 | - public static function fromString($string, Translations $translations, array $options = []) |
|
19 | - { |
|
20 | - $messages = json_decode($string, true); |
|
15 | + /** |
|
16 | + * {@inheritdoc} |
|
17 | + */ |
|
18 | + public static function fromString($string, Translations $translations, array $options = []) |
|
19 | + { |
|
20 | + $messages = json_decode($string, true); |
|
21 | 21 | |
22 | - if (is_array($messages)) { |
|
23 | - static::fromArray($messages, $translations); |
|
24 | - } |
|
25 | - } |
|
22 | + if (is_array($messages)) { |
|
23 | + static::fromArray($messages, $translations); |
|
24 | + } |
|
25 | + } |
|
26 | 26 | } |
@@ -8,15 +8,13 @@ |
||
8 | 8 | /** |
9 | 9 | * Class to get gettext strings from json. |
10 | 10 | */ |
11 | -class Json extends Extractor implements ExtractorInterface |
|
12 | -{ |
|
11 | +class Json extends Extractor implements ExtractorInterface { |
|
13 | 12 | use MultidimensionalArrayTrait; |
14 | 13 | |
15 | 14 | /** |
16 | 15 | * {@inheritdoc} |
17 | 16 | */ |
18 | - public static function fromString($string, Translations $translations, array $options = []) |
|
19 | - { |
|
17 | + public static function fromString($string, Translations $translations, array $options = []) { |
|
20 | 18 | $messages = json_decode($string, true); |
21 | 19 | |
22 | 20 | if (is_array($messages)) { |
@@ -15,12 +15,12 @@ |
||
15 | 15 | /** |
16 | 16 | * {@inheritdoc} |
17 | 17 | */ |
18 | - public static function fromString($string, Translations $translations, array $options = []) |
|
18 | + public static function fromString( $string, Translations $translations, array $options = [ ] ) |
|
19 | 19 | { |
20 | - $messages = json_decode($string, true); |
|
20 | + $messages = json_decode( $string, true ); |
|
21 | 21 | |
22 | - if (is_array($messages)) { |
|
23 | - static::fromArray($messages, $translations); |
|
22 | + if ( is_array( $messages ) ) { |
|
23 | + static::fromArray( $messages, $translations ); |
|
24 | 24 | } |
25 | 25 | } |
26 | 26 | } |
@@ -11,17 +11,17 @@ |
||
11 | 11 | */ |
12 | 12 | class Yaml extends Extractor implements ExtractorInterface |
13 | 13 | { |
14 | - use MultidimensionalArrayTrait; |
|
14 | + use MultidimensionalArrayTrait; |
|
15 | 15 | |
16 | - /** |
|
17 | - * {@inheritdoc} |
|
18 | - */ |
|
19 | - public static function fromString($string, Translations $translations, array $options = []) |
|
20 | - { |
|
21 | - $messages = YamlParser::parse($string); |
|
16 | + /** |
|
17 | + * {@inheritdoc} |
|
18 | + */ |
|
19 | + public static function fromString($string, Translations $translations, array $options = []) |
|
20 | + { |
|
21 | + $messages = YamlParser::parse($string); |
|
22 | 22 | |
23 | - if (is_array($messages)) { |
|
24 | - static::fromArray($messages, $translations); |
|
25 | - } |
|
26 | - } |
|
23 | + if (is_array($messages)) { |
|
24 | + static::fromArray($messages, $translations); |
|
25 | + } |
|
26 | + } |
|
27 | 27 | } |
@@ -9,15 +9,13 @@ |
||
9 | 9 | /** |
10 | 10 | * Class to get gettext strings from yaml. |
11 | 11 | */ |
12 | -class Yaml extends Extractor implements ExtractorInterface |
|
13 | -{ |
|
12 | +class Yaml extends Extractor implements ExtractorInterface { |
|
14 | 13 | use MultidimensionalArrayTrait; |
15 | 14 | |
16 | 15 | /** |
17 | 16 | * {@inheritdoc} |
18 | 17 | */ |
19 | - public static function fromString($string, Translations $translations, array $options = []) |
|
20 | - { |
|
18 | + public static function fromString($string, Translations $translations, array $options = []) { |
|
21 | 19 | $messages = YamlParser::parse($string); |
22 | 20 | |
23 | 21 | if (is_array($messages)) { |
@@ -16,12 +16,12 @@ |
||
16 | 16 | /** |
17 | 17 | * {@inheritdoc} |
18 | 18 | */ |
19 | - public static function fromString($string, Translations $translations, array $options = []) |
|
19 | + public static function fromString( $string, Translations $translations, array $options = [ ] ) |
|
20 | 20 | { |
21 | - $messages = YamlParser::parse($string); |
|
21 | + $messages = YamlParser::parse( $string ); |
|
22 | 22 | |
23 | - if (is_array($messages)) { |
|
24 | - static::fromArray($messages, $translations); |
|
23 | + if ( is_array( $messages ) ) { |
|
24 | + static::fromArray( $messages, $translations ); |
|
25 | 25 | } |
26 | 26 | } |
27 | 27 | } |
@@ -6,23 +6,23 @@ |
||
6 | 6 | |
7 | 7 | interface ExtractorMultiInterface |
8 | 8 | { |
9 | - /** |
|
10 | - * Parses a string and append the translations found in the Translations instance. |
|
11 | - * Allows scanning for multiple domains at a time (each Translation has to have a different domain) |
|
12 | - * |
|
13 | - * @param string $string |
|
14 | - * @param Translations[] $translations |
|
15 | - * @param array $options |
|
16 | - */ |
|
17 | - public static function fromStringMultiple($string, array $translations, array $options = []); |
|
9 | + /** |
|
10 | + * Parses a string and append the translations found in the Translations instance. |
|
11 | + * Allows scanning for multiple domains at a time (each Translation has to have a different domain) |
|
12 | + * |
|
13 | + * @param string $string |
|
14 | + * @param Translations[] $translations |
|
15 | + * @param array $options |
|
16 | + */ |
|
17 | + public static function fromStringMultiple($string, array $translations, array $options = []); |
|
18 | 18 | |
19 | - /** |
|
20 | - * Parses a string and append the translations found in the Translations instance. |
|
21 | - * Allows scanning for multiple domains at a time (each Translation has to have a different domain) |
|
22 | - * |
|
23 | - * @param $file |
|
24 | - * @param Translations[] $translations |
|
25 | - * @param array $options |
|
26 | - */ |
|
27 | - public static function fromFileMultiple($file, array $translations, array $options = []); |
|
19 | + /** |
|
20 | + * Parses a string and append the translations found in the Translations instance. |
|
21 | + * Allows scanning for multiple domains at a time (each Translation has to have a different domain) |
|
22 | + * |
|
23 | + * @param $file |
|
24 | + * @param Translations[] $translations |
|
25 | + * @param array $options |
|
26 | + */ |
|
27 | + public static function fromFileMultiple($file, array $translations, array $options = []); |
|
28 | 28 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * @param Translations[] $translations |
15 | 15 | * @param array $options |
16 | 16 | */ |
17 | - public static function fromStringMultiple($string, array $translations, array $options = []); |
|
17 | + public static function fromStringMultiple( $string, array $translations, array $options = [ ] ); |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Parses a string and append the translations found in the Translations instance. |
@@ -24,5 +24,5 @@ discard block |
||
24 | 24 | * @param Translations[] $translations |
25 | 25 | * @param array $options |
26 | 26 | */ |
27 | - public static function fromFileMultiple($file, array $translations, array $options = []); |
|
27 | + public static function fromFileMultiple( $file, array $translations, array $options = [ ] ); |
|
28 | 28 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use Gettext\Translations; |
6 | 6 | |
7 | -interface ExtractorMultiInterface |
|
8 | -{ |
|
7 | +interface ExtractorMultiInterface { |
|
9 | 8 | /** |
10 | 9 | * Parses a string and append the translations found in the Translations instance. |
11 | 10 | * Allows scanning for multiple domains at a time (each Translation has to have a different domain) |
@@ -7,531 +7,531 @@ |
||
7 | 7 | */ |
8 | 8 | class Translation |
9 | 9 | { |
10 | - protected $id; |
|
11 | - protected $context; |
|
12 | - protected $original; |
|
13 | - protected $translation = ''; |
|
14 | - protected $plural; |
|
15 | - protected $pluralTranslation = []; |
|
16 | - protected $references = []; |
|
17 | - protected $comments = []; |
|
18 | - protected $extractedComments = []; |
|
19 | - protected $flags = []; |
|
20 | - protected $disabled = false; |
|
21 | - |
|
22 | - /** |
|
23 | - * Generates the id of a translation (context + glue + original). |
|
24 | - * |
|
25 | - * @param string $context |
|
26 | - * @param string $original |
|
27 | - * |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public static function generateId($context, $original) |
|
31 | - { |
|
32 | - return "{$context}\004{$original}"; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Create a new instance of a Translation object. |
|
37 | - * |
|
38 | - * This is a factory method that will work even when Translation is extended. |
|
39 | - * |
|
40 | - * @param string $context The context of the translation |
|
41 | - * @param string $original The original string |
|
42 | - * @param string $plural The original plural string |
|
43 | - * @return static New Translation instance |
|
44 | - */ |
|
45 | - public static function create($context, $original, $plural = '') |
|
46 | - { |
|
47 | - return new static($context, $original, $plural); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Construct. |
|
52 | - * |
|
53 | - * @param string $context The context of the translation |
|
54 | - * @param string $original The original string |
|
55 | - * @param string $plural The original plural string |
|
56 | - */ |
|
57 | - public function __construct($context, $original, $plural = '') |
|
58 | - { |
|
59 | - $this->context = (string) $context; |
|
60 | - $this->original = (string) $original; |
|
61 | - |
|
62 | - $this->setPlural($plural); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Clones this translation. |
|
67 | - * |
|
68 | - * @param null|string $context Optional new context |
|
69 | - * @param null|string $original Optional new original |
|
70 | - * |
|
71 | - * @return Translation |
|
72 | - */ |
|
73 | - public function getClone($context = null, $original = null) |
|
74 | - { |
|
75 | - $new = clone $this; |
|
76 | - |
|
77 | - if ($context !== null) { |
|
78 | - $new->context = (string) $context; |
|
79 | - } |
|
80 | - |
|
81 | - if ($original !== null) { |
|
82 | - $new->original = (string) $original; |
|
83 | - } |
|
84 | - |
|
85 | - return $new; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Sets the id of this translation. |
|
90 | - * @warning The use of this function to set a custom ID will prevent |
|
91 | - * Translations::find from matching this translation. |
|
92 | - * |
|
93 | - * @param string $id |
|
94 | - */ |
|
95 | - public function setId($id) |
|
96 | - { |
|
97 | - $this->id = $id; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Returns the id of this translation. |
|
103 | - * |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function getId() |
|
107 | - { |
|
108 | - if ($this->id === null) { |
|
109 | - return static::generateId($this->context, $this->original); |
|
110 | - } |
|
111 | - return $this->id; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Checks whether the translation matches with the arguments. |
|
116 | - * |
|
117 | - * @param string $context |
|
118 | - * @param string $original |
|
119 | - * |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function is($context, $original = '') |
|
123 | - { |
|
124 | - return (($this->context === $context) && ($this->original === $original)) ? true : false; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Enable or disable the translation |
|
129 | - * |
|
130 | - * @param bool $disabled |
|
131 | - * |
|
132 | - * @return self |
|
133 | - */ |
|
134 | - public function setDisabled($disabled) |
|
135 | - { |
|
136 | - $this->disabled = (bool) $disabled; |
|
137 | - |
|
138 | - return $this; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Returns whether the translation is disabled |
|
143 | - * |
|
144 | - * @return bool |
|
145 | - */ |
|
146 | - public function isDisabled() |
|
147 | - { |
|
148 | - return $this->disabled; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Gets the original string. |
|
153 | - * |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - public function getOriginal() |
|
157 | - { |
|
158 | - return $this->original; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Checks if the original string is empty or not. |
|
163 | - * |
|
164 | - * @return bool |
|
165 | - */ |
|
166 | - public function hasOriginal() |
|
167 | - { |
|
168 | - return ($this->original !== '') ? true : false; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Sets the translation string. |
|
173 | - * |
|
174 | - * @param string $translation |
|
175 | - * |
|
176 | - * @return self |
|
177 | - */ |
|
178 | - public function setTranslation($translation) |
|
179 | - { |
|
180 | - $this->translation = (string) $translation; |
|
181 | - |
|
182 | - return $this; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Gets the translation string. |
|
187 | - * |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - public function getTranslation() |
|
191 | - { |
|
192 | - return $this->translation; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Checks if the translation string is empty or not. |
|
197 | - * |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function hasTranslation() |
|
201 | - { |
|
202 | - return ($this->translation !== '') ? true : false; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Sets the plural translation string. |
|
207 | - * |
|
208 | - * @param string $plural |
|
209 | - * |
|
210 | - * @return self |
|
211 | - */ |
|
212 | - public function setPlural($plural) |
|
213 | - { |
|
214 | - $this->plural = (string) $plural; |
|
215 | - |
|
216 | - return $this; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Gets the plural translation string. |
|
221 | - * |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - public function getPlural() |
|
225 | - { |
|
226 | - return $this->plural; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Checks if the plural translation string is empty or not. |
|
231 | - * |
|
232 | - * @return bool |
|
233 | - */ |
|
234 | - public function hasPlural() |
|
235 | - { |
|
236 | - return ($this->plural !== '') ? true : false; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Set a new plural translation. |
|
241 | - * |
|
242 | - * @param array $plural |
|
243 | - * |
|
244 | - * @return self |
|
245 | - */ |
|
246 | - public function setPluralTranslations(array $plural) |
|
247 | - { |
|
248 | - $this->pluralTranslation = $plural; |
|
249 | - |
|
250 | - return $this; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Gets all plural translations. |
|
255 | - * |
|
256 | - * @param int $size |
|
257 | - * |
|
258 | - * @return array |
|
259 | - */ |
|
260 | - public function getPluralTranslations($size = null) |
|
261 | - { |
|
262 | - if ($size === null) { |
|
263 | - return $this->pluralTranslation; |
|
264 | - } |
|
265 | - |
|
266 | - $current = count($this->pluralTranslation); |
|
267 | - |
|
268 | - if ($size > $current) { |
|
269 | - return $this->pluralTranslation + array_fill(0, $size, ''); |
|
270 | - } |
|
271 | - |
|
272 | - if ($size < $current) { |
|
273 | - return array_slice($this->pluralTranslation, 0, $size); |
|
274 | - } |
|
275 | - |
|
276 | - return $this->pluralTranslation; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Checks if there are any plural translation. |
|
281 | - * |
|
282 | - * @param bool $checkContent |
|
283 | - * |
|
284 | - * @return bool |
|
285 | - */ |
|
286 | - public function hasPluralTranslations($checkContent = false) |
|
287 | - { |
|
288 | - if ($checkContent) { |
|
289 | - return implode('', $this->pluralTranslation) !== ''; |
|
290 | - } |
|
291 | - |
|
292 | - return !empty($this->pluralTranslation); |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Removes all plural translations. |
|
297 | - * |
|
298 | - * @return self |
|
299 | - */ |
|
300 | - public function deletePluralTranslation() |
|
301 | - { |
|
302 | - $this->pluralTranslation = []; |
|
303 | - |
|
304 | - return $this; |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Gets the context of this translation. |
|
309 | - * |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function getContext() |
|
313 | - { |
|
314 | - return $this->context; |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * Checks if the context is empty or not. |
|
319 | - * |
|
320 | - * @return bool |
|
321 | - */ |
|
322 | - public function hasContext() |
|
323 | - { |
|
324 | - return (isset($this->context) && ($this->context !== '')) ? true : false; |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Adds a new reference for this translation. |
|
329 | - * |
|
330 | - * @param string $filename The file path where the translation has been found |
|
331 | - * @param null|int $line The line number where the translation has been found |
|
332 | - * |
|
333 | - * @return self |
|
334 | - */ |
|
335 | - public function addReference($filename, $line = null) |
|
336 | - { |
|
337 | - $key = "{$filename}:{$line}"; |
|
338 | - $this->references[$key] = [$filename, $line]; |
|
339 | - |
|
340 | - return $this; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Checks if the translation has any reference. |
|
345 | - * |
|
346 | - * @return bool |
|
347 | - */ |
|
348 | - public function hasReferences() |
|
349 | - { |
|
350 | - return !empty($this->references); |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Return all references for this translation. |
|
355 | - * |
|
356 | - * @return array |
|
357 | - */ |
|
358 | - public function getReferences() |
|
359 | - { |
|
360 | - return array_values($this->references); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Removes all references. |
|
365 | - * |
|
366 | - * @return self |
|
367 | - */ |
|
368 | - public function deleteReferences() |
|
369 | - { |
|
370 | - $this->references = []; |
|
371 | - |
|
372 | - return $this; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Adds a new comment for this translation. |
|
377 | - * |
|
378 | - * @param string $comment |
|
379 | - * |
|
380 | - * @return self |
|
381 | - */ |
|
382 | - public function addComment($comment) |
|
383 | - { |
|
384 | - if (!in_array($comment, $this->comments, true)) { |
|
385 | - $this->comments[] = $comment; |
|
386 | - } |
|
387 | - |
|
388 | - return $this; |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Checks if the translation has any comment. |
|
393 | - * |
|
394 | - * @return bool |
|
395 | - */ |
|
396 | - public function hasComments() |
|
397 | - { |
|
398 | - return isset($this->comments[0]); |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Returns all comments for this translation. |
|
403 | - * |
|
404 | - * @return array |
|
405 | - */ |
|
406 | - public function getComments() |
|
407 | - { |
|
408 | - return $this->comments; |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Removes all comments. |
|
413 | - * |
|
414 | - * @return self |
|
415 | - */ |
|
416 | - public function deleteComments() |
|
417 | - { |
|
418 | - $this->comments = []; |
|
419 | - |
|
420 | - return $this; |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Adds a new extracted comment for this translation. |
|
425 | - * |
|
426 | - * @param string $comment |
|
427 | - * |
|
428 | - * @return self |
|
429 | - */ |
|
430 | - public function addExtractedComment($comment) |
|
431 | - { |
|
432 | - if (!in_array($comment, $this->extractedComments, true)) { |
|
433 | - $this->extractedComments[] = $comment; |
|
434 | - } |
|
435 | - |
|
436 | - return $this; |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * Checks if the translation has any extracted comment. |
|
441 | - * |
|
442 | - * @return bool |
|
443 | - */ |
|
444 | - public function hasExtractedComments() |
|
445 | - { |
|
446 | - return isset($this->extractedComments[0]); |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * Returns all extracted comments for this translation. |
|
451 | - * |
|
452 | - * @return array |
|
453 | - */ |
|
454 | - public function getExtractedComments() |
|
455 | - { |
|
456 | - return $this->extractedComments; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Removes all extracted comments. |
|
461 | - * |
|
462 | - * @return self |
|
463 | - */ |
|
464 | - public function deleteExtractedComments() |
|
465 | - { |
|
466 | - $this->extractedComments = []; |
|
467 | - |
|
468 | - return $this; |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * Adds a new flag for this translation. |
|
473 | - * |
|
474 | - * @param string $flag |
|
475 | - * |
|
476 | - * @return self |
|
477 | - */ |
|
478 | - public function addFlag($flag) |
|
479 | - { |
|
480 | - if (!in_array($flag, $this->flags, true)) { |
|
481 | - $this->flags[] = $flag; |
|
482 | - } |
|
483 | - |
|
484 | - return $this; |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * Checks if the translation has any flag. |
|
489 | - * |
|
490 | - * @return bool |
|
491 | - */ |
|
492 | - public function hasFlags() |
|
493 | - { |
|
494 | - return isset($this->flags[0]); |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * Returns all extracted flags for this translation. |
|
499 | - * |
|
500 | - * @return array |
|
501 | - */ |
|
502 | - public function getFlags() |
|
503 | - { |
|
504 | - return $this->flags; |
|
505 | - } |
|
506 | - |
|
507 | - /** |
|
508 | - * Removes all flags. |
|
509 | - * |
|
510 | - * @return self |
|
511 | - */ |
|
512 | - public function deleteFlags() |
|
513 | - { |
|
514 | - $this->flags = []; |
|
515 | - |
|
516 | - return $this; |
|
517 | - } |
|
518 | - |
|
519 | - /** |
|
520 | - * Merges this translation with other translation. |
|
521 | - * |
|
522 | - * @param Translation $translation The translation to merge with |
|
523 | - * @param int $options |
|
524 | - * |
|
525 | - * @return self |
|
526 | - */ |
|
527 | - public function mergeWith(Translation $translation, $options = Merge::DEFAULTS) |
|
528 | - { |
|
529 | - Merge::mergeTranslation($translation, $this, $options); |
|
530 | - Merge::mergeReferences($translation, $this, $options); |
|
531 | - Merge::mergeComments($translation, $this, $options); |
|
532 | - Merge::mergeExtractedComments($translation, $this, $options); |
|
533 | - Merge::mergeFlags($translation, $this, $options); |
|
534 | - |
|
535 | - return $this; |
|
536 | - } |
|
10 | + protected $id; |
|
11 | + protected $context; |
|
12 | + protected $original; |
|
13 | + protected $translation = ''; |
|
14 | + protected $plural; |
|
15 | + protected $pluralTranslation = []; |
|
16 | + protected $references = []; |
|
17 | + protected $comments = []; |
|
18 | + protected $extractedComments = []; |
|
19 | + protected $flags = []; |
|
20 | + protected $disabled = false; |
|
21 | + |
|
22 | + /** |
|
23 | + * Generates the id of a translation (context + glue + original). |
|
24 | + * |
|
25 | + * @param string $context |
|
26 | + * @param string $original |
|
27 | + * |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public static function generateId($context, $original) |
|
31 | + { |
|
32 | + return "{$context}\004{$original}"; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Create a new instance of a Translation object. |
|
37 | + * |
|
38 | + * This is a factory method that will work even when Translation is extended. |
|
39 | + * |
|
40 | + * @param string $context The context of the translation |
|
41 | + * @param string $original The original string |
|
42 | + * @param string $plural The original plural string |
|
43 | + * @return static New Translation instance |
|
44 | + */ |
|
45 | + public static function create($context, $original, $plural = '') |
|
46 | + { |
|
47 | + return new static($context, $original, $plural); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Construct. |
|
52 | + * |
|
53 | + * @param string $context The context of the translation |
|
54 | + * @param string $original The original string |
|
55 | + * @param string $plural The original plural string |
|
56 | + */ |
|
57 | + public function __construct($context, $original, $plural = '') |
|
58 | + { |
|
59 | + $this->context = (string) $context; |
|
60 | + $this->original = (string) $original; |
|
61 | + |
|
62 | + $this->setPlural($plural); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Clones this translation. |
|
67 | + * |
|
68 | + * @param null|string $context Optional new context |
|
69 | + * @param null|string $original Optional new original |
|
70 | + * |
|
71 | + * @return Translation |
|
72 | + */ |
|
73 | + public function getClone($context = null, $original = null) |
|
74 | + { |
|
75 | + $new = clone $this; |
|
76 | + |
|
77 | + if ($context !== null) { |
|
78 | + $new->context = (string) $context; |
|
79 | + } |
|
80 | + |
|
81 | + if ($original !== null) { |
|
82 | + $new->original = (string) $original; |
|
83 | + } |
|
84 | + |
|
85 | + return $new; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Sets the id of this translation. |
|
90 | + * @warning The use of this function to set a custom ID will prevent |
|
91 | + * Translations::find from matching this translation. |
|
92 | + * |
|
93 | + * @param string $id |
|
94 | + */ |
|
95 | + public function setId($id) |
|
96 | + { |
|
97 | + $this->id = $id; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Returns the id of this translation. |
|
103 | + * |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function getId() |
|
107 | + { |
|
108 | + if ($this->id === null) { |
|
109 | + return static::generateId($this->context, $this->original); |
|
110 | + } |
|
111 | + return $this->id; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Checks whether the translation matches with the arguments. |
|
116 | + * |
|
117 | + * @param string $context |
|
118 | + * @param string $original |
|
119 | + * |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function is($context, $original = '') |
|
123 | + { |
|
124 | + return (($this->context === $context) && ($this->original === $original)) ? true : false; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Enable or disable the translation |
|
129 | + * |
|
130 | + * @param bool $disabled |
|
131 | + * |
|
132 | + * @return self |
|
133 | + */ |
|
134 | + public function setDisabled($disabled) |
|
135 | + { |
|
136 | + $this->disabled = (bool) $disabled; |
|
137 | + |
|
138 | + return $this; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Returns whether the translation is disabled |
|
143 | + * |
|
144 | + * @return bool |
|
145 | + */ |
|
146 | + public function isDisabled() |
|
147 | + { |
|
148 | + return $this->disabled; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Gets the original string. |
|
153 | + * |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + public function getOriginal() |
|
157 | + { |
|
158 | + return $this->original; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Checks if the original string is empty or not. |
|
163 | + * |
|
164 | + * @return bool |
|
165 | + */ |
|
166 | + public function hasOriginal() |
|
167 | + { |
|
168 | + return ($this->original !== '') ? true : false; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Sets the translation string. |
|
173 | + * |
|
174 | + * @param string $translation |
|
175 | + * |
|
176 | + * @return self |
|
177 | + */ |
|
178 | + public function setTranslation($translation) |
|
179 | + { |
|
180 | + $this->translation = (string) $translation; |
|
181 | + |
|
182 | + return $this; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Gets the translation string. |
|
187 | + * |
|
188 | + * @return string |
|
189 | + */ |
|
190 | + public function getTranslation() |
|
191 | + { |
|
192 | + return $this->translation; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Checks if the translation string is empty or not. |
|
197 | + * |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function hasTranslation() |
|
201 | + { |
|
202 | + return ($this->translation !== '') ? true : false; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Sets the plural translation string. |
|
207 | + * |
|
208 | + * @param string $plural |
|
209 | + * |
|
210 | + * @return self |
|
211 | + */ |
|
212 | + public function setPlural($plural) |
|
213 | + { |
|
214 | + $this->plural = (string) $plural; |
|
215 | + |
|
216 | + return $this; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Gets the plural translation string. |
|
221 | + * |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + public function getPlural() |
|
225 | + { |
|
226 | + return $this->plural; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Checks if the plural translation string is empty or not. |
|
231 | + * |
|
232 | + * @return bool |
|
233 | + */ |
|
234 | + public function hasPlural() |
|
235 | + { |
|
236 | + return ($this->plural !== '') ? true : false; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Set a new plural translation. |
|
241 | + * |
|
242 | + * @param array $plural |
|
243 | + * |
|
244 | + * @return self |
|
245 | + */ |
|
246 | + public function setPluralTranslations(array $plural) |
|
247 | + { |
|
248 | + $this->pluralTranslation = $plural; |
|
249 | + |
|
250 | + return $this; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Gets all plural translations. |
|
255 | + * |
|
256 | + * @param int $size |
|
257 | + * |
|
258 | + * @return array |
|
259 | + */ |
|
260 | + public function getPluralTranslations($size = null) |
|
261 | + { |
|
262 | + if ($size === null) { |
|
263 | + return $this->pluralTranslation; |
|
264 | + } |
|
265 | + |
|
266 | + $current = count($this->pluralTranslation); |
|
267 | + |
|
268 | + if ($size > $current) { |
|
269 | + return $this->pluralTranslation + array_fill(0, $size, ''); |
|
270 | + } |
|
271 | + |
|
272 | + if ($size < $current) { |
|
273 | + return array_slice($this->pluralTranslation, 0, $size); |
|
274 | + } |
|
275 | + |
|
276 | + return $this->pluralTranslation; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Checks if there are any plural translation. |
|
281 | + * |
|
282 | + * @param bool $checkContent |
|
283 | + * |
|
284 | + * @return bool |
|
285 | + */ |
|
286 | + public function hasPluralTranslations($checkContent = false) |
|
287 | + { |
|
288 | + if ($checkContent) { |
|
289 | + return implode('', $this->pluralTranslation) !== ''; |
|
290 | + } |
|
291 | + |
|
292 | + return !empty($this->pluralTranslation); |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Removes all plural translations. |
|
297 | + * |
|
298 | + * @return self |
|
299 | + */ |
|
300 | + public function deletePluralTranslation() |
|
301 | + { |
|
302 | + $this->pluralTranslation = []; |
|
303 | + |
|
304 | + return $this; |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Gets the context of this translation. |
|
309 | + * |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function getContext() |
|
313 | + { |
|
314 | + return $this->context; |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * Checks if the context is empty or not. |
|
319 | + * |
|
320 | + * @return bool |
|
321 | + */ |
|
322 | + public function hasContext() |
|
323 | + { |
|
324 | + return (isset($this->context) && ($this->context !== '')) ? true : false; |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Adds a new reference for this translation. |
|
329 | + * |
|
330 | + * @param string $filename The file path where the translation has been found |
|
331 | + * @param null|int $line The line number where the translation has been found |
|
332 | + * |
|
333 | + * @return self |
|
334 | + */ |
|
335 | + public function addReference($filename, $line = null) |
|
336 | + { |
|
337 | + $key = "{$filename}:{$line}"; |
|
338 | + $this->references[$key] = [$filename, $line]; |
|
339 | + |
|
340 | + return $this; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Checks if the translation has any reference. |
|
345 | + * |
|
346 | + * @return bool |
|
347 | + */ |
|
348 | + public function hasReferences() |
|
349 | + { |
|
350 | + return !empty($this->references); |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Return all references for this translation. |
|
355 | + * |
|
356 | + * @return array |
|
357 | + */ |
|
358 | + public function getReferences() |
|
359 | + { |
|
360 | + return array_values($this->references); |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Removes all references. |
|
365 | + * |
|
366 | + * @return self |
|
367 | + */ |
|
368 | + public function deleteReferences() |
|
369 | + { |
|
370 | + $this->references = []; |
|
371 | + |
|
372 | + return $this; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Adds a new comment for this translation. |
|
377 | + * |
|
378 | + * @param string $comment |
|
379 | + * |
|
380 | + * @return self |
|
381 | + */ |
|
382 | + public function addComment($comment) |
|
383 | + { |
|
384 | + if (!in_array($comment, $this->comments, true)) { |
|
385 | + $this->comments[] = $comment; |
|
386 | + } |
|
387 | + |
|
388 | + return $this; |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Checks if the translation has any comment. |
|
393 | + * |
|
394 | + * @return bool |
|
395 | + */ |
|
396 | + public function hasComments() |
|
397 | + { |
|
398 | + return isset($this->comments[0]); |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Returns all comments for this translation. |
|
403 | + * |
|
404 | + * @return array |
|
405 | + */ |
|
406 | + public function getComments() |
|
407 | + { |
|
408 | + return $this->comments; |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Removes all comments. |
|
413 | + * |
|
414 | + * @return self |
|
415 | + */ |
|
416 | + public function deleteComments() |
|
417 | + { |
|
418 | + $this->comments = []; |
|
419 | + |
|
420 | + return $this; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Adds a new extracted comment for this translation. |
|
425 | + * |
|
426 | + * @param string $comment |
|
427 | + * |
|
428 | + * @return self |
|
429 | + */ |
|
430 | + public function addExtractedComment($comment) |
|
431 | + { |
|
432 | + if (!in_array($comment, $this->extractedComments, true)) { |
|
433 | + $this->extractedComments[] = $comment; |
|
434 | + } |
|
435 | + |
|
436 | + return $this; |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * Checks if the translation has any extracted comment. |
|
441 | + * |
|
442 | + * @return bool |
|
443 | + */ |
|
444 | + public function hasExtractedComments() |
|
445 | + { |
|
446 | + return isset($this->extractedComments[0]); |
|
447 | + } |
|
448 | + |
|
449 | + /** |
|
450 | + * Returns all extracted comments for this translation. |
|
451 | + * |
|
452 | + * @return array |
|
453 | + */ |
|
454 | + public function getExtractedComments() |
|
455 | + { |
|
456 | + return $this->extractedComments; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Removes all extracted comments. |
|
461 | + * |
|
462 | + * @return self |
|
463 | + */ |
|
464 | + public function deleteExtractedComments() |
|
465 | + { |
|
466 | + $this->extractedComments = []; |
|
467 | + |
|
468 | + return $this; |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * Adds a new flag for this translation. |
|
473 | + * |
|
474 | + * @param string $flag |
|
475 | + * |
|
476 | + * @return self |
|
477 | + */ |
|
478 | + public function addFlag($flag) |
|
479 | + { |
|
480 | + if (!in_array($flag, $this->flags, true)) { |
|
481 | + $this->flags[] = $flag; |
|
482 | + } |
|
483 | + |
|
484 | + return $this; |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * Checks if the translation has any flag. |
|
489 | + * |
|
490 | + * @return bool |
|
491 | + */ |
|
492 | + public function hasFlags() |
|
493 | + { |
|
494 | + return isset($this->flags[0]); |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * Returns all extracted flags for this translation. |
|
499 | + * |
|
500 | + * @return array |
|
501 | + */ |
|
502 | + public function getFlags() |
|
503 | + { |
|
504 | + return $this->flags; |
|
505 | + } |
|
506 | + |
|
507 | + /** |
|
508 | + * Removes all flags. |
|
509 | + * |
|
510 | + * @return self |
|
511 | + */ |
|
512 | + public function deleteFlags() |
|
513 | + { |
|
514 | + $this->flags = []; |
|
515 | + |
|
516 | + return $this; |
|
517 | + } |
|
518 | + |
|
519 | + /** |
|
520 | + * Merges this translation with other translation. |
|
521 | + * |
|
522 | + * @param Translation $translation The translation to merge with |
|
523 | + * @param int $options |
|
524 | + * |
|
525 | + * @return self |
|
526 | + */ |
|
527 | + public function mergeWith(Translation $translation, $options = Merge::DEFAULTS) |
|
528 | + { |
|
529 | + Merge::mergeTranslation($translation, $this, $options); |
|
530 | + Merge::mergeReferences($translation, $this, $options); |
|
531 | + Merge::mergeComments($translation, $this, $options); |
|
532 | + Merge::mergeExtractedComments($translation, $this, $options); |
|
533 | + Merge::mergeFlags($translation, $this, $options); |
|
534 | + |
|
535 | + return $this; |
|
536 | + } |
|
537 | 537 | } |
@@ -12,11 +12,11 @@ discard block |
||
12 | 12 | protected $original; |
13 | 13 | protected $translation = ''; |
14 | 14 | protected $plural; |
15 | - protected $pluralTranslation = []; |
|
16 | - protected $references = []; |
|
17 | - protected $comments = []; |
|
18 | - protected $extractedComments = []; |
|
19 | - protected $flags = []; |
|
15 | + protected $pluralTranslation = [ ]; |
|
16 | + protected $references = [ ]; |
|
17 | + protected $comments = [ ]; |
|
18 | + protected $extractedComments = [ ]; |
|
19 | + protected $flags = [ ]; |
|
20 | 20 | protected $disabled = false; |
21 | 21 | |
22 | 22 | /** |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @return string |
29 | 29 | */ |
30 | - public static function generateId($context, $original) |
|
30 | + public static function generateId( $context, $original ) |
|
31 | 31 | { |
32 | 32 | return "{$context}\004{$original}"; |
33 | 33 | } |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * @param string $plural The original plural string |
43 | 43 | * @return static New Translation instance |
44 | 44 | */ |
45 | - public static function create($context, $original, $plural = '') |
|
45 | + public static function create( $context, $original, $plural = '' ) |
|
46 | 46 | { |
47 | - return new static($context, $original, $plural); |
|
47 | + return new static( $context, $original, $plural ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | * @param string $original The original string |
55 | 55 | * @param string $plural The original plural string |
56 | 56 | */ |
57 | - public function __construct($context, $original, $plural = '') |
|
57 | + public function __construct( $context, $original, $plural = '' ) |
|
58 | 58 | { |
59 | - $this->context = (string) $context; |
|
60 | - $this->original = (string) $original; |
|
59 | + $this->context = (string)$context; |
|
60 | + $this->original = (string)$original; |
|
61 | 61 | |
62 | - $this->setPlural($plural); |
|
62 | + $this->setPlural( $plural ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -70,16 +70,16 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return Translation |
72 | 72 | */ |
73 | - public function getClone($context = null, $original = null) |
|
73 | + public function getClone( $context = null, $original = null ) |
|
74 | 74 | { |
75 | 75 | $new = clone $this; |
76 | 76 | |
77 | - if ($context !== null) { |
|
78 | - $new->context = (string) $context; |
|
77 | + if ( $context !== null ) { |
|
78 | + $new->context = (string)$context; |
|
79 | 79 | } |
80 | 80 | |
81 | - if ($original !== null) { |
|
82 | - $new->original = (string) $original; |
|
81 | + if ( $original !== null ) { |
|
82 | + $new->original = (string)$original; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | return $new; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @param string $id |
94 | 94 | */ |
95 | - public function setId($id) |
|
95 | + public function setId( $id ) |
|
96 | 96 | { |
97 | 97 | $this->id = $id; |
98 | 98 | } |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function getId() |
107 | 107 | { |
108 | - if ($this->id === null) { |
|
109 | - return static::generateId($this->context, $this->original); |
|
108 | + if ( $this->id === null ) { |
|
109 | + return static::generateId( $this->context, $this->original ); |
|
110 | 110 | } |
111 | 111 | return $this->id; |
112 | 112 | } |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return bool |
121 | 121 | */ |
122 | - public function is($context, $original = '') |
|
122 | + public function is( $context, $original = '' ) |
|
123 | 123 | { |
124 | - return (($this->context === $context) && ($this->original === $original)) ? true : false; |
|
124 | + return ( ( $this->context === $context ) && ( $this->original === $original ) ) ? true : false; |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return self |
133 | 133 | */ |
134 | - public function setDisabled($disabled) |
|
134 | + public function setDisabled( $disabled ) |
|
135 | 135 | { |
136 | - $this->disabled = (bool) $disabled; |
|
136 | + $this->disabled = (bool)$disabled; |
|
137 | 137 | |
138 | 138 | return $this; |
139 | 139 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function hasOriginal() |
167 | 167 | { |
168 | - return ($this->original !== '') ? true : false; |
|
168 | + return ( $this->original !== '' ) ? true : false; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return self |
177 | 177 | */ |
178 | - public function setTranslation($translation) |
|
178 | + public function setTranslation( $translation ) |
|
179 | 179 | { |
180 | - $this->translation = (string) $translation; |
|
180 | + $this->translation = (string)$translation; |
|
181 | 181 | |
182 | 182 | return $this; |
183 | 183 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function hasTranslation() |
201 | 201 | { |
202 | - return ($this->translation !== '') ? true : false; |
|
202 | + return ( $this->translation !== '' ) ? true : false; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | * |
210 | 210 | * @return self |
211 | 211 | */ |
212 | - public function setPlural($plural) |
|
212 | + public function setPlural( $plural ) |
|
213 | 213 | { |
214 | - $this->plural = (string) $plural; |
|
214 | + $this->plural = (string)$plural; |
|
215 | 215 | |
216 | 216 | return $this; |
217 | 217 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public function hasPlural() |
235 | 235 | { |
236 | - return ($this->plural !== '') ? true : false; |
|
236 | + return ( $this->plural !== '' ) ? true : false; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * |
244 | 244 | * @return self |
245 | 245 | */ |
246 | - public function setPluralTranslations(array $plural) |
|
246 | + public function setPluralTranslations( array $plural ) |
|
247 | 247 | { |
248 | 248 | $this->pluralTranslation = $plural; |
249 | 249 | |
@@ -257,20 +257,20 @@ discard block |
||
257 | 257 | * |
258 | 258 | * @return array |
259 | 259 | */ |
260 | - public function getPluralTranslations($size = null) |
|
260 | + public function getPluralTranslations( $size = null ) |
|
261 | 261 | { |
262 | - if ($size === null) { |
|
262 | + if ( $size === null ) { |
|
263 | 263 | return $this->pluralTranslation; |
264 | 264 | } |
265 | 265 | |
266 | - $current = count($this->pluralTranslation); |
|
266 | + $current = count( $this->pluralTranslation ); |
|
267 | 267 | |
268 | - if ($size > $current) { |
|
269 | - return $this->pluralTranslation + array_fill(0, $size, ''); |
|
268 | + if ( $size > $current ) { |
|
269 | + return $this->pluralTranslation + array_fill( 0, $size, '' ); |
|
270 | 270 | } |
271 | 271 | |
272 | - if ($size < $current) { |
|
273 | - return array_slice($this->pluralTranslation, 0, $size); |
|
272 | + if ( $size < $current ) { |
|
273 | + return array_slice( $this->pluralTranslation, 0, $size ); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | return $this->pluralTranslation; |
@@ -283,13 +283,13 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @return bool |
285 | 285 | */ |
286 | - public function hasPluralTranslations($checkContent = false) |
|
286 | + public function hasPluralTranslations( $checkContent = false ) |
|
287 | 287 | { |
288 | - if ($checkContent) { |
|
289 | - return implode('', $this->pluralTranslation) !== ''; |
|
288 | + if ( $checkContent ) { |
|
289 | + return implode( '', $this->pluralTranslation ) !== ''; |
|
290 | 290 | } |
291 | 291 | |
292 | - return !empty($this->pluralTranslation); |
|
292 | + return ! empty( $this->pluralTranslation ); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | */ |
300 | 300 | public function deletePluralTranslation() |
301 | 301 | { |
302 | - $this->pluralTranslation = []; |
|
302 | + $this->pluralTranslation = [ ]; |
|
303 | 303 | |
304 | 304 | return $this; |
305 | 305 | } |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function hasContext() |
323 | 323 | { |
324 | - return (isset($this->context) && ($this->context !== '')) ? true : false; |
|
324 | + return ( isset( $this->context ) && ( $this->context !== '' ) ) ? true : false; |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
@@ -332,10 +332,10 @@ discard block |
||
332 | 332 | * |
333 | 333 | * @return self |
334 | 334 | */ |
335 | - public function addReference($filename, $line = null) |
|
335 | + public function addReference( $filename, $line = null ) |
|
336 | 336 | { |
337 | 337 | $key = "{$filename}:{$line}"; |
338 | - $this->references[$key] = [$filename, $line]; |
|
338 | + $this->references[ $key ] = [ $filename, $line ]; |
|
339 | 339 | |
340 | 340 | return $this; |
341 | 341 | } |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | */ |
348 | 348 | public function hasReferences() |
349 | 349 | { |
350 | - return !empty($this->references); |
|
350 | + return ! empty( $this->references ); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | */ |
358 | 358 | public function getReferences() |
359 | 359 | { |
360 | - return array_values($this->references); |
|
360 | + return array_values( $this->references ); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | */ |
368 | 368 | public function deleteReferences() |
369 | 369 | { |
370 | - $this->references = []; |
|
370 | + $this->references = [ ]; |
|
371 | 371 | |
372 | 372 | return $this; |
373 | 373 | } |
@@ -379,10 +379,10 @@ discard block |
||
379 | 379 | * |
380 | 380 | * @return self |
381 | 381 | */ |
382 | - public function addComment($comment) |
|
382 | + public function addComment( $comment ) |
|
383 | 383 | { |
384 | - if (!in_array($comment, $this->comments, true)) { |
|
385 | - $this->comments[] = $comment; |
|
384 | + if ( ! in_array( $comment, $this->comments, true ) ) { |
|
385 | + $this->comments[ ] = $comment; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | return $this; |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | */ |
396 | 396 | public function hasComments() |
397 | 397 | { |
398 | - return isset($this->comments[0]); |
|
398 | + return isset( $this->comments[ 0 ] ); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | */ |
416 | 416 | public function deleteComments() |
417 | 417 | { |
418 | - $this->comments = []; |
|
418 | + $this->comments = [ ]; |
|
419 | 419 | |
420 | 420 | return $this; |
421 | 421 | } |
@@ -427,10 +427,10 @@ discard block |
||
427 | 427 | * |
428 | 428 | * @return self |
429 | 429 | */ |
430 | - public function addExtractedComment($comment) |
|
430 | + public function addExtractedComment( $comment ) |
|
431 | 431 | { |
432 | - if (!in_array($comment, $this->extractedComments, true)) { |
|
433 | - $this->extractedComments[] = $comment; |
|
432 | + if ( ! in_array( $comment, $this->extractedComments, true ) ) { |
|
433 | + $this->extractedComments[ ] = $comment; |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | return $this; |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | */ |
444 | 444 | public function hasExtractedComments() |
445 | 445 | { |
446 | - return isset($this->extractedComments[0]); |
|
446 | + return isset( $this->extractedComments[ 0 ] ); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | */ |
464 | 464 | public function deleteExtractedComments() |
465 | 465 | { |
466 | - $this->extractedComments = []; |
|
466 | + $this->extractedComments = [ ]; |
|
467 | 467 | |
468 | 468 | return $this; |
469 | 469 | } |
@@ -475,10 +475,10 @@ discard block |
||
475 | 475 | * |
476 | 476 | * @return self |
477 | 477 | */ |
478 | - public function addFlag($flag) |
|
478 | + public function addFlag( $flag ) |
|
479 | 479 | { |
480 | - if (!in_array($flag, $this->flags, true)) { |
|
481 | - $this->flags[] = $flag; |
|
480 | + if ( ! in_array( $flag, $this->flags, true ) ) { |
|
481 | + $this->flags[ ] = $flag; |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | return $this; |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | */ |
492 | 492 | public function hasFlags() |
493 | 493 | { |
494 | - return isset($this->flags[0]); |
|
494 | + return isset( $this->flags[ 0 ] ); |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | /** |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | */ |
512 | 512 | public function deleteFlags() |
513 | 513 | { |
514 | - $this->flags = []; |
|
514 | + $this->flags = [ ]; |
|
515 | 515 | |
516 | 516 | return $this; |
517 | 517 | } |
@@ -524,13 +524,13 @@ discard block |
||
524 | 524 | * |
525 | 525 | * @return self |
526 | 526 | */ |
527 | - public function mergeWith(Translation $translation, $options = Merge::DEFAULTS) |
|
527 | + public function mergeWith( Translation $translation, $options = Merge::DEFAULTS ) |
|
528 | 528 | { |
529 | - Merge::mergeTranslation($translation, $this, $options); |
|
530 | - Merge::mergeReferences($translation, $this, $options); |
|
531 | - Merge::mergeComments($translation, $this, $options); |
|
532 | - Merge::mergeExtractedComments($translation, $this, $options); |
|
533 | - Merge::mergeFlags($translation, $this, $options); |
|
529 | + Merge::mergeTranslation( $translation, $this, $options ); |
|
530 | + Merge::mergeReferences( $translation, $this, $options ); |
|
531 | + Merge::mergeComments( $translation, $this, $options ); |
|
532 | + Merge::mergeExtractedComments( $translation, $this, $options ); |
|
533 | + Merge::mergeFlags( $translation, $this, $options ); |
|
534 | 534 | |
535 | 535 | return $this; |
536 | 536 | } |
@@ -5,8 +5,7 @@ discard block |
||
5 | 5 | /** |
6 | 6 | * Class to manage a translation string. |
7 | 7 | */ |
8 | -class Translation |
|
9 | -{ |
|
8 | +class Translation { |
|
10 | 9 | protected $id; |
11 | 10 | protected $context; |
12 | 11 | protected $original; |
@@ -27,8 +26,7 @@ discard block |
||
27 | 26 | * |
28 | 27 | * @return string |
29 | 28 | */ |
30 | - public static function generateId($context, $original) |
|
31 | - { |
|
29 | + public static function generateId($context, $original) { |
|
32 | 30 | return "{$context}\004{$original}"; |
33 | 31 | } |
34 | 32 | |
@@ -42,8 +40,7 @@ discard block |
||
42 | 40 | * @param string $plural The original plural string |
43 | 41 | * @return static New Translation instance |
44 | 42 | */ |
45 | - public static function create($context, $original, $plural = '') |
|
46 | - { |
|
43 | + public static function create($context, $original, $plural = '') { |
|
47 | 44 | return new static($context, $original, $plural); |
48 | 45 | } |
49 | 46 | |
@@ -54,8 +51,7 @@ discard block |
||
54 | 51 | * @param string $original The original string |
55 | 52 | * @param string $plural The original plural string |
56 | 53 | */ |
57 | - public function __construct($context, $original, $plural = '') |
|
58 | - { |
|
54 | + public function __construct($context, $original, $plural = '') { |
|
59 | 55 | $this->context = (string) $context; |
60 | 56 | $this->original = (string) $original; |
61 | 57 | |
@@ -70,8 +66,7 @@ discard block |
||
70 | 66 | * |
71 | 67 | * @return Translation |
72 | 68 | */ |
73 | - public function getClone($context = null, $original = null) |
|
74 | - { |
|
69 | + public function getClone($context = null, $original = null) { |
|
75 | 70 | $new = clone $this; |
76 | 71 | |
77 | 72 | if ($context !== null) { |
@@ -92,8 +87,7 @@ discard block |
||
92 | 87 | * |
93 | 88 | * @param string $id |
94 | 89 | */ |
95 | - public function setId($id) |
|
96 | - { |
|
90 | + public function setId($id) { |
|
97 | 91 | $this->id = $id; |
98 | 92 | } |
99 | 93 | |
@@ -103,8 +97,7 @@ discard block |
||
103 | 97 | * |
104 | 98 | * @return string |
105 | 99 | */ |
106 | - public function getId() |
|
107 | - { |
|
100 | + public function getId() { |
|
108 | 101 | if ($this->id === null) { |
109 | 102 | return static::generateId($this->context, $this->original); |
110 | 103 | } |
@@ -119,8 +112,7 @@ discard block |
||
119 | 112 | * |
120 | 113 | * @return bool |
121 | 114 | */ |
122 | - public function is($context, $original = '') |
|
123 | - { |
|
115 | + public function is($context, $original = '') { |
|
124 | 116 | return (($this->context === $context) && ($this->original === $original)) ? true : false; |
125 | 117 | } |
126 | 118 | |
@@ -131,8 +123,7 @@ discard block |
||
131 | 123 | * |
132 | 124 | * @return self |
133 | 125 | */ |
134 | - public function setDisabled($disabled) |
|
135 | - { |
|
126 | + public function setDisabled($disabled) { |
|
136 | 127 | $this->disabled = (bool) $disabled; |
137 | 128 | |
138 | 129 | return $this; |
@@ -143,8 +134,7 @@ discard block |
||
143 | 134 | * |
144 | 135 | * @return bool |
145 | 136 | */ |
146 | - public function isDisabled() |
|
147 | - { |
|
137 | + public function isDisabled() { |
|
148 | 138 | return $this->disabled; |
149 | 139 | } |
150 | 140 | |
@@ -153,8 +143,7 @@ discard block |
||
153 | 143 | * |
154 | 144 | * @return string |
155 | 145 | */ |
156 | - public function getOriginal() |
|
157 | - { |
|
146 | + public function getOriginal() { |
|
158 | 147 | return $this->original; |
159 | 148 | } |
160 | 149 | |
@@ -163,8 +152,7 @@ discard block |
||
163 | 152 | * |
164 | 153 | * @return bool |
165 | 154 | */ |
166 | - public function hasOriginal() |
|
167 | - { |
|
155 | + public function hasOriginal() { |
|
168 | 156 | return ($this->original !== '') ? true : false; |
169 | 157 | } |
170 | 158 | |
@@ -175,8 +163,7 @@ discard block |
||
175 | 163 | * |
176 | 164 | * @return self |
177 | 165 | */ |
178 | - public function setTranslation($translation) |
|
179 | - { |
|
166 | + public function setTranslation($translation) { |
|
180 | 167 | $this->translation = (string) $translation; |
181 | 168 | |
182 | 169 | return $this; |
@@ -187,8 +174,7 @@ discard block |
||
187 | 174 | * |
188 | 175 | * @return string |
189 | 176 | */ |
190 | - public function getTranslation() |
|
191 | - { |
|
177 | + public function getTranslation() { |
|
192 | 178 | return $this->translation; |
193 | 179 | } |
194 | 180 | |
@@ -197,8 +183,7 @@ discard block |
||
197 | 183 | * |
198 | 184 | * @return bool |
199 | 185 | */ |
200 | - public function hasTranslation() |
|
201 | - { |
|
186 | + public function hasTranslation() { |
|
202 | 187 | return ($this->translation !== '') ? true : false; |
203 | 188 | } |
204 | 189 | |
@@ -209,8 +194,7 @@ discard block |
||
209 | 194 | * |
210 | 195 | * @return self |
211 | 196 | */ |
212 | - public function setPlural($plural) |
|
213 | - { |
|
197 | + public function setPlural($plural) { |
|
214 | 198 | $this->plural = (string) $plural; |
215 | 199 | |
216 | 200 | return $this; |
@@ -221,8 +205,7 @@ discard block |
||
221 | 205 | * |
222 | 206 | * @return string |
223 | 207 | */ |
224 | - public function getPlural() |
|
225 | - { |
|
208 | + public function getPlural() { |
|
226 | 209 | return $this->plural; |
227 | 210 | } |
228 | 211 | |
@@ -231,8 +214,7 @@ discard block |
||
231 | 214 | * |
232 | 215 | * @return bool |
233 | 216 | */ |
234 | - public function hasPlural() |
|
235 | - { |
|
217 | + public function hasPlural() { |
|
236 | 218 | return ($this->plural !== '') ? true : false; |
237 | 219 | } |
238 | 220 | |
@@ -243,8 +225,7 @@ discard block |
||
243 | 225 | * |
244 | 226 | * @return self |
245 | 227 | */ |
246 | - public function setPluralTranslations(array $plural) |
|
247 | - { |
|
228 | + public function setPluralTranslations(array $plural) { |
|
248 | 229 | $this->pluralTranslation = $plural; |
249 | 230 | |
250 | 231 | return $this; |
@@ -257,8 +238,7 @@ discard block |
||
257 | 238 | * |
258 | 239 | * @return array |
259 | 240 | */ |
260 | - public function getPluralTranslations($size = null) |
|
261 | - { |
|
241 | + public function getPluralTranslations($size = null) { |
|
262 | 242 | if ($size === null) { |
263 | 243 | return $this->pluralTranslation; |
264 | 244 | } |
@@ -283,8 +263,7 @@ discard block |
||
283 | 263 | * |
284 | 264 | * @return bool |
285 | 265 | */ |
286 | - public function hasPluralTranslations($checkContent = false) |
|
287 | - { |
|
266 | + public function hasPluralTranslations($checkContent = false) { |
|
288 | 267 | if ($checkContent) { |
289 | 268 | return implode('', $this->pluralTranslation) !== ''; |
290 | 269 | } |
@@ -297,8 +276,7 @@ discard block |
||
297 | 276 | * |
298 | 277 | * @return self |
299 | 278 | */ |
300 | - public function deletePluralTranslation() |
|
301 | - { |
|
279 | + public function deletePluralTranslation() { |
|
302 | 280 | $this->pluralTranslation = []; |
303 | 281 | |
304 | 282 | return $this; |
@@ -309,8 +287,7 @@ discard block |
||
309 | 287 | * |
310 | 288 | * @return string |
311 | 289 | */ |
312 | - public function getContext() |
|
313 | - { |
|
290 | + public function getContext() { |
|
314 | 291 | return $this->context; |
315 | 292 | } |
316 | 293 | |
@@ -319,8 +296,7 @@ discard block |
||
319 | 296 | * |
320 | 297 | * @return bool |
321 | 298 | */ |
322 | - public function hasContext() |
|
323 | - { |
|
299 | + public function hasContext() { |
|
324 | 300 | return (isset($this->context) && ($this->context !== '')) ? true : false; |
325 | 301 | } |
326 | 302 | |
@@ -332,8 +308,7 @@ discard block |
||
332 | 308 | * |
333 | 309 | * @return self |
334 | 310 | */ |
335 | - public function addReference($filename, $line = null) |
|
336 | - { |
|
311 | + public function addReference($filename, $line = null) { |
|
337 | 312 | $key = "{$filename}:{$line}"; |
338 | 313 | $this->references[$key] = [$filename, $line]; |
339 | 314 | |
@@ -345,8 +320,7 @@ discard block |
||
345 | 320 | * |
346 | 321 | * @return bool |
347 | 322 | */ |
348 | - public function hasReferences() |
|
349 | - { |
|
323 | + public function hasReferences() { |
|
350 | 324 | return !empty($this->references); |
351 | 325 | } |
352 | 326 | |
@@ -355,8 +329,7 @@ discard block |
||
355 | 329 | * |
356 | 330 | * @return array |
357 | 331 | */ |
358 | - public function getReferences() |
|
359 | - { |
|
332 | + public function getReferences() { |
|
360 | 333 | return array_values($this->references); |
361 | 334 | } |
362 | 335 | |
@@ -365,8 +338,7 @@ discard block |
||
365 | 338 | * |
366 | 339 | * @return self |
367 | 340 | */ |
368 | - public function deleteReferences() |
|
369 | - { |
|
341 | + public function deleteReferences() { |
|
370 | 342 | $this->references = []; |
371 | 343 | |
372 | 344 | return $this; |
@@ -379,8 +351,7 @@ discard block |
||
379 | 351 | * |
380 | 352 | * @return self |
381 | 353 | */ |
382 | - public function addComment($comment) |
|
383 | - { |
|
354 | + public function addComment($comment) { |
|
384 | 355 | if (!in_array($comment, $this->comments, true)) { |
385 | 356 | $this->comments[] = $comment; |
386 | 357 | } |
@@ -393,8 +364,7 @@ discard block |
||
393 | 364 | * |
394 | 365 | * @return bool |
395 | 366 | */ |
396 | - public function hasComments() |
|
397 | - { |
|
367 | + public function hasComments() { |
|
398 | 368 | return isset($this->comments[0]); |
399 | 369 | } |
400 | 370 | |
@@ -403,8 +373,7 @@ discard block |
||
403 | 373 | * |
404 | 374 | * @return array |
405 | 375 | */ |
406 | - public function getComments() |
|
407 | - { |
|
376 | + public function getComments() { |
|
408 | 377 | return $this->comments; |
409 | 378 | } |
410 | 379 | |
@@ -413,8 +382,7 @@ discard block |
||
413 | 382 | * |
414 | 383 | * @return self |
415 | 384 | */ |
416 | - public function deleteComments() |
|
417 | - { |
|
385 | + public function deleteComments() { |
|
418 | 386 | $this->comments = []; |
419 | 387 | |
420 | 388 | return $this; |
@@ -427,8 +395,7 @@ discard block |
||
427 | 395 | * |
428 | 396 | * @return self |
429 | 397 | */ |
430 | - public function addExtractedComment($comment) |
|
431 | - { |
|
398 | + public function addExtractedComment($comment) { |
|
432 | 399 | if (!in_array($comment, $this->extractedComments, true)) { |
433 | 400 | $this->extractedComments[] = $comment; |
434 | 401 | } |
@@ -441,8 +408,7 @@ discard block |
||
441 | 408 | * |
442 | 409 | * @return bool |
443 | 410 | */ |
444 | - public function hasExtractedComments() |
|
445 | - { |
|
411 | + public function hasExtractedComments() { |
|
446 | 412 | return isset($this->extractedComments[0]); |
447 | 413 | } |
448 | 414 | |
@@ -451,8 +417,7 @@ discard block |
||
451 | 417 | * |
452 | 418 | * @return array |
453 | 419 | */ |
454 | - public function getExtractedComments() |
|
455 | - { |
|
420 | + public function getExtractedComments() { |
|
456 | 421 | return $this->extractedComments; |
457 | 422 | } |
458 | 423 | |
@@ -461,8 +426,7 @@ discard block |
||
461 | 426 | * |
462 | 427 | * @return self |
463 | 428 | */ |
464 | - public function deleteExtractedComments() |
|
465 | - { |
|
429 | + public function deleteExtractedComments() { |
|
466 | 430 | $this->extractedComments = []; |
467 | 431 | |
468 | 432 | return $this; |
@@ -475,8 +439,7 @@ discard block |
||
475 | 439 | * |
476 | 440 | * @return self |
477 | 441 | */ |
478 | - public function addFlag($flag) |
|
479 | - { |
|
442 | + public function addFlag($flag) { |
|
480 | 443 | if (!in_array($flag, $this->flags, true)) { |
481 | 444 | $this->flags[] = $flag; |
482 | 445 | } |
@@ -489,8 +452,7 @@ discard block |
||
489 | 452 | * |
490 | 453 | * @return bool |
491 | 454 | */ |
492 | - public function hasFlags() |
|
493 | - { |
|
455 | + public function hasFlags() { |
|
494 | 456 | return isset($this->flags[0]); |
495 | 457 | } |
496 | 458 | |
@@ -499,8 +461,7 @@ discard block |
||
499 | 461 | * |
500 | 462 | * @return array |
501 | 463 | */ |
502 | - public function getFlags() |
|
503 | - { |
|
464 | + public function getFlags() { |
|
504 | 465 | return $this->flags; |
505 | 466 | } |
506 | 467 | |
@@ -509,8 +470,7 @@ discard block |
||
509 | 470 | * |
510 | 471 | * @return self |
511 | 472 | */ |
512 | - public function deleteFlags() |
|
513 | - { |
|
473 | + public function deleteFlags() { |
|
514 | 474 | $this->flags = []; |
515 | 475 | |
516 | 476 | return $this; |
@@ -524,8 +484,7 @@ discard block |
||
524 | 484 | * |
525 | 485 | * @return self |
526 | 486 | */ |
527 | - public function mergeWith(Translation $translation, $options = Merge::DEFAULTS) |
|
528 | - { |
|
487 | + public function mergeWith(Translation $translation, $options = Merge::DEFAULTS) { |
|
529 | 488 | Merge::mergeTranslation($translation, $this, $options); |
530 | 489 | Merge::mergeReferences($translation, $this, $options); |
531 | 490 | Merge::mergeComments($translation, $this, $options); |
@@ -4,35 +4,35 @@ |
||
4 | 4 | |
5 | 5 | class HigherOrderTapProxy |
6 | 6 | { |
7 | - /** |
|
8 | - * The target being tapped. |
|
9 | - * |
|
10 | - * @var mixed |
|
11 | - */ |
|
12 | - public $target; |
|
7 | + /** |
|
8 | + * The target being tapped. |
|
9 | + * |
|
10 | + * @var mixed |
|
11 | + */ |
|
12 | + public $target; |
|
13 | 13 | |
14 | - /** |
|
15 | - * Create a new tap proxy instance. |
|
16 | - * |
|
17 | - * @param mixed $target |
|
18 | - * @return void |
|
19 | - */ |
|
20 | - public function __construct($target) |
|
21 | - { |
|
22 | - $this->target = $target; |
|
23 | - } |
|
14 | + /** |
|
15 | + * Create a new tap proxy instance. |
|
16 | + * |
|
17 | + * @param mixed $target |
|
18 | + * @return void |
|
19 | + */ |
|
20 | + public function __construct($target) |
|
21 | + { |
|
22 | + $this->target = $target; |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Dynamically pass method calls to the target. |
|
27 | - * |
|
28 | - * @param string $method |
|
29 | - * @param array $parameters |
|
30 | - * @return mixed |
|
31 | - */ |
|
32 | - public function __call($method, $parameters) |
|
33 | - { |
|
34 | - $this->target->{$method}(...$parameters); |
|
25 | + /** |
|
26 | + * Dynamically pass method calls to the target. |
|
27 | + * |
|
28 | + * @param string $method |
|
29 | + * @param array $parameters |
|
30 | + * @return mixed |
|
31 | + */ |
|
32 | + public function __call($method, $parameters) |
|
33 | + { |
|
34 | + $this->target->{$method}(...$parameters); |
|
35 | 35 | |
36 | - return $this->target; |
|
37 | - } |
|
36 | + return $this->target; |
|
37 | + } |
|
38 | 38 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @param mixed $target |
18 | 18 | * @return void |
19 | 19 | */ |
20 | - public function __construct($target) |
|
20 | + public function __construct( $target ) |
|
21 | 21 | { |
22 | 22 | $this->target = $target; |
23 | 23 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * @param array $parameters |
30 | 30 | * @return mixed |
31 | 31 | */ |
32 | - public function __call($method, $parameters) |
|
32 | + public function __call( $method, $parameters ) |
|
33 | 33 | { |
34 | - $this->target->{$method}(...$parameters); |
|
34 | + $this->target->{$method}( ...$parameters ); |
|
35 | 35 | |
36 | 36 | return $this->target; |
37 | 37 | } |
@@ -2,8 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Illuminate\Support; |
4 | 4 | |
5 | -class HigherOrderTapProxy |
|
6 | -{ |
|
5 | +class HigherOrderTapProxy { |
|
7 | 6 | /** |
8 | 7 | * The target being tapped. |
9 | 8 | * |
@@ -17,8 +16,7 @@ discard block |
||
17 | 16 | * @param mixed $target |
18 | 17 | * @return void |
19 | 18 | */ |
20 | - public function __construct($target) |
|
21 | - { |
|
19 | + public function __construct($target) { |
|
22 | 20 | $this->target = $target; |
23 | 21 | } |
24 | 22 | |
@@ -29,8 +27,7 @@ discard block |
||
29 | 27 | * @param array $parameters |
30 | 28 | * @return mixed |
31 | 29 | */ |
32 | - public function __call($method, $parameters) |
|
33 | - { |
|
30 | + public function __call($method, $parameters) { |
|
34 | 31 | $this->target->{$method}(...$parameters); |
35 | 32 | |
36 | 33 | return $this->target; |
@@ -50,13 +50,13 @@ |
||
50 | 50 | */ |
51 | 51 | class File extends Facade |
52 | 52 | { |
53 | - /** |
|
54 | - * Get the registered name of the component. |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - protected static function getFacadeAccessor() |
|
59 | - { |
|
60 | - return 'files'; |
|
61 | - } |
|
53 | + /** |
|
54 | + * Get the registered name of the component. |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + protected static function getFacadeAccessor() |
|
59 | + { |
|
60 | + return 'files'; |
|
61 | + } |
|
62 | 62 | } |
@@ -5,15 +5,13 @@ |
||
5 | 5 | /** |
6 | 6 | * @see \Illuminate\Filesystem\Filesystem |
7 | 7 | */ |
8 | -class File extends Facade |
|
9 | -{ |
|
8 | +class File extends Facade { |
|
10 | 9 | /** |
11 | 10 | * Get the registered name of the component. |
12 | 11 | * |
13 | 12 | * @return string |
14 | 13 | */ |
15 | - protected static function getFacadeAccessor() |
|
16 | - { |
|
14 | + protected static function getFacadeAccessor() { |
|
17 | 15 | return 'files'; |
18 | 16 | } |
19 | 17 | } |
@@ -33,13 +33,13 @@ |
||
33 | 33 | */ |
34 | 34 | class Session extends Facade |
35 | 35 | { |
36 | - /** |
|
37 | - * Get the registered name of the component. |
|
38 | - * |
|
39 | - * @return string |
|
40 | - */ |
|
41 | - protected static function getFacadeAccessor() |
|
42 | - { |
|
43 | - return 'session'; |
|
44 | - } |
|
36 | + /** |
|
37 | + * Get the registered name of the component. |
|
38 | + * |
|
39 | + * @return string |
|
40 | + */ |
|
41 | + protected static function getFacadeAccessor() |
|
42 | + { |
|
43 | + return 'session'; |
|
44 | + } |
|
45 | 45 | } |
@@ -31,15 +31,13 @@ |
||
31 | 31 | * @see \Illuminate\Session\SessionManager |
32 | 32 | * @see \Illuminate\Session\Store |
33 | 33 | */ |
34 | -class Session extends Facade |
|
35 | -{ |
|
34 | +class Session extends Facade { |
|
36 | 35 | /** |
37 | 36 | * Get the registered name of the component. |
38 | 37 | * |
39 | 38 | * @return string |
40 | 39 | */ |
41 | - protected static function getFacadeAccessor() |
|
42 | - { |
|
40 | + protected static function getFacadeAccessor() { |
|
43 | 41 | return 'session'; |
44 | 42 | } |
45 | 43 | } |