Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InputValidator.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Deploy\Console;
7 
11 use Symfony\Component\Console\Input\InputInterface;
12 
17 {
21  public static $fileExtensionOptionMap = [
22  'js' => Options::NO_JAVASCRIPT,
23  'map' => Options::NO_JAVASCRIPT,
24  'css' => Options::NO_CSS,
25  'less' => Options::NO_LESS,
26  'html' => Options::NO_HTML,
27  'htm' => Options::NO_HTML,
28  'jpg' => Options::NO_IMAGES,
29  'jpeg' => Options::NO_IMAGES,
30  'gif' => Options::NO_IMAGES,
31  'png' => Options::NO_IMAGES,
32  'ico' => Options::NO_IMAGES,
33  'svg' => Options::NO_IMAGES,
34  'eot' => Options::NO_FONTS,
35  'ttf' => Options::NO_FONTS,
36  'woff' => Options::NO_FONTS,
37  'woff2' => Options::NO_FONTS,
38  'md' => Options::NO_MISC,
39  'jbf' => Options::NO_MISC,
40  'csv' => Options::NO_MISC,
41  'json' => Options::NO_MISC,
42  'txt' => Options::NO_MISC,
43  'htc' => Options::NO_MISC,
44  'swf' => Options::NO_MISC,
45  'LICENSE' => Options::NO_MISC,
46  '' => Options::NO_MISC,
47  ];
48 
56  private $localeValidator;
57 
63  public function __construct(Locale $localeValidator)
64  {
65  $this->localeValidator = $localeValidator;
66  }
67 
74  public function validate(InputInterface $input)
75  {
76  $this->checkAreasInput(
77  $input->getOption(Options::AREA),
78  $input->getOption(Options::EXCLUDE_AREA)
79  );
80  $this->checkThemesInput(
81  $input->getOption(Options::THEME),
82  $input->getOption(Options::EXCLUDE_THEME)
83  );
84  $this->checkLanguagesInput(
85  $input->getArgument(Options::LANGUAGES_ARGUMENT) ?: ['all'],
86  $input->getOption(Options::EXCLUDE_LANGUAGE)
87  );
88  }
89 
98  private function checkAreasInput(array $areasInclude, array $areasExclude)
99  {
100  if ($areasInclude[0] != 'all' && $areasExclude[0] != 'none') {
101  throw new \InvalidArgumentException(
102  '--area (-a) and --exclude-area cannot be used at the same time'
103  );
104  }
105  }
106 
115  private function checkThemesInput(array $themesInclude, array $themesExclude)
116  {
117  if ($themesInclude[0] != 'all' && $themesExclude[0] != 'none') {
118  throw new \InvalidArgumentException(
119  '--theme (-t) and --exclude-theme cannot be used at the same time'
120  );
121  }
122  }
123 
132  private function checkLanguagesInput(array $languagesInclude, array $languagesExclude)
133  {
134  if ($languagesInclude[0] != 'all') {
135  foreach ($languagesInclude as $lang) {
136  if (!$this->localeValidator->isValid($lang)) {
137  throw new \InvalidArgumentException(
138  $lang .
139  ' argument has invalid value, please run info:language:list for list of available locales'
140  );
141  }
142  }
143  if ($languagesExclude[0] != 'none') {
144  throw new \InvalidArgumentException(
145  '--language (-l) and --exclude-language cannot be used at the same time'
146  );
147  }
148  }
149  }
150 }
__construct(Locale $localeValidator)