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