1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of gpupo/pipe2 |
5
|
|
|
* |
6
|
|
|
* (c) Gilmar Pupo <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* For more information, see |
12
|
|
|
* <https://opensource.gpupo.com/pipe2/>. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Gpupo\Pipe2\Converter; |
16
|
|
|
|
17
|
|
|
use Symfony\Component\Console\Command\Command as Core; |
18
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
20
|
|
|
use Symfony\Component\Console\Input\InputOption; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
|
23
|
|
|
class Command extends Core |
24
|
|
|
{ |
25
|
|
|
protected function configure() |
26
|
|
|
{ |
27
|
|
|
$this |
28
|
|
|
->setName('convert') |
29
|
|
|
->setDescription('Convert Xml file to xmlpipe2 format') |
30
|
|
|
->addArgument( |
31
|
|
|
'file', |
32
|
|
|
InputArgument::OPTIONAL, |
33
|
|
|
'Xml file path' |
34
|
|
|
) |
35
|
|
|
->addOption( |
36
|
|
|
'format', |
37
|
|
|
null, |
38
|
|
|
InputOption::VALUE_OPTIONAL, |
39
|
|
|
'Input Xml Format(google, blank)', |
40
|
|
|
'google' |
41
|
|
|
) |
42
|
|
|
->addOption( |
43
|
|
|
'output', |
44
|
|
|
null, |
45
|
|
|
InputOption::VALUE_OPTIONAL, |
46
|
|
|
'Output filename', |
47
|
|
|
'stder' |
48
|
|
|
) |
49
|
|
|
->addOption( |
50
|
|
|
'channel', |
51
|
|
|
null, |
52
|
|
|
InputOption::VALUE_OPTIONAL, |
53
|
|
|
'Channel name for fill channel item field', |
54
|
|
|
'xml' |
55
|
|
|
) |
56
|
|
|
->addOption( |
57
|
|
|
'pretty', |
58
|
|
|
null, |
59
|
|
|
InputOption::VALUE_OPTIONAL, |
60
|
|
|
'Nicely formats output with indentation and extra space', |
61
|
|
|
false |
62
|
|
|
) |
63
|
|
|
->addOption( |
64
|
|
|
'slug', |
65
|
|
|
null, |
66
|
|
|
InputOption::VALUE_OPTIONAL, |
67
|
|
|
'add sluggables fields - schema based ', |
68
|
|
|
false |
69
|
|
|
) |
70
|
|
|
->addOption( |
71
|
|
|
'idField', |
72
|
|
|
null, |
73
|
|
|
InputOption::VALUE_OPTIONAL, |
74
|
|
|
'Item field to fill document id', |
75
|
|
|
'sku' |
76
|
|
|
) |
77
|
|
|
->addOption( |
78
|
|
|
'idPrefix', |
79
|
|
|
null, |
80
|
|
|
InputOption::VALUE_OPTIONAL, |
81
|
|
|
'Integer prefix for document id', |
82
|
|
|
null |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
protected function getParameters(InputInterface $input) |
87
|
|
|
{ |
88
|
|
|
$parameters = [ |
89
|
|
|
'input' => $input->getArgument('file'), |
90
|
|
|
'output' => $input->getOption('output'), |
91
|
|
|
'channel' => $input->getOption('channel'), |
92
|
|
|
'slug' => $input->getOption('slug'), |
93
|
|
|
'id' => [ |
94
|
|
|
'field' => $input->getOption('idField'), |
95
|
|
|
'prefix' => $input->getOption('idPrefix'), |
96
|
|
|
], |
97
|
|
|
'format' => ucfirst($input->getOption('format')), |
98
|
|
|
'formatOutput' => ($input->getOption('pretty') === 'true') ? true : false, |
99
|
|
|
]; |
100
|
|
|
|
101
|
|
|
return $parameters; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
105
|
|
|
{ |
106
|
|
|
$parameters = $this->getParameters($input); |
107
|
|
|
$validator = new InputValidator(); |
108
|
|
|
|
109
|
|
|
if ($validator->validateInputParameters($parameters)) { |
110
|
|
|
$converter = '\\Gpupo\Pipe2\Converter\\'.$parameters['format'].'Converter'; |
111
|
|
|
$convert = new $converter($parameters); |
112
|
|
|
$output->writeln($convert->execute()->getDocument()->saveXml()); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|