|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jabe\Impl\Cxf\Webservice; |
|
4
|
|
|
|
|
5
|
|
|
use Jabe\Impl\Bpmn\Data\SimpleStructureDefinition; |
|
6
|
|
|
use Jabe\Impl\Bpmn\Parser\XMLImporterInterface; |
|
7
|
|
|
use Sax\Element; |
|
8
|
|
|
use Jabe\Impl\Webservice\{ |
|
9
|
|
|
WSDLManager, |
|
10
|
|
|
WSOperation, |
|
11
|
|
|
WSService, |
|
12
|
|
|
WSDLServiceBuilder |
|
13
|
|
|
}; |
|
14
|
|
|
use Jabe\Impl\Model\Wsdl\Instance\{ |
|
15
|
|
|
ComplexTypeInterface, |
|
16
|
|
|
DefinitionsInterface, |
|
17
|
|
|
OperationInterface, |
|
18
|
|
|
ServiceInterface, |
|
19
|
|
|
TypesInterface |
|
20
|
|
|
}; |
|
21
|
|
|
|
|
22
|
|
|
class CxfWSDLImporter implements XMLImporterInterface |
|
23
|
|
|
{ |
|
24
|
|
|
protected $wsServices = []; |
|
25
|
|
|
protected $wsOperations = []; |
|
26
|
|
|
protected $structures = []; |
|
27
|
|
|
|
|
28
|
|
|
protected $wsdlLocation; |
|
29
|
|
|
protected $namespace = ""; |
|
30
|
|
|
|
|
31
|
|
|
public function importFrom($data): void |
|
32
|
|
|
{ |
|
33
|
|
|
if ($data instanceof Element) { |
|
34
|
|
|
$this->namespace = $data->attribute("namespace") === null ? "" : $data->attribute("namespace") . ":"; |
|
35
|
|
|
$this->importFrom($data->attribute("location")); |
|
36
|
|
|
} elseif (is_string($data)) { |
|
37
|
|
|
$url = $data; |
|
38
|
|
|
|
|
39
|
|
|
$this->wsServices = []; |
|
40
|
|
|
$this->wsOperations = []; |
|
41
|
|
|
$this->structures = []; |
|
42
|
|
|
$this->wsdlLocation = $url; |
|
43
|
|
|
|
|
44
|
|
|
$wsdlManager = new WSDLManager(); |
|
45
|
|
|
$def = $wsdlManager->getDefinition($url); |
|
46
|
|
|
$builder = new WSDLServiceBuilder(); |
|
47
|
|
|
|
|
48
|
|
|
$services = $builder->buildServices($def); |
|
49
|
|
|
foreach ($services as $service) { |
|
50
|
|
|
$wsService = $this->importService($service, $def); |
|
51
|
|
|
$this->wsServices[$this->namespace . $wsService->getName()] = $wsService; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if ($def !== null && $def->getTypes() !== null) { |
|
|
|
|
|
|
55
|
|
|
$this->importTypes($def->getTypes()); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
protected function importService(ServiceInterface $service, DefinitionsInterface $def): WSService |
|
61
|
|
|
{ |
|
62
|
|
|
$name = $service->getName(); |
|
|
|
|
|
|
63
|
|
|
$location = $service->getEndpoint(); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
$serviceName = $service->getName(); |
|
66
|
|
|
$arr = explode(':', $service->getBinding()); |
|
|
|
|
|
|
67
|
|
|
$bindingName = end($arr); |
|
68
|
|
|
$bindings = $def->getBindings(); |
|
|
|
|
|
|
69
|
|
|
$binding = null; |
|
|
|
|
|
|
70
|
|
|
$wsService = new WSService($this->namespace . $name, $location, $this->wsdlLocation); |
|
71
|
|
|
foreach ($bindings as $testBinding) { |
|
72
|
|
|
$arr = explode(':', $testBinding->getType()); |
|
73
|
|
|
$bindingType = end($arr); |
|
74
|
|
|
if ($serviceName == $bindingType && $bindingName == $testBinding->getName()) { |
|
75
|
|
|
$operations = $testBinding->getOperations(); |
|
76
|
|
|
foreach ($operations as $operation) { |
|
77
|
|
|
$wsOperation = $this->importOperation($operation, $wsService); |
|
78
|
|
|
$wsService->addOperation($wsOperation); |
|
79
|
|
|
$this->wsOperations[$this->namespace . $operation->getName()] = $wsOperation; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $wsService; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
protected function importOperation(OperationInterface $operation, WSService $service): WSOperation |
|
88
|
|
|
{ |
|
89
|
|
|
$wsOperation = new WSOperation($this->namespace . $operation->getName(), $operation->getName(), $service); |
|
90
|
|
|
return $wsOperation; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
protected function importTypes(TypesInterface $types): void |
|
94
|
|
|
{ |
|
95
|
|
|
$impl = $types->getSchema(); |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
$mappings = $impl->getElements(); |
|
98
|
|
|
|
|
99
|
|
|
foreach ($mappings as $mapping) { |
|
100
|
|
|
$this->importStructure($mapping); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
protected function importStructure(ComplexTypeInterface $mapping): void |
|
105
|
|
|
{ |
|
106
|
|
|
$structure = new SimpleStructureDefinition($this->namespace . $mapping->getName()); |
|
|
|
|
|
|
107
|
|
|
$params = $mapping->getParameters(); |
|
|
|
|
|
|
108
|
|
|
foreach ($params as $param) { |
|
109
|
|
|
$fieldName = $param->getName(); |
|
110
|
|
|
$arr = explode(":", $param->getType()); |
|
111
|
|
|
$fieldClass = end($arr); |
|
112
|
|
|
$structure->setFieldName($fieldName, $fieldClass, null); |
|
113
|
|
|
} |
|
114
|
|
|
$this->structures[$structure->getId()] = $structure; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function getStructures(): array |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->structures; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function getServices(): array |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->wsServices; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function getOperations(): array |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->wsOperations; |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|