10 use Symfony\Component\Console\Command\Command;
11 use Symfony\Component\Console\Input\InputArgument;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Input\InputInterface;
14 use Symfony\Component\Console\Output\OutputInterface;
39 private $filesUtility;
65 \
Magento\Framework\
App\Utility\Files $filesUtility,
66 \
Magento\Framework\Config\Dom\UrnResolver $urnResolver,
70 $this->filesUtility = $filesUtility;
71 $this->urnResolver = $urnResolver;
72 $this->formats = $formats;
73 $this->readFactory = $readFactory;
74 parent::__construct();
82 $this->setName(
'dev:urn-catalog:generate')
83 ->setDescription(
'Generates the catalog of URNs to *.xsd mappings for the IDE to highlight xml.')
88 InputOption::VALUE_REQUIRED,
89 'Format in which catalog will be generated. Supported: ['.
94 self::IDE_FILE_PATH_ARGUMENT,
95 InputArgument::REQUIRED,
96 'Path to file to output the catalog. For PhpStorm use .idea/misc.xml' 109 private function getUrnDictionary(OutputInterface
$output)
111 $files = $this->filesUtility->getXmlCatalogFiles(
'*.xml');
112 $files = array_merge(
$files, $this->filesUtility->getXmlCatalogFiles(
'*.xsd'));
115 foreach (
$files as $file) {
116 $fileDir = dirname($file[0]);
118 $read = $this->readFactory->create($fileDir);
121 preg_match_all(
'/schemaLocation="(urn\:magento\:[^"]*)"/i',
$content, $matches);
122 if (isset($matches[1])) {
123 $urns = array_merge($urns, $matches[1]);
126 $urns = array_unique($urns);
128 foreach ($urns as $urn) {
130 $paths[$urn] = $this->urnResolver->getRealPath($urn);
131 }
catch (\Exception $e) {
133 if (
$output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
134 $output->writeln($e->getMessage());
147 $ideName = $input->getOption(self::IDE_OPTION);
148 $ideFilePath = $input->getArgument(self::IDE_FILE_PATH_ARGUMENT);
150 $urnDictionary = $this->getUrnDictionary(
$output);
151 if ($formatter = $this->getFormatters($ideName)) {
152 $formatter->generateCatalog($urnDictionary, $ideFilePath);
154 throw new InputException(
__(
"Format for IDE '%1' is not supported", $ideName));
164 private function getFormatters(
$format)
167 if (!isset($this->formats[
$format])) {
170 return $this->formats[
$format];
180 return array_keys($this->formats);
execute(InputInterface $input, OutputInterface $output)
const IDE_FILE_PATH_ARGUMENT
__construct(\Magento\Framework\App\Utility\Files $filesUtility, \Magento\Framework\Config\Dom\UrnResolver $urnResolver, \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory, array $formats=[])
foreach($appDirs as $dir) $files