|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GoetasWebservices\SoapServices\SoapClient\Command; |
|
4
|
|
|
|
|
5
|
|
|
use GoetasWebservices\SoapServices\SoapClient\Builder\SoapContainerBuilder; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Logger\ConsoleLogger; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
|
|
13
|
|
|
class Generate extends Command |
|
14
|
|
|
{ |
|
15
|
|
|
protected function configure() |
|
16
|
|
|
{ |
|
17
|
|
|
parent::configure(); |
|
18
|
|
|
$this->setName('generate'); |
|
19
|
|
|
$this->setDescription("Convert create all the necessary PHP classes for a SOAP client"); |
|
20
|
|
|
$this->setDefinition([ |
|
21
|
|
|
new InputArgument('config', InputArgument::REQUIRED, 'Config file location'), |
|
22
|
|
|
new InputArgument('dest-dir', InputArgument::REQUIRED, 'Container files destination directory'), |
|
23
|
|
|
new InputOption('dest-class', null, InputOption::VALUE_REQUIRED, 'Container class file destination directory'), |
|
24
|
|
|
]); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param InputInterface $input |
|
29
|
|
|
* @param OutputInterface $output |
|
30
|
|
|
* @return int |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
33
|
|
|
{ |
|
34
|
|
|
$logger = new ConsoleLogger($output); |
|
35
|
|
|
$containerBuilder = new SoapContainerBuilder($input->getArgument('config'), $logger); |
|
36
|
|
|
|
|
37
|
|
|
if ($input->getOption('dest-class')) { |
|
38
|
|
|
$containerBuilder->setContainerClassName($input->getOption('dest-class')); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$debugContainer = $containerBuilder->getDebugContainer(); |
|
42
|
|
|
//$debugContainer->set('logger', $logger); |
|
43
|
|
|
|
|
44
|
|
|
$wsdlMetadata = $debugContainer->getParameter('goetas_webservices.soap_client.config')['metadata']; |
|
45
|
|
|
|
|
46
|
|
|
$schemas = []; |
|
47
|
|
|
$portTypes = []; |
|
48
|
|
|
$wsdlReader = $debugContainer->get('goetas_webservices.wsdl2php.wsdl_reader'); |
|
49
|
|
|
|
|
50
|
|
|
foreach (array_keys($wsdlMetadata) as $src) { |
|
51
|
|
|
$definitions = $wsdlReader->readFile($src); |
|
52
|
|
|
$schemas[] = $definitions->getSchema(); |
|
53
|
|
|
$portTypes = array_merge($portTypes, $definitions->getAllPortTypes()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$soapReader = $debugContainer->get('goetas_webservices.wsdl2php.soap_reader'); |
|
57
|
|
|
$soapServices = $soapReader->getServices(); |
|
58
|
|
|
|
|
59
|
|
|
foreach (['php', 'jms'] as $type) { |
|
60
|
|
|
|
|
61
|
|
|
$converter = $debugContainer->get('goetas_webservices.xsd2php.converter.' . $type); |
|
62
|
|
|
$wsdlConverter = $debugContainer->get('goetas_webservices.wsdl2php.converter.' . $type); |
|
63
|
|
|
$items = $wsdlConverter->visitServices($soapServices); |
|
64
|
|
|
$items = array_merge($items, $converter->convert($schemas)); |
|
65
|
|
|
|
|
66
|
|
|
$writer = $debugContainer->get('goetas_webservices.xsd2php.writer.' . $type); |
|
67
|
|
|
$writer->write($items); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$containerBuilder->dumpContainerForProd($input->getArgument('dest-dir'), $debugContainer); |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @var $clientStubGenerator \GoetasWebservices\SoapServices\SoapClient\StubGeneration\ClientStubGenerator |
|
74
|
|
|
*/ |
|
75
|
|
|
$clientStubGenerator = $debugContainer->get('goetas_webservices.soap_client.stub.client_generator'); |
|
76
|
|
|
|
|
77
|
|
|
$classDefinitions = $clientStubGenerator->generate($portTypes); |
|
78
|
|
|
$classWriter = $debugContainer->get('goetas_webservices.xsd2php.class_writer.php'); |
|
79
|
|
|
$classWriter->write($classDefinitions); |
|
80
|
|
|
|
|
81
|
|
|
return 0; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|