Skip to content
Snippets Groups Projects
Commit 2b66c0a5 authored by Ivan Gavryshko's avatar Ivan Gavryshko
Browse files

MAGETWO-36076: Move dev/tools/Magento/Tools/Layout/xmlUpdater.php

- moved tool to command.
parent 2d8e2178
No related merge requests found
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Developer\Console\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Developer\Model\Tools\Formatter;
/**
* Class XmlConverterCommand
* Converts XML file using XSL style sheets
*/
class XmlConverterCommand extends Command
{
/**
* XML file argument name constant
*/
const XML_FILE_ARGUMENT = 'xml-file';
/**
* Processor argument constant
*/
const PROCESSOR_ARGUMENT = 'processor';
/**
* Overwrite option constant
*/
const OVERWRITE_OPTION = 'overwrite';
/**
* @var Formatter
*/
private $formatter;
/**
* Inject dependencies
*
* @param Formatter $formatter
*/
public function __construct(
Formatter $formatter,
\DOMDocument $dom,
\XSLTProcessor $xsltProcessor
) {
$this->formatter = $formatter;
$this->domXml = clone $dom;
$this->domXsl = clone $dom;
$this->xsltProcessor = $xsltProcessor;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('dev:xml:convert')
->setDescription('Converts XML file using XSL style sheets')
->setDefinition([
new InputArgument(
self::XML_FILE_ARGUMENT,
InputArgument::REQUIRED,
'Path to XML file that going to be transformed'
),
new InputArgument(
self::PROCESSOR_ARGUMENT,
InputArgument::REQUIRED,
'Path to XSL styli sheet that going to be applied to XML file'
),
new InputOption(
self::OVERWRITE_OPTION,
'-o',
InputOption::VALUE_NONE,
'Overwrite file XML file'
),
]);
parent::configure();
}
/**
* {@inheritdoc}
* @throws \InvalidArgumentException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$xmlFile = $input->getArgument(self::XML_FILE_ARGUMENT);
$this->domXml->preserveWhiteSpace = true;
$this->domXml->load($xmlFile);
$this->domXsl->preserveWhiteSpace = true;
$this->domXsl->load($input->getArgument(self::PROCESSOR_ARGUMENT));
$this->xsltProcessor->registerPHPFunctions();
$this->xsltProcessor->importStylesheet($this->domXsl);
$transformedDoc = $this->xsltProcessor->transformToXml($this->domXml);
$result = $this->formatter->format($transformedDoc);
if ($input->getOption(self::OVERWRITE_OPTION)) {
file_put_contents($input->getArgument(self::XML_FILE_ARGUMENT), $result);
$output->writeln("<info>You saved converted XML into $xmlFile</info>");
} else {
echo $result;
}
return;
} catch (\Zend_Console_Getopt_Exception $e) {
$errorMessage = $e->getUsageMessage();
$output->writeln("<error>$errorMessage</error>");
return;
} catch (\Exception $exception) {
$errorMessage = $exception->getMessage();
$output->writeln("<error>$errorMessage</error>");
return;
}
}
}
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
* Copyright © 2015 Magento. All rights reserved. * Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details. * See COPYING.txt for license details.
*/ */
namespace Magento\Tools\Layout;
namespace Magento\Developer\Model\Tools;
class Formatter class Formatter
{ {
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
<argument name="commands" xsi:type="array"> <argument name="commands" xsi:type="array">
<item name="dev_tests_run" xsi:type="object">Magento\Developer\Console\Command\DevTestsRunCommand</item> <item name="dev_tests_run" xsi:type="object">Magento\Developer\Console\Command\DevTestsRunCommand</item>
<item name="dev_css_deploy" xsi:type="object">Magento\Developer\Console\Command\CssDeployCommand</item> <item name="dev_css_deploy" xsi:type="object">Magento\Developer\Console\Command\CssDeployCommand</item>
<item name="xml_converter" xsi:type="object">Magento\Developer\Console\Command\XmlConverterCommand</item>
</argument> </argument>
</arguments> </arguments>
</type> </type>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment