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