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