1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WsdlToPhp\PackageGenerator\File; |
4
|
|
|
|
5
|
|
|
use WsdlToPhp\PackageGenerator\Generator\Generator; |
6
|
|
|
use WsdlToPhp\PackageGenerator\Model\AbstractModel; |
7
|
|
|
use WsdlToPhp\PackageGenerator\Model\Method as MethodModel; |
8
|
|
|
use WsdlToPhp\PackageGenerator\Model\Struct as StructModel; |
9
|
|
|
use WsdlToPhp\PhpGenerator\Element\PhpFunctionParameter; |
10
|
|
|
|
11
|
|
|
abstract class AbstractOperation |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
const DEFAULT_TYPE = 'string'; |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
const SOAP_CALL_NAME = '__call'; |
21
|
|
|
/** |
22
|
|
|
* @var MethodModel |
23
|
|
|
*/ |
24
|
|
|
protected $method; |
25
|
|
|
/** |
26
|
|
|
* @var Generator |
27
|
|
|
*/ |
28
|
|
|
protected $generator; |
29
|
|
|
/** |
30
|
|
|
* @param MethodModel $method |
31
|
|
|
* @param Generator $generator |
32
|
|
|
*/ |
33
|
84 |
|
public function __construct(MethodModel $method, Generator $generator) |
34
|
|
|
{ |
35
|
84 |
|
$this->setMethod($method)->setGenerator($generator); |
36
|
84 |
|
} |
37
|
|
|
/** |
38
|
|
|
* @return StructModel|null |
39
|
|
|
*/ |
40
|
84 |
|
protected function getParameterTypeModel() |
41
|
|
|
{ |
42
|
84 |
|
return $this->isParameterTypeAString() ? $this->getGenerator()->getStruct($this->getMethod()->getParameterType()) : null; |
|
|
|
|
43
|
|
|
} |
44
|
|
|
/** |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
8 |
|
protected function isParameterTypeEmpty() |
48
|
|
|
{ |
49
|
8 |
|
$parameterType = $this->getMethod()->getParameterType(); |
50
|
8 |
|
return empty($parameterType); |
51
|
|
|
} |
52
|
|
|
/** |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
84 |
|
protected function isParameterTypeAnArray() |
56
|
|
|
{ |
57
|
84 |
|
return is_array($this->getMethod()->getParameterType()); |
58
|
|
|
} |
59
|
|
|
/** |
60
|
|
|
* @param bool $methodUsage |
61
|
|
|
* @return string[] |
62
|
|
|
*/ |
63
|
76 |
|
protected function getParameterTypeArrayTypes($methodUsage = false) |
64
|
|
|
{ |
65
|
76 |
|
$types = array(); |
66
|
76 |
|
$parameterTypes = $this->getMethod()->getParameterType(); |
67
|
76 |
|
if (is_array($parameterTypes)) { |
68
|
76 |
|
foreach ($parameterTypes as $parameterName => $parameterType) { |
69
|
76 |
|
$type = $methodUsage ? null : self::DEFAULT_TYPE; |
70
|
76 |
|
if (($model = $this->getGenerator()->getStruct($parameterType)) instanceof StructModel && $model->getIsStruct() && !$model->getIsRestriction()) { |
71
|
68 |
|
$type = $model->getPackagedName(true); |
72
|
51 |
|
} |
73
|
76 |
|
$types[$parameterName] = $type; |
74
|
57 |
|
} |
75
|
57 |
|
} |
76
|
76 |
|
return $types; |
77
|
|
|
} |
78
|
|
|
/** |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
84 |
|
protected function isParameterTypeAString() |
82
|
|
|
{ |
83
|
84 |
|
return is_string($this->getMethod()->getParameterType()); |
84
|
|
|
} |
85
|
|
|
/** |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
84 |
|
protected function isParameterTypeAModel() |
89
|
|
|
{ |
90
|
84 |
|
return $this->getParameterTypeModel() instanceof StructModel; |
91
|
|
|
} |
92
|
|
|
/** |
93
|
|
|
* @param string $name |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
84 |
|
protected function getParameterName($name) |
97
|
|
|
{ |
98
|
84 |
|
return lcfirst(AbstractModel::cleanString($name)); |
99
|
|
|
} |
100
|
|
|
/** |
101
|
|
|
* @param string $name |
102
|
|
|
* @param string $type |
103
|
|
|
* @return PhpFunctionParameter |
104
|
|
|
*/ |
105
|
84 |
|
protected function getMethodParameter($name, $type = null) |
106
|
|
|
{ |
107
|
|
|
try { |
108
|
84 |
|
return new PhpFunctionParameter($name, PhpFunctionParameter::NO_VALUE, $type); |
109
|
|
|
} catch (\InvalidArgumentException $exception) { |
110
|
|
|
throw new \InvalidArgumentException(sprintf('Unable to create function parameter for method "%s" with type "%s" and name "%s"', $this->getMethod()->getName(), var_export($type, true), $name), __LINE__, $exception); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
/** |
114
|
|
|
* @param Generator $generator |
115
|
|
|
* @return AbstractOperation |
116
|
|
|
*/ |
117
|
84 |
|
public function setGenerator(Generator $generator) |
118
|
|
|
{ |
119
|
84 |
|
$this->generator = $generator; |
120
|
84 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
/** |
123
|
|
|
* @return Generator |
124
|
|
|
*/ |
125
|
84 |
|
public function getGenerator() |
126
|
|
|
{ |
127
|
84 |
|
return $this->generator; |
128
|
|
|
} |
129
|
|
|
/** |
130
|
|
|
* @param MethodModel $method |
131
|
|
|
* @return AbstractOperation |
132
|
|
|
*/ |
133
|
84 |
|
public function setMethod(MethodModel $method) |
134
|
|
|
{ |
135
|
84 |
|
$this->method = $method; |
136
|
84 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
/** |
139
|
|
|
* @return MethodModel |
140
|
|
|
*/ |
141
|
84 |
|
public function getMethod() |
142
|
|
|
{ |
143
|
84 |
|
return $this->method; |
144
|
|
|
} |
145
|
|
|
/** |
146
|
|
|
* @param string $name |
147
|
|
|
* @return StructModel|null |
148
|
|
|
*/ |
149
|
20 |
|
protected function getModelByName($name) |
150
|
|
|
{ |
151
|
20 |
|
return $this->getGenerator()->getStruct($name); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.