1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace WsdlToPhp\PackageGenerator\File; |
6
|
|
|
|
7
|
|
|
use WsdlToPhp\PackageGenerator\Container\PhpElement\Constant as ConstantContainer; |
8
|
|
|
use WsdlToPhp\PackageGenerator\Container\PhpElement\Property as PropertyContainer; |
9
|
|
|
use WsdlToPhp\PackageGenerator\Model\Struct as StructModel; |
10
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpAnnotation; |
11
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock; |
12
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpConstant; |
13
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpMethod; |
14
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpProperty; |
15
|
|
|
|
16
|
|
|
final class ClassMap extends AbstractModelFile |
17
|
|
|
{ |
18
|
|
|
public const METHOD_NAME = 'get'; |
19
|
|
|
|
20
|
22 |
|
protected function fillClassConstants(ConstantContainer $constants): void |
21
|
|
|
{ |
22
|
22 |
|
} |
23
|
|
|
|
24
|
|
|
protected function getConstantAnnotationBlock(PhpConstant $constant): ?PhpAnnotationBlock |
25
|
|
|
{ |
26
|
|
|
return null; |
27
|
|
|
} |
28
|
|
|
|
29
|
22 |
|
protected function fillClassProperties(PropertyContainer $properties): void |
30
|
|
|
{ |
31
|
22 |
|
} |
32
|
|
|
|
33
|
|
|
protected function getPropertyAnnotationBlock(PhpProperty $property): ?PhpAnnotationBlock |
34
|
|
|
{ |
35
|
|
|
return null; |
36
|
|
|
} |
37
|
|
|
|
38
|
22 |
|
protected function fillClassMethods(): void |
39
|
|
|
{ |
40
|
22 |
|
$method = new PhpMethod(self::METHOD_NAME, [], self::TYPE_ARRAY, PhpMethod::ACCESS_PUBLIC, false, true, true); |
41
|
22 |
|
$this->addMethodBody($method); |
42
|
22 |
|
$this->methods->add($method); |
43
|
|
|
} |
44
|
|
|
|
45
|
22 |
|
protected function getMethodAnnotationBlock(PhpMethod $method): ?PhpAnnotationBlock |
46
|
|
|
{ |
47
|
22 |
|
return new PhpAnnotationBlock([ |
48
|
22 |
|
'Returns the mapping between the WSDL Structs and generated Structs\' classes', |
49
|
22 |
|
'This array is sent to the \SoapClient when calling the WS', |
50
|
22 |
|
new PhpAnnotation(AbstractModelFile::ANNOTATION_RETURN, 'string[]'), |
51
|
22 |
|
]); |
52
|
|
|
} |
53
|
|
|
|
54
|
22 |
|
protected function getClassAnnotationBlock(): PhpAnnotationBlock |
55
|
|
|
{ |
56
|
22 |
|
$annotations = [ |
57
|
22 |
|
'Class which returns the class map definition', |
58
|
22 |
|
]; |
59
|
|
|
|
60
|
22 |
|
if (!empty($this->getGenerator()->getOptionPrefix())) { |
61
|
6 |
|
$annotations[] = new PhpAnnotation(self::ANNOTATION_PACKAGE, $this->getGenerator()->getOptionPrefix()); |
62
|
|
|
} |
63
|
|
|
|
64
|
22 |
|
return new PhpAnnotationBlock($annotations); |
65
|
|
|
} |
66
|
|
|
|
67
|
22 |
|
protected function addMethodBody(PhpMethod $method): self |
68
|
|
|
{ |
69
|
22 |
|
if ($this->getGenerator()->getStructs()->count() > 0) { |
70
|
22 |
|
$method->addChild('return ['); |
71
|
22 |
|
foreach ($this->getGenerator()->getStructs() as $struct) { |
72
|
22 |
|
$this->addStructToClassMapList($method, $struct); |
73
|
|
|
} |
74
|
22 |
|
$method->addChild('];'); |
75
|
|
|
} |
76
|
|
|
|
77
|
22 |
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
22 |
|
protected function addStructToClassMapList(PhpMethod $method, StructModel $struct): self |
81
|
|
|
{ |
82
|
22 |
|
if ($struct->isStruct() && !$struct->isRestriction()) { |
83
|
22 |
|
$method->addChild($method->getIndentedString(sprintf('\'%s\' => \'%s\',', $struct->getName(), $this->getStructName($struct)), 1)); |
84
|
|
|
} |
85
|
|
|
|
86
|
22 |
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Work around for https://bugs.php.net/bug.php?id=69280. |
91
|
|
|
*/ |
92
|
22 |
|
protected function getStructName(StructModel $struct): string |
93
|
|
|
{ |
94
|
22 |
|
return str_replace('\\', '\\\\', $struct->getPackagedName(true)); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|