13
13
use Magento \Framework \Console \Cli ;
14
14
use Magento \Deploy \Console \Command \DeployStaticOptionsInterface as Options ;
15
15
use Magento \Framework \RequireJs \Config as RequireJsConfig ;
16
- use Magento \Framework \App \View \Asset \Publisher ;
17
- use Magento \Framework \View \Asset \Repository ;
16
+ use Magento \Framework \Translate \Js \Config as TranslationJsConfig ;
18
17
use Magento \Framework \App \ObjectManager ;
19
- use Magento \Translation \Model \Js \Config as TranslationJsConfig ;
20
- use Magento \Framework \TranslateInterface ;
18
+ use Magento \Deploy \Model \DeployStrategyFactory ;
21
19
22
20
class LocaleQuickDeploy implements DeployInterface
23
21
{
@@ -42,51 +40,41 @@ class LocaleQuickDeploy implements DeployInterface
42
40
private $ options = [];
43
41
44
42
/**
45
- * @var Repository
46
- */
47
- private $ assetRepo ;
48
-
49
- /**
50
- * @var Publisher
43
+ * @var TranslationJsConfig
51
44
*/
52
- private $ assetPublisher ;
45
+ private $ translationJsConfig ;
53
46
54
47
/**
55
- * @var TranslationJsConfig
48
+ * @var DeployStrategyFactory
56
49
*/
57
- private $ translationJsConfig ;
50
+ private $ deployStrategyFactory ;
58
51
59
52
/**
60
- * @var TranslateInterface
53
+ * @var DeployInterface[]
61
54
*/
62
- private $ translator ;
55
+ private $ deploys ;
63
56
64
57
/**
65
58
* @param Filesystem $filesystem
66
59
* @param OutputInterface $output
67
60
* @param array $options
68
- * @param Repository $assetRepo
69
- * @param Publisher $assetPublisher
70
61
* @param TranslationJsConfig $translationJsConfig
71
- * @param TranslateInterface $translator
62
+ * @param DeployStrategyFactory $deployStrategyFactory
72
63
*/
73
64
public function __construct (
74
65
Filesystem $ filesystem ,
75
66
OutputInterface $ output ,
76
67
$ options = [],
77
- Repository $ assetRepo = null ,
78
- Publisher $ assetPublisher = null ,
79
68
TranslationJsConfig $ translationJsConfig = null ,
80
- TranslateInterface $ translator = null
69
+ DeployStrategyFactory $ deployStrategyFactory = null
81
70
) {
82
71
$ this ->filesystem = $ filesystem ;
83
72
$ this ->output = $ output ;
84
73
$ this ->options = $ options ;
85
- $ this ->assetRepo = $ assetRepo ?: ObjectManager::getInstance ()->get (Repository::class);
86
- $ this ->assetPublisher = $ assetPublisher ?: ObjectManager::getInstance ()->get (Publisher::class);
87
74
$ this ->translationJsConfig = $ translationJsConfig
88
75
?: ObjectManager::getInstance ()->get (TranslationJsConfig::class);
89
- $ this ->translator = $ translator ?: ObjectManager::getInstance ()->get (TranslateInterface::class);
76
+ $ this ->deployStrategyFactory = $ deployStrategyFactory
77
+ ?: ObjectManager::getInstance ()->get (DeployStrategyFactory::class);
90
78
}
91
79
92
80
/**
@@ -140,16 +128,23 @@ public function deploy($area, $themePath, $locale)
140
128
$ jsDictionaryEnabled = $ this ->translationJsConfig ->dictionaryEnabled ();
141
129
foreach ($ localeFiles as $ path ) {
142
130
if ($ this ->getStaticDirectory ()->isFile ($ path )) {
143
- $ destination = $ this ->replaceLocaleInPath ($ path , $ baseLocale , $ locale );
144
131
if (!$ jsDictionaryEnabled || !$ this ->isJsDictionary ($ path )) {
132
+ $ destination = $ this ->replaceLocaleInPath ($ path , $ baseLocale , $ locale );
145
133
$ this ->getStaticDirectory ()->copyFile ($ path , $ destination );
134
+ $ processedFiles ++;
146
135
}
147
- $ processedFiles ++;
148
136
}
149
137
}
150
138
151
139
if ($ jsDictionaryEnabled ) {
152
- $ this ->deployJsDictionary ($ area , $ themePath , $ locale );
140
+ $ this ->getDeploy (
141
+ DeployStrategyFactory::DEPLOY_STRATEGY_JS_DICTIONARY ,
142
+ [
143
+ 'output ' => $ this ->output ,
144
+ 'translationJsConfig ' => $ this ->translationJsConfig
145
+ ]
146
+ )
147
+ ->deploy ($ area , $ themePath , $ locale );
153
148
$ processedFiles ++;
154
149
}
155
150
@@ -160,40 +155,29 @@ public function deploy($area, $themePath, $locale)
160
155
}
161
156
162
157
/**
163
- * Define if provided path is js dictionary
158
+ * Get deploy strategy according to required strategy
164
159
*
165
- * @param string $path
166
- * @return bool
160
+ * @param string $strategy
161
+ * @param array $params
162
+ * @return DeployInterface
167
163
*/
168
- private function isJsDictionary ( $ path )
164
+ private function getDeploy ( $ strategy , $ params )
169
165
{
170
- return strpos ($ path , $ this ->translationJsConfig ->getDictionaryFileName ()) !== false ;
166
+ if (empty ($ this ->deploys [$ strategy ])) {
167
+ $ this ->deploys [$ strategy ] = $ this ->deployStrategyFactory ->create ($ strategy , $ params );
168
+ }
169
+ return $ this ->deploys [$ strategy ];
171
170
}
172
171
173
172
/**
174
- * Deploy js-dictionary for specific locale, theme and area
173
+ * Define if provided path is js dictionary
175
174
*
176
- * @param string $area
177
- * @param string $themePath
178
- * @param string $locale
179
- * @return void
175
+ * @param string $path
176
+ * @return bool
180
177
*/
181
- private function deployJsDictionary ( $ area , $ themePath , $ locale )
178
+ private function isJsDictionary ( $ path )
182
179
{
183
- $ this ->translator ->setLocale ($ locale );
184
- $ this ->translator ->loadData ($ area , true );
185
-
186
- $ asset = $ this ->assetRepo ->createAsset (
187
- $ this ->translationJsConfig ->getDictionaryFileName (),
188
- ['area ' => $ area , 'theme ' => $ themePath , 'locale ' => $ locale ]
189
- );
190
- if ($ this ->output ->isVeryVerbose ()) {
191
- $ this ->output ->writeln ("\tDeploying the file to ' {$ asset ->getPath ()}' " );
192
- } else {
193
- $ this ->output ->write ('. ' );
194
- }
195
-
196
- $ this ->assetPublisher ->publish ($ asset );
180
+ return strpos ($ path , $ this ->translationJsConfig ->getDictionaryFileName ()) !== false ;
197
181
}
198
182
199
183
/**
0 commit comments