forked from mikaelcom/WsdlToPhp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WsdlToPhpService.php
155 lines (155 loc) · 4.12 KB
/
WsdlToPhpService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* File for WsdlToPhpService
* @package WsdlToPhpGenerator
* @date 19/12/2012
*/
/**
* Class WsdlToPhpService stands for an available service containing the functions/operations described in the WSDL
* @package WsdlToPhpGenerator
* @date 19/12/2012
*/
class WsdlToPhpService extends WsdlToPhpModel
{
/**
* Store the functions of the service
* @var array
*/
private $functions;
/**
* Main constructor
* @see WsdlToPhpModel::__construct()
* @uses WsdlToPhpService::setFunctions()
* @param string $_name the function name
* @return WsdlToPhpService
*/
public function __construct($_name)
{
parent::__construct($_name);
$this->setFunctions();
}
/**
* Allows to define the contextual part of the class name for the package
* @see WsdlToPhpModel::getContextualPart()
* @return string
*/
public function getContextualPart()
{
return 'Service';
}
/**
* Returns the sub package name which the model belongs to
* Must be overridden by sub classes
* @see WsdlToPhpModel::getDocSubPackages()
* @return array
*/
public function getDocSubPackages()
{
return array(
'Services');
}
/**
* Returns the commment lines for this function
* @uses WsdlToPhpModel::getModelByName()
* @uses WsdlToPhpModel::getPackagedName()
* @uses WsdlToPhpService::getFunctions()
* @uses WsdlToPhpFunction::getReturnType()
* @uses WsdlToPhpFunction::getComment()
* @uses WsdlToPhpFunction::getBody()
* @uses WsdlToPhpGenerator::getPackageName()
* @uses WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()
* @param array $_body
* @return void
*/
public function getClassBody(&$_body)
{
if(count($this->getFunctions()))
{
$returnTypes = array();
foreach($this->getFunctions() as $function)
{
array_push($_body,array(
'comment'=>$function->getComment()));
$function->getBody($_body);
$model = self::getModelByName($function->getReturnType());
if($model && $model->getIsStruct())
{
array_push($returnTypes,$model->getPackagedName());
unset($model);
}
else
array_push($returnTypes,$function->getReturnType());
}
if(count($returnTypes) && WsdlToPhpGenerator::getOptionGenerateWsdlClassFile())
{
$returnTypes = array_unique($returnTypes);
natcasesort($returnTypes);
/**
* getResult() method comments
*/
$comments = array();
array_push($comments,'Returns the result');
array_push($comments,'@see ' . WsdlToPhpGenerator::getPackageName() . 'WsdlClass::getResult()');
array_push($comments,'@return ' . implode('|',$returnTypes));
/**
* getResult() method body
*/
array_push($_body,array(
'comment'=>$comments));
array_push($_body,'public function getResult()');
array_push($_body,'{');
array_push($_body,'return parent::getResult();');
array_push($_body,'}');
unset($comments);
}
unset($returnTypes);
}
}
/**
* Returns the functions of the service
* @return array
*/
public function getFunctions()
{
return $this->functions;
}
/**
* Set the functions
* @param array $_functions
* @return array
*/
private function setFunctions(array $_functions = array())
{
return ($this->functions = $_functions);
}
/**
* Add a function to the service
* @param string $_functionName original function name
* @param string $_functionParameterType original parameter type/name
* @param string $_functionReturnType original return type/name
* @return WsdlToPhpFunction
*/
public function addFunction($_functionName,$_functionParameterType,$_functionReturnType)
{
return ($this->functions[$_functionName] = new WsdlToPhpFunction($_functionName,$_functionParameterType,$_functionReturnType,$this));
}
/**
* Returns the function by its original name
* @uses WsdlToPhpService::getFunctions()
* @param string $_functionName the original function name
* @return WsdlToPhpFunction|null
*/
public function getFunction($_functionName)
{
return array_key_exists($_functionName,$this->getFunctions())?$this->functions[$_functionName]:null;
}
/**
* Return class name
* @return string __CLASS__
*/
public function __toString()
{
return __CLASS__;
}
}
?>