9
9
*/
10
10
namespace Magento \Store \Model \App ;
11
11
12
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
13
+ use Magento \Framework \App \ObjectManager ;
14
+ use Magento \Framework \Locale \ResolverInterface ;
15
+ use Magento \Framework \Phrase ;
16
+ use Magento \Framework \Phrase \RendererInterface ;
12
17
use Magento \Framework \Translate \Inline \ConfigInterface ;
18
+ use Magento \Framework \Translate \Inline \StateInterface ;
19
+ use Magento \Framework \TranslateInterface ;
20
+ use Magento \Framework \View \DesignInterface ;
21
+ use Magento \Store \Model \StoreManagerInterface ;
22
+ use Psr \Log \LoggerInterface ;
13
23
14
24
/**
15
25
* @api
16
26
* @since 100.0.2
27
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17
28
*/
18
29
class Emulation extends \Magento \Framework \DataObject
19
30
{
20
31
/**
21
- * @var \Magento\Store\Model\ StoreManagerInterface
32
+ * @var StoreManagerInterface
22
33
*/
23
34
protected $ _storeManager ;
24
35
25
36
/**
26
- * @var \Magento\Framework\ TranslateInterface
37
+ * @var TranslateInterface
27
38
*/
28
39
protected $ _translate ;
29
40
30
41
/**
31
42
* Core store config
32
43
*
33
- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
44
+ * @var ScopeConfigInterface
34
45
*/
35
46
protected $ _scopeConfig ;
36
47
37
48
/**
38
- * @var \Magento\Framework\Locale\ ResolverInterface
49
+ * @var ResolverInterface
39
50
*/
40
51
protected $ _localeResolver ;
41
52
@@ -50,7 +61,7 @@ class Emulation extends \Magento\Framework\DataObject
50
61
protected $ inlineConfig ;
51
62
52
63
/**
53
- * @var \Magento\Framework\Translate\Inline\ StateInterface
64
+ * @var StateInterface
54
65
*/
55
66
protected $ inlineTranslation ;
56
67
@@ -62,39 +73,46 @@ class Emulation extends \Magento\Framework\DataObject
62
73
private $ initialEnvironmentInfo ;
63
74
64
75
/**
65
- * @var \Psr\Log\ LoggerInterface
76
+ * @var LoggerInterface
66
77
*/
67
78
private $ logger ;
68
79
69
80
/**
70
- * @var \Magento\Framework\View\ DesignInterface
81
+ * @var DesignInterface
71
82
*/
72
83
private $ _viewDesign ;
73
84
74
85
/**
75
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
76
- * @param \Magento\Framework\View\DesignInterface $viewDesign
86
+ * @var RendererInterface
87
+ */
88
+ private $ phraseRenderer ;
89
+
90
+ /**
91
+ * @param StoreManagerInterface $storeManager
92
+ * @param DesignInterface $viewDesign
77
93
* @param \Magento\Framework\App\DesignInterface $design
78
- * @param \Magento\Framework\ TranslateInterface $translate
79
- * @param \Magento\Framework\App\Config\ ScopeConfigInterface $scopeConfig
94
+ * @param TranslateInterface $translate
95
+ * @param ScopeConfigInterface $scopeConfig
80
96
* @param ConfigInterface $inlineConfig
81
- * @param \Magento\Framework\Translate\Inline\ StateInterface $inlineTranslation
82
- * @param \Magento\Framework\Locale\ ResolverInterface $localeResolver
83
- * @param \Psr\Log\ LoggerInterface $logger
97
+ * @param StateInterface $inlineTranslation
98
+ * @param ResolverInterface $localeResolver
99
+ * @param LoggerInterface $logger
84
100
* @param array $data
101
+ * @param RendererInterface|null $phraseRenderer
85
102
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
86
103
*/
87
104
public function __construct (
88
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
89
- \ Magento \ Framework \ View \ DesignInterface $ viewDesign ,
105
+ StoreManagerInterface $ storeManager ,
106
+ DesignInterface $ viewDesign ,
90
107
\Magento \Framework \App \DesignInterface $ design ,
91
- \ Magento \ Framework \ TranslateInterface $ translate ,
92
- \ Magento \ Framework \ App \ Config \ ScopeConfigInterface $ scopeConfig ,
108
+ TranslateInterface $ translate ,
109
+ ScopeConfigInterface $ scopeConfig ,
93
110
ConfigInterface $ inlineConfig ,
94
- \Magento \Framework \Translate \Inline \StateInterface $ inlineTranslation ,
95
- \Magento \Framework \Locale \ResolverInterface $ localeResolver ,
96
- \Psr \Log \LoggerInterface $ logger ,
97
- array $ data = []
111
+ StateInterface $ inlineTranslation ,
112
+ ResolverInterface $ localeResolver ,
113
+ LoggerInterface $ logger ,
114
+ array $ data = [],
115
+ ?RendererInterface $ phraseRenderer = null
98
116
) {
99
117
$ this ->_localeResolver = $ localeResolver ;
100
118
parent ::__construct ($ data );
@@ -106,6 +124,8 @@ public function __construct(
106
124
$ this ->inlineConfig = $ inlineConfig ;
107
125
$ this ->inlineTranslation = $ inlineTranslation ;
108
126
$ this ->logger = $ logger ;
127
+ $ this ->phraseRenderer = $ phraseRenderer
128
+ ?? ObjectManager::getInstance ()->get (RendererInterface::class);
109
129
}
110
130
111
131
/**
@@ -158,6 +178,7 @@ public function startEnvironmentEmulation(
158
178
$ this ->_localeResolver ->setLocale ($ newLocaleCode );
159
179
$ this ->_translate ->setLocale ($ newLocaleCode );
160
180
$ this ->_translate ->loadData ($ area );
181
+ Phrase::setRenderer ($ this ->phraseRenderer );
161
182
}
162
183
163
184
/**
@@ -179,7 +200,7 @@ public function stopEnvironmentEmulation()
179
200
// Current store needs to be changed right before locale change and after design change
180
201
$ this ->_storeManager ->setCurrentStore ($ initialDesign ['store ' ]);
181
202
$ this ->_restoreInitialLocale ($ this ->initialEnvironmentInfo ->getInitialLocaleCode (), $ initialDesign ['area ' ]);
182
-
203
+ Phrase:: setRenderer ( $ this -> initialEnvironmentInfo -> getPhraseRenderer ());
183
204
$ this ->initialEnvironmentInfo = null ;
184
205
return $ this ;
185
206
}
@@ -202,6 +223,8 @@ public function storeCurrentEnvironmentInfo()
202
223
]
203
224
)->setInitialLocaleCode (
204
225
$ this ->_localeResolver ->getLocale ()
226
+ )->setPhraseRenderer (
227
+ Phrase::getRenderer ()
205
228
);
206
229
}
207
230
0 commit comments