|
1
|
|
|
<?php |
|
2
|
|
|
namespace Goetas\Xsd\XsdToPhp\Command; |
|
3
|
|
|
|
|
4
|
|
|
use Goetas\Xsd\XsdToPhp\AbstractConverter; |
|
5
|
|
|
use Goetas\Xsd\XsdToPhp\Jms\PathGenerator\Psr4PathGenerator; |
|
6
|
|
|
use Goetas\Xsd\XsdToPhp\Jms\YamlConverter; |
|
7
|
|
|
use Goetas\Xsd\XsdToPhp\Naming\NamingStrategy; |
|
8
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
use Symfony\Component\Yaml\Dumper; |
|
11
|
|
|
|
|
12
|
|
|
class ConvertToYaml extends AbstractConvert |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* |
|
17
|
|
|
* @see Console\Command\Command |
|
18
|
|
|
*/ |
|
19
|
|
|
protected function configure() |
|
20
|
|
|
{ |
|
21
|
|
|
parent::configure(); |
|
22
|
|
|
$this->setName('convert:jms-yaml'); |
|
23
|
|
|
$this->setDescription('Convert XSD definitions into YAML metadata for JMS Serializer'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
protected function getConverterter(NamingStrategy $naming) |
|
27
|
|
|
{ |
|
28
|
|
|
return new YamlConverter($naming); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output) |
|
32
|
|
|
{ |
|
33
|
|
|
$items = $converter->convert($schemas); |
|
34
|
|
|
|
|
35
|
|
|
$dumper = new Dumper(); |
|
36
|
|
|
|
|
37
|
|
|
$pathGenerator = new Psr4PathGenerator($targets); |
|
38
|
|
|
|
|
39
|
|
|
$progress = new ProgressBar($output, count($items)); |
|
40
|
|
|
$progress->start(); |
|
41
|
|
|
|
|
42
|
|
|
foreach ($items as $item) { |
|
43
|
|
|
$progress->advance(); |
|
44
|
|
|
$output->write(" Item <info>" . key($item) . "</info>... "); |
|
45
|
|
|
|
|
46
|
|
|
$source = $dumper->dump($item, 10000); |
|
47
|
|
|
$output->write("created source... "); |
|
48
|
|
|
|
|
49
|
|
|
$path = $pathGenerator->getPath($item); |
|
50
|
|
|
$bytes = file_put_contents($path, $source); |
|
51
|
|
|
$output->writeln("saved source <comment>$bytes bytes</comment>."); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|