1
|
|
|
<?php |
2
|
|
|
namespace Goetas\Xsd\XsdToPhp\Command; |
3
|
|
|
|
4
|
|
|
use Goetas\Xsd\XsdToPhp\AbstractConverter; |
5
|
|
|
use Goetas\Xsd\XsdToPhp\Naming\NamingStrategy; |
6
|
|
|
use Goetas\Xsd\XsdToPhp\Php\ClassGenerator; |
7
|
|
|
use Goetas\Xsd\XsdToPhp\Php\PathGenerator\Psr4PathGenerator; |
8
|
|
|
use Goetas\Xsd\XsdToPhp\Php\PhpConverter; |
9
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Zend\Code\Generator\FileGenerator; |
12
|
|
|
|
13
|
|
|
class ConvertToPHP extends AbstractConvert |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* |
18
|
|
|
* @see Console\Command\Command |
19
|
|
|
*/ |
20
|
|
|
protected function configure() |
21
|
|
|
{ |
22
|
|
|
parent::configure(); |
23
|
|
|
$this->setName('convert:php'); |
24
|
|
|
$this->setDescription('Convert XSD definitions into PHP classes'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function getConverterter(NamingStrategy $naming) |
28
|
|
|
{ |
29
|
|
|
return new PhpConverter($naming); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output) |
33
|
|
|
{ |
34
|
|
|
$generator = new ClassGenerator(); |
35
|
|
|
$pathGenerator = new Psr4PathGenerator($targets); |
36
|
|
|
$items = $converter->convert($schemas); |
37
|
|
|
|
38
|
|
|
$progress = new ProgressBar($output, count($items)); |
39
|
|
|
$progress->start(); |
40
|
|
|
|
41
|
|
|
foreach ($items as $item) { |
42
|
|
|
$progress->advance(); |
43
|
|
|
$output->write(" Creating <info>" . $output->getFormatter()->escape($item->getFullName()) . "</info>... "); |
44
|
|
|
$path = $pathGenerator->getPath($item); |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
$fileGen = new FileGenerator(); |
48
|
|
|
$fileGen->setFilename($path); |
49
|
|
|
$classGen = new \Zend\Code\Generator\ClassGenerator(); |
50
|
|
|
|
51
|
|
|
if ($generator->generate($classGen, $item)) { |
52
|
|
|
|
53
|
|
|
$fileGen->setClass($classGen); |
54
|
|
|
|
55
|
|
|
$fileGen->write(); |
56
|
|
|
$output->writeln("done."); |
57
|
|
|
} else { |
58
|
|
|
$output->write("skip."); |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|