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