|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WsdlToPhp\PackageGenerator\Model; |
|
4
|
|
|
|
|
5
|
|
|
use WsdlToPhp\PackageGenerator\Generator\Generator; |
|
6
|
|
|
use WsdlToPhp\PackageGenerator\ConfigurationReader\ServiceReservedMethod; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class Method stands for an available operation described in the WSDL |
|
10
|
|
|
*/ |
|
11
|
|
|
class Method extends AbstractModel |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Type of the parameter for the operation |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
private $parameterType = ''; |
|
18
|
|
|
/** |
|
19
|
|
|
* Type of the return value for the operation |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
private $returnType = ''; |
|
23
|
|
|
/** |
|
24
|
|
|
* Indicates function is not alone with this name, then its name is contextualized based on its parameter(s) |
|
25
|
|
|
* @var bool |
|
26
|
|
|
*/ |
|
27
|
|
|
private $isUnique = true; |
|
28
|
|
|
/** |
|
29
|
|
|
* Generated method name stored as soon as it has been defined once |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
private $methodName = null; |
|
33
|
|
|
/** |
|
34
|
|
|
* Main constructor |
|
35
|
|
|
* @see AbstractModel::__construct() |
|
36
|
|
|
* @uses Method::setParameterType() |
|
37
|
|
|
* @uses Method::setReturnType() |
|
38
|
|
|
* @uses AbstractModel::setOwner() |
|
39
|
|
|
* @param Generator $generator |
|
40
|
|
|
* @param string $name the function name |
|
41
|
|
|
* @param string|array $parameterType the type/name of the parameter |
|
42
|
|
|
* @param string|array $returnType the type/name of the return value |
|
43
|
|
|
* @param Service $service defines the struct which owns this value |
|
44
|
|
|
* @param bool $isUnique defines if the method is unique or not |
|
45
|
|
|
*/ |
|
46
|
508 |
|
public function __construct(Generator $generator, $name, $parameterType, $returnType, Service $service, $isUnique = true) |
|
47
|
|
|
{ |
|
48
|
508 |
|
parent::__construct($generator, $name); |
|
49
|
508 |
|
$this->setParameterType($parameterType)->setReturnType($returnType)->setIsUnique($isUnique)->setOwner($service); |
|
50
|
508 |
|
} |
|
51
|
|
|
/** |
|
52
|
|
|
* Method name can't starts with numbers |
|
53
|
|
|
* @see \WsdlToPhp\PackageGenerator\Model\AbstractModel::getCleanName() |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
508 |
|
public function getCleanName($keepMultipleUnderscores = true) |
|
57
|
|
|
{ |
|
58
|
508 |
|
return preg_replace('/^(\d+)([a-zA-Z0-9]*)$/', '_$2', parent::getCleanName($keepMultipleUnderscores)); |
|
59
|
|
|
} |
|
60
|
|
|
/** |
|
61
|
|
|
* Returns the name of the method that is used to call the operation |
|
62
|
|
|
* It takes care of the fact that the method might not be the only one named as it is. |
|
63
|
|
|
* @uses Method::getCleanName() |
|
64
|
|
|
* @uses AbstractModel::replacePhpReservedKeyword() |
|
65
|
|
|
* @uses AbstractModel::getOwner() |
|
66
|
|
|
* @uses AbstractModel::getPackagedName() |
|
67
|
|
|
* @uses AbstractModel::uniqueName() |
|
68
|
|
|
* @uses Method::getOwner() |
|
69
|
|
|
* @uses Method::getParameterType() |
|
70
|
|
|
* @uses Method::getIsUnique() |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
508 |
|
public function getMethodName() |
|
74
|
|
|
{ |
|
75
|
508 |
|
if (empty($this->methodName)) { |
|
76
|
508 |
|
$methodName = $this->getCleanName(); |
|
77
|
508 |
|
if (!$this->getIsUnique()) { |
|
78
|
12 |
|
if (is_string($this->getParameterType())) { |
|
79
|
12 |
|
$methodName .= ucfirst($this->getParameterType()); |
|
80
|
9 |
|
} else { |
|
81
|
|
|
$methodName .= '_' . md5(var_export($this->getParameterType(), true)); |
|
82
|
|
|
} |
|
83
|
9 |
|
} |
|
84
|
508 |
|
$context = $this->getOwner()->getPackagedName(); |
|
85
|
508 |
|
$methodName = $this->replaceReservedMethod($methodName, $context); |
|
86
|
508 |
|
$methodName = self::replacePhpReservedKeyword($methodName, $context); |
|
87
|
508 |
|
$this->methodName = self::uniqueName($methodName, $this->getOwner()->getPackagedName()); |
|
88
|
381 |
|
} |
|
89
|
508 |
|
return $this->methodName; |
|
90
|
|
|
} |
|
91
|
|
|
/** |
|
92
|
|
|
* Returns the parameter type |
|
93
|
|
|
* @return string|string[] |
|
94
|
|
|
*/ |
|
95
|
356 |
|
public function getParameterType() |
|
96
|
|
|
{ |
|
97
|
356 |
|
return $this->parameterType; |
|
98
|
|
|
} |
|
99
|
|
|
/** |
|
100
|
|
|
* Set the parameter type |
|
101
|
|
|
* @param string|string[] |
|
102
|
|
|
* @return Method |
|
103
|
|
|
*/ |
|
104
|
508 |
|
public function setParameterType($parameterType) |
|
105
|
|
|
{ |
|
106
|
508 |
|
$this->parameterType = $parameterType; |
|
107
|
508 |
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
/** |
|
110
|
|
|
* Returns the retrun type |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
292 |
|
public function getReturnType() |
|
114
|
|
|
{ |
|
115
|
292 |
|
return $this->returnType; |
|
116
|
|
|
} |
|
117
|
|
|
/** |
|
118
|
|
|
* Set the retrun type |
|
119
|
|
|
* @param string|string[] |
|
120
|
|
|
* @return Method |
|
121
|
|
|
*/ |
|
122
|
508 |
|
public function setReturnType($returnType) |
|
123
|
|
|
{ |
|
124
|
508 |
|
$this->returnType = $returnType; |
|
125
|
508 |
|
return $this; |
|
126
|
|
|
} |
|
127
|
|
|
/** |
|
128
|
|
|
* Returns the isUnique property |
|
129
|
|
|
* @return bool |
|
130
|
|
|
*/ |
|
131
|
508 |
|
public function getIsUnique() |
|
132
|
|
|
{ |
|
133
|
508 |
|
return $this->isUnique; |
|
134
|
|
|
} |
|
135
|
|
|
/** |
|
136
|
|
|
* Set the isUnique property |
|
137
|
|
|
* @param bool |
|
138
|
|
|
* @return Method |
|
139
|
|
|
*/ |
|
140
|
508 |
|
public function setIsUnique($isUnique) |
|
141
|
|
|
{ |
|
142
|
508 |
|
$this->isUnique = $isUnique; |
|
143
|
508 |
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
/** |
|
146
|
|
|
* Returns the owner model object, meaning a Service object |
|
147
|
|
|
* @see AbstractModel::getOwner() |
|
148
|
|
|
* @uses AbstractModel::getOwner() |
|
149
|
|
|
* @return Service |
|
150
|
|
|
*/ |
|
151
|
508 |
|
public function getOwner() |
|
152
|
|
|
{ |
|
153
|
508 |
|
return parent::getOwner(); |
|
154
|
|
|
} |
|
155
|
|
|
/** |
|
156
|
|
|
* @param $filename |
|
157
|
|
|
* @return ServiceReservedMethod |
|
158
|
|
|
*/ |
|
159
|
508 |
|
public function getReservedMethodsInstance($filename = null) |
|
160
|
|
|
{ |
|
161
|
508 |
|
return ServiceReservedMethod::instance($filename); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|