This repository has been archived by the owner on Jun 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathWsdlToPhpStructAttribute.php
326 lines (326 loc) · 12.8 KB
/
WsdlToPhpStructAttribute.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
/**
* File for WsdlToPhpStructAttribute
* @package WsdlToPhpGenerator
* @date 19/12/2012
*/
/**
* Class WsdlToPhpStructAttribute stands for an available struct attribute described in the WSDL
* @package WsdlToPhpGenerator
* @date 19/12/2012
*/
class WsdlToPhpStructAttribute extends WsdlToPhpModel
{
/**
* Type of the struct attribute
* @var string
*/
private $type = '';
/**
* Main constructor
* @see WsdlToPhpModel::__construct()
* @uses WsdlToPhpStructAttribute::setType()
* @uses WsdlToPhpModel::setOwner()
* @param string $_name the original name
* @param string $_type the type
* @param WsdlToPhpStruct $_wsdlToPhpStruct defines the struct which owns this value
* @return WsdlToPhpStructAttribute
*/
public function __construct($_name,$_type,WsdlToPhpStruct $_wsdlToPhpStruct)
{
parent::__construct($_name);
$this->setType($_type);
$this->setOwner($_wsdlToPhpStruct);
}
/**
* Returns the comment lines for this attribute
* @see WsdlToPhpModel::getComment()
* @uses WsdlToPhpModel::getName()
* @uses WsdlToPhpStruct::getIsStruct()
* @uses WsdlToPhpStructAttribute::getType()
* @uses WsdlToPhpStructAttribute::getOwner()
* @uses WsdlToPhpModel::addMetaComment()
* @uses WsdlToPhpModel::getModelByName()
* @uses WsdlToPhpModel::getPackagedName()
* @uses WsdlToPhpModel::getInheritance()
* @return array
*/
public function getComment()
{
$comments = array();
array_push($comments,'The ' . $this->getName());
$this->addMetaComment($comments);
$model = self::getModelByName($this->getType());
if($model)
{
/**
* A virtual struct exists only to store meta informations about itself
* A property for which the data type points to its actual owner class has to be of its native type
* So don't add meta informations about a valid struct
*/
if(!$model->getIsStruct() || $model->getPackagedName() == $this->getOwner()->getPackagedName())
{
$model->addMetaComment($comments);
array_push($comments,'@var ' . ($model->getInheritance()?$model->getInheritance():$this->getType()));
}
else
array_push($comments,'@var ' . $model->getPackagedName());
}
else
array_push($comments,'@var ' . $this->getType());
return $comments;
}
/**
* Returns the unique name in the current struct (for setters/getters and struct contrusctor array)
* @uses WsdlToPhpModel::getCleanName()
* @uses WsdlToPhpModel::getName()
* @uses WsdlToPhpModel::uniqueName()
* @uses WsdlToPhpStructAttribute::getOwner()
* @return string
*/
public function getUniqueName()
{
return self::uniqueName($this->getCleanName(),$this->getOwner()->getName());
}
/**
* Returns the declaration of the attribute
* @uses WsdlToPhpModel::getCleanName()
* @return string
*/
public function getDeclaration()
{
return 'public $' . $this->getCleanName() . ';';
}
/**
* Returns the getter name for this attribute
* @uses WsdlToPhpStructAttribute::getUniqueName()
* @return string
*/
public function getGetterName()
{
return 'get' . ucfirst(self::getUniqueName());
}
/**
* Returns the getter name for this attribute
* @uses WsdlToPhpStructAttribute::getUniqueName()
* @return string
*/
public function getSetterName()
{
return 'set' . ucfirst(self::getUniqueName());
}
/**
* Returns the array of lines to declare the getter
* @uses WsdlToPhpModel::getModelByName()
* @uses WsdlToPhpModel::getCleanName()
* @uses WsdlToPhpModel::nameIsClean()
* @uses WsdlToPhpModel::getName()
* @uses WsdlToPhpModel::getPackagedName()
* @uses WsdlToPhpStruct::getIsStruct()
* @uses WsdlToPhpStructAttribute::getType()
* @uses WsdlToPhpStructAttribute::getGetterName()
* @uses WsdlToPhpStructAttribute::isRequired()
* @uses WsdlToPhpStructAttribute::getOwner()
* @param array $_body
* @param WsdlToPhpStruct $_struct
* @return void
*/
public function getGetterDeclaration(&$_body,WsdlToPhpStruct $_struct)
{
$model = self::getModelByName($this->getType());
$isXml = ($this->getType() == 'DOMDocument');
/**
* get() method comment
*/
$comments = array();
array_push($comments,'Get ' . $this->getName() . ' value');
if($isXml)
{
array_push($comments,'@uses DOMDocument::loadXML()');
array_push($comments,'@uses DOMDocument::hasChildNodes()');
array_push($comments,'@uses DOMDocument::saveXML()');
array_push($comments,'@uses DOMNode::item()');
array_push($comments,'@uses ' . $_struct->getPackagedName() . '::' . $this->getSetterName() . '()');
array_push($comments,'@param bool true or false whether to return XML value as string or as DOMDocument');
}
array_push($comments,'@return ' . ($model?(($model->getIsStruct() && $model->getPackagedName() != $this->getOwner()->getPackagedName())?$model->getPackagedName():($model->getInheritance()?$model->getInheritance():$this->getType())):$this->getType()) . ($this->isRequired()?'':'|null'));
array_push($_body,array(
'comment'=>$comments));
/**
* get() method body
*/
array_push($_body,'public function ' . $this->getGetterName() . '(' . ($isXml?'$_asString = true':'') . ')');
array_push($_body,"{");
$thisAccess = '';
if($this->nameIsClean())
$thisAccess = '$this->' . $this->getName();
else
$thisAccess = '$this->{\'' . addslashes($this->getName()) . '\'}';
/**
* format XML data
*/
if($isXml)
{
array_push($_body,'if(!empty(' . $thisAccess . ') && !(' . $thisAccess . ' instanceof DOMDocument))');
array_push($_body,'{');
array_push($_body,'$dom = new DOMDocument(\'1.0\',\'UTF-8\');');
array_push($_body,'$dom->formatOutput = true;');
array_push($_body,'if($dom->loadXML(' . $thisAccess . '))');
array_push($_body,'{');
array_push($_body,'$this->' . $this->getSetterName() . '($dom);');
array_push($_body,'}');
array_push($_body,'unset($dom);');
array_push($_body,'}');
}
if($isXml)
array_push($_body,'return ($_asString && (' . $thisAccess . ' instanceof DOMDocument) && ' . $thisAccess . '->hasChildNodes())?' . $thisAccess . '->saveXML(' . $thisAccess . '->childNodes->item(0)):' . $thisAccess . ';');
else
array_push($_body,'return ' . $thisAccess . ';');
array_push($_body,"}");
unset($model,$isXml,$comments);
}
/**
* Returns the array of lines to declare the setter
* @uses WsdlToPhpModel::getModelByName()
* @uses WsdlToPhpModel::getCleanName()
* @uses WsdlToPhpModel::nameIsClean()
* @uses WsdlToPhpModel::getName()
* @uses WsdlToPhpModel::getPackagedName()
* @uses WsdlToPhpModel::getInheritance()
* @uses WsdlToPhpStruct::getIsRestriction()
* @uses WsdlToPhpStruct::isArray()
* @uses WsdlToPhpStructAttribute::getType()
* @uses WsdlToPhpStructAttribute::getSetterName()
* @uses WsdlToPhpStructAttribute::getOwner()
* @param array $_body
* @param WsdlToPhpStruct $_struct
* @return void
*/
public function getSetterDeclaration(&$_body,WsdlToPhpStruct $_struct)
{
$model = self::getModelByName($this->getType());
/**
* set() method comment
*/
$comments = array();
array_push($comments,'Set ' . $this->getName() . ' value');
if($model && $model->getIsRestriction() && !$_struct->isArray())
array_push($comments,'@uses ' . $model->getPackagedName() . '::valueIsValid()');
if($model)
{
if($model->getIsStruct() && $model->getPackagedName() != $this->getOwner()->getPackagedName())
{
array_push($comments,'@param ' . $model->getPackagedName() . ' $_' . lcfirst($this->getCleanName()) . ' the ' . $this->getName());
array_push($comments,'@return ' . $model->getPackagedName());
}
else
{
array_push($comments,'@param ' . ($model->getInheritance()?$model->getInheritance():$this->getType()) . ' $_' . lcfirst($this->getCleanName()) . ' the ' . $this->getName());
array_push($comments,'@return ' . ($model->getInheritance()?$model->getInheritance():$this->getType()));
}
}
else
{
array_push($comments,'@param ' . $this->getType() . ' $_' . lcfirst($this->getCleanName()) . ' the ' . $this->getName());
array_push($comments,'@return ' . $this->getType());
}
array_push($_body,array(
'comment'=>$comments));
/**
* set() method body
*/
array_push($_body,'public function ' . $this->getSetterName() . '($_' . lcfirst($this->getCleanName()) . ')');
array_push($_body,'{');
if($model && $model->getIsRestriction() && !$_struct->isArray())
{
array_push($_body,'if(!' . $model->getPackagedName() . '::valueIsValid($_' . lcfirst($this->getCleanName()) . '))');
array_push($_body,'{');
array_push($_body,'return false;');
array_push($_body,'}');
}
if($this->nameIsClean())
array_push($_body,'return ($this->' . $this->getName() . ' = $_' . lcfirst($this->getCleanName()) . ');');
else
array_push($_body,'return ($this->' . $this->getCleanName() . ' = $this->{\'' . addslashes($this->getName()) . '\'} = $_' . lcfirst($this->getCleanName()) . ');');
array_push($_body,'}');
unset($model,$comments);
}
/**
* Returns the type value
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Sets the type value
* @param string $_type
* @return string
*/
public function setType($_type)
{
return ($this->type = $_type);
}
/**
* Returns potential default value
* @uses WsdlToPhpModel::getMetaValueFirstSet()
* @uses WsdlToPhpModel::getValueWithinItsType()
* @uses WsdlToPhpStructAttribute::getType()
* @return mixed
*/
public function getDefaultValue()
{
return self::getValueWithinItsType($this->getMetaValueFirstSet(array(
'default',
'Default',
'DefaultValue',
'defaultValue',
'defaultvalue')),$this->getType());
}
/**
* Returns true or false depending on minOccurs information associated to the attribute
* @uses WsdlToPhpModel::getMetaValueFirstSet()
* @uses WsdlToPhpModel::getMetaValue()
* @return bool true|false
*/
public function isRequired()
{
return ($this->getMetaValue('use','') === 'required' || $this->getMetaValueFirstSet(array(
'minOccurs',
'minoccurs',
'MinOccurs',
'Minoccurs'),false));
}
/**
* Returns the patern which the value must match
* @uses WsdlToPhpModel::getMetaValueFirstSet()
* @return string
*/
public function getPattern()
{
return $this->getMetaValueFirstSet(array(
'pattern',
'Pattern',
'match',
'Match'),'');
}
/**
* Returns the owner model object, meaning a WsdlToPhpStruct object
* @see WsdlToPhpModel::getOwner()
* @uses WsdlToPhpModel::getOwner()
* @return WsdlToPhpStruct
*/
public function getOwner()
{
return parent::getOwner();
}
/**
* Returns class name
* @return string __CLASS__
*/
public function __toString()
{
return __CLASS__;
}
}