|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WsdlToPhp\PackageGenerator\Model; |
|
4
|
|
|
|
|
5
|
|
|
use WsdlToPhp\PackageGenerator\Generator\Utils; |
|
6
|
|
|
use WsdlToPhp\PackageGenerator\Generator\Generator; |
|
7
|
|
|
use WsdlToPhp\PackageGenerator\ConfigurationReader\StructReservedMethod; |
|
8
|
|
|
use WsdlToPhp\PackageGenerator\ConfigurationReader\StructArrayReservedMethod; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class StructAttribute stands for an available struct attribute described in the WSDL |
|
12
|
|
|
*/ |
|
13
|
|
|
class StructAttribute extends AbstractModel |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Type of the struct attribute |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $type = ''; |
|
20
|
|
|
/** |
|
21
|
|
|
* Defines that this property is not a simple value but an array of values |
|
22
|
|
|
* Infos at {@link https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints} |
|
23
|
|
|
* @var bool |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $containsElements = false; |
|
26
|
|
|
/** |
|
27
|
|
|
* Defines that this property can be removed from request or not. |
|
28
|
|
|
* The property cna be removed from the request (meaning from the Struct) as soon as the nillable=true && minOccurs=0 |
|
29
|
|
|
* Infos at {@link http://www.w3schools.com/xml/el_element.asp} |
|
30
|
|
|
* @var bool |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $removableFromRequest = false; |
|
33
|
|
|
/** |
|
34
|
|
|
* Main constructor |
|
35
|
|
|
* @see AbstractModel::__construct() |
|
36
|
|
|
* @uses StructAttribute::setType() |
|
37
|
|
|
* @uses AbstractModel::setOwner() |
|
38
|
|
|
* @param Generator $generator |
|
39
|
|
|
* @param string $name the original name |
|
40
|
|
|
* @param string $type the type |
|
41
|
|
|
* @param Struct $struct defines the struct which owns this value |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct(Generator $generator, $name, $type = '', Struct $struct = null) |
|
44
|
|
|
{ |
|
45
|
|
|
parent::__construct($generator, $name); |
|
46
|
|
|
$this->setType($type)->setOwner($struct); |
|
47
|
|
|
} |
|
48
|
|
|
/** |
|
49
|
|
|
* Returns the unique name in the current struct (for setters/getters and struct constructor array) |
|
50
|
|
|
* @uses AbstractModel::getCleanName() |
|
51
|
|
|
* @uses AbstractModel::getName() |
|
52
|
|
|
* @uses AbstractModel::uniqueName() |
|
53
|
|
|
* @uses StructAttribute::getOwner() |
|
54
|
|
|
* @param string $additionalContext |
|
55
|
|
|
* @param string $string |
|
56
|
|
|
* @param string $additionalContext |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getUniqueString($string, $additionalContext= '') |
|
60
|
|
|
{ |
|
61
|
|
|
return self::uniqueName($string, $this->getOwner()->getName() . $additionalContext); |
|
62
|
|
|
} |
|
63
|
|
|
/** |
|
64
|
|
|
* Returns the unique name in the current struct (for setters/getters and struct contrusctor array) |
|
65
|
|
|
* @uses AbstractModel::getCleanName() |
|
66
|
|
|
* @uses AbstractModel::getName() |
|
67
|
|
|
* @uses AbstractModel::uniqueName() |
|
68
|
|
|
* @uses StructAttribute::getOwner() |
|
69
|
|
|
* @param string $additionalContext |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getUniqueName($additionalContext = '') |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->getUniqueString($this->getCleanName(), $additionalContext); |
|
75
|
|
|
} |
|
76
|
|
|
/** |
|
77
|
|
|
* Returns the getter name for this attribute |
|
78
|
|
|
* @uses StructAttribute::getUniqueName() |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getGetterName() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->replaceReservedMethod(sprintf('get%s', ucfirst($this->getUniqueName('get'))), $this->getOwner()->getPackagedName()); |
|
84
|
|
|
} |
|
85
|
|
|
/** |
|
86
|
|
|
* Returns the getter name for this attribute |
|
87
|
|
|
* @uses StructAttribute::getUniqueName() |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getSetterName() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->replaceReservedMethod(sprintf('set%s', ucfirst($this->getUniqueName('set'))), $this->getOwner()->getPackagedName()); |
|
93
|
|
|
} |
|
94
|
|
|
/** |
|
95
|
|
|
* Returns the type value |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getType($useTypeStruct = false) |
|
99
|
|
|
{ |
|
100
|
|
|
if ($useTypeStruct) { |
|
101
|
|
|
$typeStruct = $this->getTypeStruct(); |
|
102
|
|
|
if ($typeStruct instanceof Struct) { |
|
103
|
|
|
$type = $typeStruct->getTopInheritance(); |
|
104
|
|
|
return $type ? $type : $this->type; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
return $this->type; |
|
108
|
|
|
} |
|
109
|
|
|
/** |
|
110
|
|
|
* Sets the type value |
|
111
|
|
|
* @param string $type |
|
112
|
|
|
* @return StructAttribute |
|
113
|
|
|
*/ |
|
114
|
|
|
public function setType($type) |
|
115
|
|
|
{ |
|
116
|
|
|
$this->type = $type; |
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
/** |
|
120
|
|
|
* Returns the type value |
|
121
|
|
|
* @return bool |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getContainsElements() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->containsElements; |
|
126
|
|
|
} |
|
127
|
|
|
/** |
|
128
|
|
|
* Sets the type value |
|
129
|
|
|
* @param bool $containsElements |
|
130
|
|
|
* @return StructAttribute |
|
131
|
|
|
*/ |
|
132
|
|
|
public function setContainsElements($containsElements) |
|
133
|
|
|
{ |
|
134
|
|
|
$this->containsElements = $containsElements; |
|
135
|
|
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
/** |
|
138
|
|
|
* @return bool |
|
139
|
|
|
*/ |
|
140
|
|
|
public function getRemovableFromRequest() |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->removableFromRequest; |
|
143
|
|
|
} |
|
144
|
|
|
/** |
|
145
|
|
|
* @param bool $removableFromRequest |
|
146
|
|
|
* @return StructAttribute |
|
147
|
|
|
*/ |
|
148
|
|
|
public function setRemovableFromRequest($removableFromRequest) |
|
149
|
|
|
{ |
|
150
|
|
|
$this->removableFromRequest = $removableFromRequest; |
|
151
|
|
|
return $this; |
|
152
|
|
|
} |
|
153
|
|
|
/** |
|
154
|
|
|
* If this attribute contains elements then it's an array |
|
155
|
|
|
* only if its parent, the Struct, is not itself an array, |
|
156
|
|
|
* if the parent is an array, then it is certainly not an array too |
|
157
|
|
|
* @return bool |
|
158
|
|
|
*/ |
|
159
|
|
|
public function isArray() |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->containsElements || $this->isTypeStructArray(); |
|
162
|
|
|
} |
|
163
|
|
|
/** |
|
164
|
|
|
* Returns potential default value |
|
165
|
|
|
* @uses AbstractModel::getMetaValueFirstSet() |
|
166
|
|
|
* @uses Utils::getValueWithinItsType() |
|
167
|
|
|
* @uses StructAttribute::getType() |
|
168
|
|
|
* @uses StructAttribute::getContainsElements() |
|
169
|
|
|
* @return mixed |
|
170
|
|
|
*/ |
|
171
|
|
|
public function getDefaultValue() |
|
172
|
|
|
{ |
|
173
|
|
|
if ($this->isArray()) { |
|
174
|
|
|
return []; |
|
175
|
|
|
} |
|
176
|
|
|
return Utils::getValueWithinItsType($this->getMetaValueFirstSet([ |
|
177
|
|
|
'default', |
|
178
|
|
|
'Default', |
|
179
|
|
|
'DefaultValue', |
|
180
|
|
|
'defaultValue', |
|
181
|
|
|
'defaultvalue', |
|
182
|
|
|
]), $this->getType(true)); |
|
183
|
|
|
} |
|
184
|
|
|
/** |
|
185
|
|
|
* Returns true or false depending on minOccurs information associated to the attribute |
|
186
|
|
|
* @uses AbstractModel::getMetaValueFirstSet() |
|
187
|
|
|
* @uses AbstractModel::getMetaValue() |
|
188
|
|
|
* @return bool true|false |
|
189
|
|
|
*/ |
|
190
|
|
|
public function isRequired() |
|
191
|
|
|
{ |
|
192
|
|
|
return ($this->getMetaValue('use', '') === 'required' || $this->getMetaValueFirstSet([ |
|
193
|
|
|
'minOccurs', |
|
194
|
|
|
'minoccurs', |
|
195
|
|
|
'MinOccurs', |
|
196
|
|
|
'Minoccurs', |
|
197
|
|
|
], false)); |
|
198
|
|
|
} |
|
199
|
|
|
/** |
|
200
|
|
|
* Returns the owner model object, meaning a Struct object |
|
201
|
|
|
* @see AbstractModel::getOwner() |
|
202
|
|
|
* @uses AbstractModel::getOwner() |
|
203
|
|
|
* @return Struct |
|
204
|
|
|
*/ |
|
205
|
|
|
public function getOwner() |
|
206
|
|
|
{ |
|
207
|
|
|
return parent::getOwner(); |
|
208
|
|
|
} |
|
209
|
|
|
/** |
|
210
|
|
|
* @uses StructAttribute::getType() |
|
211
|
|
|
* @return bool |
|
212
|
|
|
*/ |
|
213
|
|
|
public function isXml() |
|
214
|
|
|
{ |
|
215
|
|
|
return stripos($this->getType(), '\DOM') === 0; |
|
216
|
|
|
} |
|
217
|
|
|
/** |
|
218
|
|
|
* @return Struct|null |
|
219
|
|
|
*/ |
|
220
|
|
|
public function getTypeStruct() |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->getGenerator()->getStruct($this->getType()); |
|
223
|
|
|
} |
|
224
|
|
|
/** |
|
225
|
|
|
* @return string[] |
|
226
|
|
|
*/ |
|
227
|
|
|
public function getTypeStructMeta() |
|
228
|
|
|
{ |
|
229
|
|
|
$typeStruct = $this->getTypeStruct(); |
|
230
|
|
|
return ($typeStruct && !$typeStruct->isStruct()) ? $typeStruct->getMeta() : []; |
|
231
|
|
|
} |
|
232
|
|
|
/** |
|
233
|
|
|
* @return bool |
|
234
|
|
|
*/ |
|
235
|
|
|
public function isTypeStructArray() |
|
236
|
|
|
{ |
|
237
|
|
|
$typeStruct = $this->getTypeStruct(); |
|
238
|
|
|
return $typeStruct && $typeStruct->isArray() && !$typeStruct->isStruct(); |
|
239
|
|
|
} |
|
240
|
|
|
/** |
|
241
|
|
|
* @return Struct|null |
|
242
|
|
|
*/ |
|
243
|
|
|
public function getInheritanceStruct() |
|
244
|
|
|
{ |
|
245
|
|
|
return $this->getGenerator()->getStruct($this->getInheritance()); |
|
246
|
|
|
} |
|
247
|
|
|
/** |
|
248
|
|
|
* @return string[] |
|
249
|
|
|
*/ |
|
250
|
|
|
public function getInheritanceStructMeta() |
|
251
|
|
|
{ |
|
252
|
|
|
$inheritanceStruct = $this->getInheritanceStruct(); |
|
253
|
|
|
return ($inheritanceStruct && !$inheritanceStruct->isStruct()) ? $inheritanceStruct->getMeta() : []; |
|
254
|
|
|
} |
|
255
|
|
|
/** |
|
256
|
|
|
* @see \WsdlToPhp\PackageGenerator\Model\AbstractModel::getMeta() |
|
257
|
|
|
* @return string[] |
|
258
|
|
|
*/ |
|
259
|
|
|
public function getMeta() |
|
260
|
|
|
{ |
|
261
|
|
|
return array_merge_recursive(parent::getMeta(), $this->getTypeStructMeta(), $this->getInheritanceStructMeta()); |
|
262
|
|
|
} |
|
263
|
|
|
/** |
|
264
|
|
|
* @param $filename |
|
265
|
|
|
* @return StructReservedMethod|StructArrayReservedMethod |
|
266
|
|
|
*/ |
|
267
|
|
|
public function getReservedMethodsInstance($filename = null) |
|
268
|
|
|
{ |
|
269
|
|
|
return $this->getOwner()->getReservedMethodsInstance($filename); |
|
270
|
|
|
} |
|
271
|
|
|
/** |
|
272
|
|
|
* {@inheritDoc} |
|
273
|
|
|
* @see \WsdlToPhp\PackageGenerator\Model\AbstractModel::toJsonSerialize() |
|
274
|
|
|
*/ |
|
275
|
|
|
protected function toJsonSerialize() |
|
276
|
|
|
{ |
|
277
|
|
|
return [ |
|
278
|
|
|
'containsElements' => $this->containsElements, |
|
279
|
|
|
'removableFromRequest' => $this->removableFromRequest, |
|
280
|
|
|
'type' => $this->type, |
|
281
|
|
|
]; |
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
|