16
16
use Magento \Setup \Model \ObjectManagerProvider ;
17
17
use Magento \Framework \ObjectManagerInterface ;
18
18
use Magento \Framework \Exception \LocalizedException ;
19
- use Magento \Store \Model \Store ;
20
- use Magento \Framework \Validator \Locale ;
21
- use Magento \Framework \Validator \Timezone ;
22
- use Magento \Framework \Validator \Currency ;
23
- use Magento \Framework \Validator \Url ;
19
+ use Magento \Framework \Validator \Locale as LocaleValidator ;
20
+ use Magento \Framework \Validator \Timezone as TimezoneValidator ;
21
+ use Magento \Framework \Validator \Currency as CurrencyValidator ;
22
+ use Magento \Framework \Validator \Url as UrlValidator ;
24
23
25
24
/**
26
25
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -43,24 +42,57 @@ class InstallStoreConfigurationCommand extends AbstractSetupCommand
43
42
* Object Manager
44
43
*
45
44
* @var ObjectManagerInterface
45
+ * @deprecated
46
46
*/
47
47
private $ objectManager ;
48
48
49
+ /**
50
+ * @var LocaleValidator
51
+ */
52
+ private $ localeValidator ;
53
+
54
+ /**
55
+ * @var TimezoneValidator
56
+ */
57
+ private $ timezoneValidator ;
58
+
59
+ /**
60
+ * @var CurrencyValidator
61
+ */
62
+ private $ currencyValidator ;
63
+
64
+ /**
65
+ * @var UrlValidator
66
+ */
67
+ private $ urlValidator ;
68
+
49
69
/**
50
70
* Inject dependencies
51
71
*
52
72
* @param InstallerFactory $installerFactory
53
73
* @param DeploymentConfig $deploymentConfig
54
74
* @param ObjectManagerProvider $objectManagerProvider
75
+ * @param LocaleValidator $localeValidator,
76
+ * @param TimezoneValidator $timezoneValidator,
77
+ * @param CurrencyValidator $currencyValidator,
78
+ * @param UrlValidator $urlValidator
55
79
*/
56
80
public function __construct (
57
81
InstallerFactory $ installerFactory ,
58
82
DeploymentConfig $ deploymentConfig ,
59
- ObjectManagerProvider $ objectManagerProvider
83
+ ObjectManagerProvider $ objectManagerProvider ,
84
+ LocaleValidator $ localeValidator ,
85
+ TimezoneValidator $ timezoneValidator ,
86
+ CurrencyValidator $ currencyValidator ,
87
+ UrlValidator $ urlValidator
60
88
) {
61
89
$ this ->installerFactory = $ installerFactory ;
62
90
$ this ->deploymentConfig = $ deploymentConfig ;
63
91
$ this ->objectManager = $ objectManagerProvider ->get ();
92
+ $ this ->localeValidator = $ localeValidator ;
93
+ $ this ->timezoneValidator = $ timezoneValidator ;
94
+ $ this ->currencyValidator = $ currencyValidator ;
95
+ $ this ->urlValidator = $ urlValidator ;
64
96
parent ::__construct ();
65
97
}
66
98
@@ -193,25 +225,31 @@ public function validate(InputInterface $input)
193
225
}
194
226
break ;
195
227
case StoreConfigurationDataMapper::KEY_LANGUAGE :
196
- /** @var Locale $lists */
197
- $ lists = $ this ->objectManager ->get (\Magento \Framework \Validator \Locale::class);
198
- $ errorMsg = $ this ->validateCodes ($ lists , $ value , StoreConfigurationDataMapper::KEY_LANGUAGE );
228
+ $ errorMsg = $ this ->validateCodes (
229
+ $ this ->localeValidator ,
230
+ $ value ,
231
+ StoreConfigurationDataMapper::KEY_LANGUAGE
232
+ );
199
233
if ($ errorMsg !== '' ) {
200
234
$ errors [] = $ errorMsg ;
201
235
}
202
236
break ;
203
237
case StoreConfigurationDataMapper::KEY_TIMEZONE :
204
- /** @var Timezone $lists */
205
- $ lists = $ this ->objectManager ->get (\Magento \Framework \Validator \Timezone::class);
206
- $ errorMsg = $ this ->validateCodes ($ lists , $ value , StoreConfigurationDataMapper::KEY_TIMEZONE );
238
+ $ errorMsg = $ this ->validateCodes (
239
+ $ this ->timezoneValidator ,
240
+ $ value ,
241
+ StoreConfigurationDataMapper::KEY_TIMEZONE
242
+ );
207
243
if ($ errorMsg !== '' ) {
208
244
$ errors [] = $ errorMsg ;
209
245
}
210
246
break ;
211
247
case StoreConfigurationDataMapper::KEY_CURRENCY :
212
- /** @var Currency $lists */
213
- $ lists = $ this ->objectManager ->get (\Magento \Framework \Validator \Currency::class);
214
- $ errorMsg = $ this ->validateCodes ($ lists , $ value , StoreConfigurationDataMapper::KEY_CURRENCY );
248
+ $ errorMsg = $ this ->validateCodes (
249
+ $ this ->currencyValidator ,
250
+ $ value ,
251
+ StoreConfigurationDataMapper::KEY_CURRENCY
252
+ );
215
253
if ($ errorMsg !== '' ) {
216
254
$ errors [] = $ errorMsg ;
217
255
}
@@ -291,7 +329,7 @@ private function validateBinaryValue($value, $key)
291
329
/**
292
330
* Validate codes for languages, currencies or timezones
293
331
*
294
- * @param Locale|Timezone|Currency $lists
332
+ * @param LocaleValidator|TimezoneValidator|CurrencyValidator $lists
295
333
* @param string $code
296
334
* @param string $type
297
335
* @return string
@@ -316,12 +354,9 @@ private function validateCodes($lists, $code, $type)
316
354
*/
317
355
private function validateUrl ($ url , $ option , array $ allowedSchemes )
318
356
{
319
- /** @var Url $validator */
320
- $ validator = $ this ->objectManager ->get (Url::class);
321
-
322
357
$ errorMsg = '' ;
323
358
324
- if (!$ validator ->isValid ($ url , $ allowedSchemes )) {
359
+ if (!$ this -> urlValidator ->isValid ($ url , $ allowedSchemes )) {
325
360
$ errorTemplate = '<error>Command option \'%s \': Invalid URL \'%s \'. '
326
361
. ' Domain Name should contain only letters, digits and hyphen. '
327
362
. ' And you should use only following schemes: \'%s \'.</error> ' ;
0 commit comments