99 */
1010namespace Magento \Store \Model \App ;
1111
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 ;
1217use 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 ;
1323
1424/**
1525 * @api
1626 * @since 100.0.2
27+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1728 */
1829class Emulation extends \Magento \Framework \DataObject
1930{
2031 /**
21- * @var \Magento\Store\Model\ StoreManagerInterface
32+ * @var StoreManagerInterface
2233 */
2334 protected $ _storeManager ;
2435
2536 /**
26- * @var \Magento\Framework\ TranslateInterface
37+ * @var TranslateInterface
2738 */
2839 protected $ _translate ;
2940
3041 /**
3142 * Core store config
3243 *
33- * @var \Magento\Framework\App\Config\ ScopeConfigInterface
44+ * @var ScopeConfigInterface
3445 */
3546 protected $ _scopeConfig ;
3647
3748 /**
38- * @var \Magento\Framework\Locale\ ResolverInterface
49+ * @var ResolverInterface
3950 */
4051 protected $ _localeResolver ;
4152
@@ -50,7 +61,7 @@ class Emulation extends \Magento\Framework\DataObject
5061 protected $ inlineConfig ;
5162
5263 /**
53- * @var \Magento\Framework\Translate\Inline\ StateInterface
64+ * @var StateInterface
5465 */
5566 protected $ inlineTranslation ;
5667
@@ -62,39 +73,46 @@ class Emulation extends \Magento\Framework\DataObject
6273 private $ initialEnvironmentInfo ;
6374
6475 /**
65- * @var \Psr\Log\ LoggerInterface
76+ * @var LoggerInterface
6677 */
6778 private $ logger ;
6879
6980 /**
70- * @var \Magento\Framework\View\ DesignInterface
81+ * @var DesignInterface
7182 */
7283 private $ _viewDesign ;
7384
7485 /**
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
7793 * @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
8096 * @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
84100 * @param array $data
101+ * @param RendererInterface|null $phraseRenderer
85102 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
86103 */
87104 public function __construct (
88- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
89- \ Magento \ Framework \ View \ DesignInterface $ viewDesign ,
105+ StoreManagerInterface $ storeManager ,
106+ DesignInterface $ viewDesign ,
90107 \Magento \Framework \App \DesignInterface $ design ,
91- \ Magento \ Framework \ TranslateInterface $ translate ,
92- \ Magento \ Framework \ App \ Config \ ScopeConfigInterface $ scopeConfig ,
108+ TranslateInterface $ translate ,
109+ ScopeConfigInterface $ scopeConfig ,
93110 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
98116 ) {
99117 $ this ->_localeResolver = $ localeResolver ;
100118 parent ::__construct ($ data );
@@ -106,6 +124,8 @@ public function __construct(
106124 $ this ->inlineConfig = $ inlineConfig ;
107125 $ this ->inlineTranslation = $ inlineTranslation ;
108126 $ this ->logger = $ logger ;
127+ $ this ->phraseRenderer = $ phraseRenderer
128+ ?? ObjectManager::getInstance ()->get (RendererInterface::class);
109129 }
110130
111131 /**
@@ -158,6 +178,7 @@ public function startEnvironmentEmulation(
158178 $ this ->_localeResolver ->setLocale ($ newLocaleCode );
159179 $ this ->_translate ->setLocale ($ newLocaleCode );
160180 $ this ->_translate ->loadData ($ area );
181+ Phrase::setRenderer ($ this ->phraseRenderer );
161182 }
162183
163184 /**
@@ -179,7 +200,7 @@ public function stopEnvironmentEmulation()
179200 // Current store needs to be changed right before locale change and after design change
180201 $ this ->_storeManager ->setCurrentStore ($ initialDesign ['store ' ]);
181202 $ this ->_restoreInitialLocale ($ this ->initialEnvironmentInfo ->getInitialLocaleCode (), $ initialDesign ['area ' ]);
182-
203+ Phrase:: setRenderer ( $ this -> initialEnvironmentInfo -> getPhraseRenderer ());
183204 $ this ->initialEnvironmentInfo = null ;
184205 return $ this ;
185206 }
@@ -202,6 +223,8 @@ public function storeCurrentEnvironmentInfo()
202223 ]
203224 )->setInitialLocaleCode (
204225 $ this ->_localeResolver ->getLocale ()
226+ )->setPhraseRenderer (
227+ Phrase::getRenderer ()
205228 );
206229 }
207230
0 commit comments