1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace WsdlToPhp\PackageGenerator\File; |
6
|
|
|
|
7
|
|
|
use WsdlToPhp\PackageGenerator\File\Utils as FileUtils; |
8
|
|
|
use WsdlToPhp\PackageGenerator\Model\AbstractModel; |
9
|
|
|
use WsdlToPhp\PackageGenerator\Model\Method as MethodModel; |
10
|
|
|
use WsdlToPhp\PackageGenerator\Parser\Wsdl\TagHeader; |
11
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpAnnotation; |
12
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock; |
13
|
|
|
|
14
|
|
|
final class OperationAnnotationBlock extends AbstractOperation |
15
|
|
|
{ |
16
|
46 |
|
public function addAnnotationBlockForOperationMethod(PhpAnnotationBlock $annotationBlock): self |
17
|
|
|
{ |
18
|
|
|
$this |
19
|
46 |
|
->addOperationMethodDeclaration($annotationBlock) |
20
|
46 |
|
->addOperationMethodMetaInformation($annotationBlock) |
21
|
46 |
|
->addOperationMethodUses($annotationBlock) |
22
|
46 |
|
->addOperationMethodParam($annotationBlock) |
23
|
46 |
|
->addOperationMethodReturn($annotationBlock) |
24
|
|
|
; |
25
|
|
|
|
26
|
46 |
|
return $this; |
27
|
|
|
} |
28
|
|
|
|
29
|
46 |
|
protected function addOperationMethodDeclaration(PhpAnnotationBlock $annotationBlock): self |
30
|
|
|
{ |
31
|
46 |
|
$annotationBlock->addChild(sprintf('Method to call the operation originally named %s', $this->getMethod()->getName())); |
32
|
46 |
|
if (!$this->getMethod()->isUnique()) { |
33
|
|
|
$annotationBlock->addChild('This method has been renamed because it is defined several times but with different signature'); |
34
|
|
|
} |
35
|
|
|
|
36
|
46 |
|
return $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
46 |
|
protected function addOperationMethodMetaInformation(PhpAnnotationBlock $annotationBlock): self |
40
|
|
|
{ |
41
|
46 |
|
$soapHeaderNames = $this->getMethod()->getMetaValue(TagHeader::META_SOAP_HEADER_NAMES, []); |
42
|
46 |
|
$soapHeaderTypes = $this->getMethod()->getMetaValue(TagHeader::META_SOAP_HEADER_TYPES, []); |
43
|
46 |
|
$soapHeaderNamespaces = $this->getMethod()->getMetaValue(TagHeader::META_SOAP_HEADER_NAMESPACES, []); |
44
|
46 |
|
$soapHeaders = $this->getMethod()->getMetaValue(TagHeader::META_SOAP_HEADERS, []); |
45
|
46 |
|
if (!empty($soapHeaderNames) && !empty($soapHeaderTypes) && !empty($soapHeaderNamespaces)) { |
46
|
|
|
$annotationBlock |
47
|
12 |
|
->addChild('Meta information extracted from the WSDL') |
48
|
12 |
|
->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNames: %s', implode(', ', $soapHeaderNames)), AbstractModelFile::ANNOTATION_LONG_LENGTH)) |
49
|
12 |
|
->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderNamespaces: %s', implode(', ', $soapHeaderNamespaces)), AbstractModelFile::ANNOTATION_LONG_LENGTH)) |
50
|
12 |
|
->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaderTypes: %s', implode(', ', $this->getSoapHeaderTypesTypes($soapHeaderTypes))), AbstractModelFile::ANNOTATION_LONG_LENGTH)) |
51
|
12 |
|
->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, sprintf('- SOAPHeaders: %s', implode(', ', $soapHeaders)), AbstractModelFile::ANNOTATION_LONG_LENGTH)) |
52
|
|
|
; |
53
|
|
|
} |
54
|
46 |
|
FileUtils::defineModelAnnotationsFromWsdl($annotationBlock, $this->getMethod(), [ |
55
|
46 |
|
TagHeader::META_SOAP_HEADER_NAMES, |
56
|
46 |
|
TagHeader::META_SOAP_HEADER_NAMESPACES, |
57
|
46 |
|
TagHeader::META_SOAP_HEADER_TYPES, |
58
|
46 |
|
TagHeader::META_SOAP_HEADERS, |
59
|
|
|
]); |
60
|
|
|
|
61
|
46 |
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
12 |
|
protected function getSoapHeaderTypesTypes(array $soapHeaderTypes): array |
65
|
|
|
{ |
66
|
12 |
|
$soapHeaderTypesTypes = []; |
67
|
12 |
|
foreach ($soapHeaderTypes as $soapHeaderType) { |
68
|
12 |
|
$soapHeaderTypesTypes[] = $this->getSoapHeaderTypeType($soapHeaderType, true); |
69
|
|
|
} |
70
|
|
|
|
71
|
12 |
|
return $soapHeaderTypesTypes; |
72
|
|
|
} |
73
|
|
|
|
74
|
12 |
|
protected function getSoapHeaderTypeType(string $soapHeaderType, bool $namespaced = false): string |
75
|
|
|
{ |
76
|
12 |
|
$type = $soapHeaderType; |
77
|
12 |
|
$model = $this->getModelByName($soapHeaderType); |
78
|
12 |
|
if ($model instanceof AbstractModel) { |
79
|
12 |
|
$type = $model->getPackagedName($namespaced); |
80
|
|
|
} |
81
|
|
|
|
82
|
12 |
|
return $type; |
83
|
|
|
} |
84
|
|
|
|
85
|
46 |
|
protected function addOperationMethodUses(PhpAnnotationBlock $annotationBlock): self |
86
|
|
|
{ |
87
|
|
|
$annotationBlock |
88
|
46 |
|
->addChild(new PhpAnnotation(AbstractModelFile::ANNOTATION_USES, sprintf('%s::getSoapClient()', $this->getMethod()->getOwner()->getExtends(true)))) |
89
|
46 |
|
->addChild(new PhpAnnotation(AbstractModelFile::ANNOTATION_USES, sprintf('%s::setResult()', $this->getMethod()->getOwner()->getExtends(true)))) |
90
|
46 |
|
->addChild(new PhpAnnotation(AbstractModelFile::ANNOTATION_USES, sprintf('%s::saveLastError()', $this->getMethod()->getOwner()->getExtends(true)))) |
91
|
|
|
; |
92
|
|
|
|
93
|
46 |
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
46 |
|
protected function addOperationMethodParam(PhpAnnotationBlock $annotationBlock): self |
97
|
|
|
{ |
98
|
46 |
|
$this->addOperationMethodParamFromArray($annotationBlock)->addOperationMethodParamFromModel($annotationBlock)->addOperationMethodParamFromString($annotationBlock); |
99
|
|
|
|
100
|
46 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
46 |
|
protected function addOperationMethodParamFromArray(PhpAnnotationBlock $annotationBlock): self |
104
|
|
|
{ |
105
|
46 |
|
if ($this->isParameterTypeAnArray()) { |
106
|
42 |
|
foreach ($this->getParameterTypeArrayTypes() as $parameterName => $parameterType) { |
107
|
42 |
|
$annotationBlock->addChild($this->getOperationMethodParam($parameterType, $this->getParameterName($parameterName))); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
46 |
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
46 |
|
protected function addOperationMethodParamFromModel(PhpAnnotationBlock $annotationBlock): self |
115
|
|
|
{ |
116
|
46 |
|
if ($this->isParameterTypeAModel()) { |
117
|
2 |
|
$annotationBlock->addChild($this->getOperationMethodParam($this->getParameterTypeModel()->getPackagedName(true), $this->getParameterName($this->getParameterTypeModel()->getPackagedName()))); |
118
|
|
|
} |
119
|
|
|
|
120
|
46 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
46 |
|
protected function getOperationMethodParam(string $type, string $name): PhpAnnotation |
124
|
|
|
{ |
125
|
46 |
|
return new PhpAnnotation(AbstractModelFile::ANNOTATION_PARAM, sprintf('%s $%s', $type, $name)); |
126
|
|
|
} |
127
|
|
|
|
128
|
46 |
|
protected function addOperationMethodParamFromString(PhpAnnotationBlock $annotationBlock): self |
129
|
|
|
{ |
130
|
46 |
|
if ($this->isParameterTypeAString() && !$this->isParameterTypeAModel()) { |
131
|
2 |
|
$annotationBlock->addChild($this->getOperationMethodParam($this->getMethod()->getParameterType(), lcfirst($this->getMethod()->getParameterType()))); |
132
|
|
|
} |
133
|
|
|
|
134
|
46 |
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
46 |
|
protected function addOperationMethodReturn(PhpAnnotationBlock $annotationBlock): self |
138
|
|
|
{ |
139
|
46 |
|
$annotationBlock->addChild(new PhpAnnotation(AbstractModelFile::ANNOTATION_RETURN, sprintf('%s|bool', $this->getOperationMethodReturnType($this->getMethod())))); |
140
|
|
|
|
141
|
46 |
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
46 |
|
protected function getOperationMethodReturnType(MethodModel $method): string |
145
|
|
|
{ |
146
|
46 |
|
return Service::getOperationMethodReturnType($method, $this->getGenerator()); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|