|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ConfigCacheBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2015-2016 Yahoo Japan Corporation |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace YahooJapan\ConfigCacheBundle\ConfigCache\Locale\Loader; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Translation\Translator; |
|
15
|
|
|
use YahooJapan\ConfigCacheBundle\ConfigCache\Loader\ArrayLoader as BaseArrayLoader; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* ArrayLoader loads an array converting user configurations. |
|
19
|
|
|
*/ |
|
20
|
|
|
class ArrayLoader extends BaseArrayLoader implements TranslationLoaderInterface |
|
21
|
|
|
{ |
|
22
|
|
|
protected $locale; |
|
23
|
|
|
protected $translator; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Constructor. |
|
27
|
|
|
* |
|
28
|
|
|
* @param Translator $translator |
|
29
|
|
|
*/ |
|
30
|
5 |
|
public function __construct(Translator $translator) |
|
31
|
|
|
{ |
|
32
|
5 |
|
$this->translator = $translator; |
|
33
|
5 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Sets a locale. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $locale |
|
39
|
|
|
* |
|
40
|
|
|
* @return ArrayLoader |
|
41
|
|
|
*/ |
|
42
|
5 |
|
public function setLocale($locale) |
|
43
|
|
|
{ |
|
44
|
5 |
|
$this->locale = $locale; |
|
45
|
|
|
|
|
46
|
5 |
|
return $this; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
2 |
|
protected function walkInternal(&$value, $nouse) |
|
53
|
|
|
{ |
|
54
|
2 |
|
if ($this->translator->getCatalogue()->has($value)) { |
|
55
|
1 |
|
$value = $this->translator->trans($value); |
|
56
|
1 |
|
} |
|
57
|
2 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Walks by locale internal processing. |
|
61
|
|
|
* |
|
62
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
63
|
|
|
* @param string &$value |
|
64
|
|
|
* @param string $nouse |
|
65
|
|
|
* |
|
66
|
|
|
* @return void |
|
67
|
|
|
*/ |
|
68
|
4 |
|
protected function walkByLocaleInternal(&$value, $nouse) |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
4 |
|
if ($this->translator->getCatalogue($this->locale)->has($value)) { |
|
71
|
4 |
|
$value = $this->translator->trans($value, array(), null, $this->locale); |
|
72
|
4 |
|
} |
|
73
|
4 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* {@inheritdoc} |
|
77
|
|
|
*/ |
|
78
|
5 |
|
protected function getInternalMethod() |
|
79
|
|
|
{ |
|
80
|
5 |
|
if (is_null($this->locale)) { |
|
81
|
1 |
|
return parent::getInternalMethod(); |
|
82
|
|
|
} else { |
|
83
|
5 |
|
return 'walkByLocaleInternal'; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.